Skip to content

Commit f198f96

Browse files
committed
fix up linter failures
1 parent 464030a commit f198f96

File tree

7 files changed

+29
-79
lines changed

7 files changed

+29
-79
lines changed

action.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ func (a *Action) delete(
378378
if ons == "" {
379379
ons = ns
380380
}
381-
if err = a.doDelete(ctx, c, res, name, ns); err != nil {
381+
if err = a.doDelete(ctx, c, res, name, ons); err != nil {
382382
return err
383383
}
384384
}

assertions.go

-30
Original file line numberDiff line numberDiff line change
@@ -328,36 +328,6 @@ func (a *assertions) expectsNotFound() bool {
328328
return (exp.Len != nil && *exp.Len == 0) || exp.NotFound
329329
}
330330

331-
// notFoundOK returns true if the supplied error and response matches the
332-
// NotFound condition and the Len==0 condition, false otherwise
333-
func (a *assertions) notFoundOK() bool {
334-
if a.expectsNotFound() {
335-
// First check if the error is like one returned from Get or Delete
336-
// that has a 404 ErrStatus.Code in it
337-
apierr, ok := a.err.(*apierrors.StatusError)
338-
if ok {
339-
if http.StatusNotFound != int(apierr.ErrStatus.Code) {
340-
msg := fmt.Sprintf("got status code %d", apierr.ErrStatus.Code)
341-
a.Fail(ExpectedNotFound(msg))
342-
return false
343-
}
344-
return true
345-
}
346-
// Next check to see if the supplied resp is a list of objects returned
347-
// by the dynamic client and if so, is that an empty list.
348-
list, ok := a.r.(*unstructured.UnstructuredList)
349-
if ok {
350-
if len(list.Items) != 0 {
351-
msg := fmt.Sprintf("got %d items", len(list.Items))
352-
a.Fail(ExpectedNotFound(msg))
353-
return false
354-
}
355-
return true
356-
}
357-
}
358-
return true
359-
}
360-
361331
// lenOK returns true if the subject matches the Len condition, false otherwise
362332
func (a *assertions) lenOK() bool {
363333
exp := a.exp

compare.go

+21-23
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package kube
66

77
import (
88
"fmt"
9-
"io/ioutil"
9+
"os"
1010
"reflect"
1111
"strconv"
1212
"strings"
@@ -42,7 +42,7 @@ func compareConditions(
4242
panic(msg)
4343
}
4444
if (!found || len(conds) == 0) && len(expected) != 0 {
45-
for condType, _ := range expected {
45+
for condType := range expected {
4646
d.Add(fmt.Sprintf("no condition with type %q found", condType))
4747
}
4848
return d
@@ -130,13 +130,13 @@ func compareConditions(
130130
// map[string]interface{} is the collection of resource fields that we will
131131
// match against.
132132
func matchObjectFromAny(m interface{}) map[string]interface{} {
133-
switch m.(type) {
133+
switch m := m.(type) {
134134
case string:
135135
var err error
136136
var b []byte
137-
v := m.(string)
137+
v := m
138138
if probablyFilePath(v) {
139-
b, err = ioutil.ReadFile(v)
139+
b, err = os.ReadFile(v)
140140
if err != nil {
141141
// NOTE(jaypipes): We already validated that the file exists at
142142
// parse time. If we get an error here, just panic cuz there's
@@ -155,7 +155,7 @@ func matchObjectFromAny(m interface{}) map[string]interface{} {
155155
}
156156
return obj
157157
case map[string]interface{}:
158-
return m.(map[string]interface{})
158+
return m
159159
}
160160
return map[string]interface{}{}
161161
}
@@ -238,7 +238,7 @@ func collectFieldDifferences(
238238
}
239239
return
240240
case int, int8, int16, int32, int64:
241-
switch subject.(type) {
241+
switch subject := subject.(type) {
242242
case int, int8, int16, int32, int64:
243243
mv := toInt64(match)
244244
sv := toInt64(subject)
@@ -261,8 +261,7 @@ func collectFieldDifferences(
261261
}
262262
case string:
263263
mv := toInt64(match)
264-
ss := subject.(string)
265-
sv, err := strconv.Atoi(ss)
264+
sv, err := strconv.Atoi(subject)
266265
if err != nil {
267266
diff := fmt.Sprintf(
268267
"%s had different values. expected %v but found %v",
@@ -296,8 +295,7 @@ func collectFieldDifferences(
296295
}
297296
case string:
298297
mv, _ := match.(string)
299-
sv, _ := subject.(string)
300-
if mv != sv {
298+
if mv != subject {
301299
diff := fmt.Sprintf(
302300
"%s had different values. expected %v but found %v",
303301
fp, match, subject,
@@ -362,34 +360,34 @@ func typesComparable(a, b interface{}) bool {
362360

363361
// toUint64 takes an interface and returns a uint64
364362
func toUint64(v interface{}) uint64 {
365-
switch v.(type) {
363+
switch v := v.(type) {
366364
case uint64:
367-
return v.(uint64)
365+
return v
368366
case uint8:
369-
return uint64(v.(uint8))
367+
return uint64(v)
370368
case uint16:
371-
return uint64(v.(uint16))
369+
return uint64(v)
372370
case uint32:
373-
return uint64(v.(uint32))
371+
return uint64(v)
374372
case uint:
375-
return uint64(v.(uint))
373+
return uint64(v)
376374
}
377375
return 0
378376
}
379377

380378
// toInt64 takes an interface and returns an int64
381379
func toInt64(v interface{}) int64 {
382-
switch v.(type) {
380+
switch v := v.(type) {
383381
case int64:
384-
return v.(int64)
382+
return v
385383
case int8:
386-
return int64(v.(int8))
384+
return int64(v)
387385
case int16:
388-
return int64(v.(int16))
386+
return int64(v)
389387
case int32:
390-
return int64(v.(int32))
388+
return int64(v)
391389
case int:
392-
return int64(v.(int))
390+
return int64(v)
393391
}
394392
return 0
395393
}

fixtures/kind/kind.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (f *KindFixture) waitForDefaultServiceAccount(ctx context.Context) error {
144144
)
145145
ticker := backoff.NewTicker(bo)
146146
attempts := 1
147-
for _ = range ticker.C {
147+
for range ticker.C {
148148
found := true
149149
_, err = clientset.CoreV1().ServiceAccounts("default").Get(context.TODO(), "default", metav1.GetOptions{})
150150
if err != nil {

parse.go

-18
Original file line numberDiff line numberDiff line change
@@ -356,24 +356,6 @@ func (e *Expect) UnmarshalYAML(node *yaml.Node) error {
356356
return nil
357357
}
358358

359-
// expandShortcut looks at the shortcut fields (e.g. `kube.create`) and expands
360-
// the shortcut into a full KubeSpec.
361-
func expandShortcut(s *Spec) {
362-
if s.Kube != nil {
363-
return
364-
}
365-
ks := &KubeSpec{
366-
Action: Action{},
367-
}
368-
if s.KubeCreate != "" {
369-
ks.Create = s.KubeCreate
370-
}
371-
if s.KubeApply != "" {
372-
ks.Apply = s.KubeApply
373-
}
374-
s.Kube = ks
375-
}
376-
377359
// moreThanOneAction returns true if the test author has specified more than a
378360
// single action in the KubeSpec.
379361
func moreThanOneAction(a *Action) bool {

parse_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package kube_test
66

77
import (
88
"path/filepath"
9-
"runtime"
109
"testing"
1110

1211
"github.com/gdt-dev/gdt"
@@ -16,11 +15,6 @@ import (
1615
"github.com/stretchr/testify/require"
1716
)
1817

19-
func currentDir() string {
20-
_, filename, _, _ := runtime.Caller(0)
21-
return filepath.Dir(filename)
22-
}
23-
2418
func TestFailureBadDefaults(t *testing.T) {
2519
assert := assert.New(t)
2620
require := require.New(t)

placement.go

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ func getNodes(
3535
Kind: "Node",
3636
}
3737
res, err := c.gvrFromGVK(gvk)
38+
if err != nil {
39+
panic(err)
40+
}
3841
opts := metav1.ListOptions{}
3942
list, err := c.client.Resource(res).Namespace("").List(
4043
ctx, opts,
@@ -94,6 +97,9 @@ func getPods(
9497
Kind: "Pod",
9598
}
9699
res, err := c.gvrFromGVK(gvk)
100+
if err != nil {
101+
panic(err)
102+
}
97103
opts := client.ListOptions{
98104
LabelSelector: ls,
99105
Namespace: ns,

0 commit comments

Comments
 (0)