Skip to content

Commit

Permalink
fix up linter failures
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypipes committed Jun 25, 2024
1 parent 464030a commit f198f96
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 79 deletions.
2 changes: 1 addition & 1 deletion action.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func (a *Action) delete(
if ons == "" {
ons = ns
}
if err = a.doDelete(ctx, c, res, name, ns); err != nil {
if err = a.doDelete(ctx, c, res, name, ons); err != nil {
return err
}
}
Expand Down
30 changes: 0 additions & 30 deletions assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,36 +328,6 @@ func (a *assertions) expectsNotFound() bool {
return (exp.Len != nil && *exp.Len == 0) || exp.NotFound
}

// notFoundOK returns true if the supplied error and response matches the
// NotFound condition and the Len==0 condition, false otherwise
func (a *assertions) notFoundOK() bool {
if a.expectsNotFound() {
// First check if the error is like one returned from Get or Delete
// that has a 404 ErrStatus.Code in it
apierr, ok := a.err.(*apierrors.StatusError)
if ok {
if http.StatusNotFound != int(apierr.ErrStatus.Code) {
msg := fmt.Sprintf("got status code %d", apierr.ErrStatus.Code)
a.Fail(ExpectedNotFound(msg))
return false
}
return true
}
// Next check to see if the supplied resp is a list of objects returned
// by the dynamic client and if so, is that an empty list.
list, ok := a.r.(*unstructured.UnstructuredList)
if ok {
if len(list.Items) != 0 {
msg := fmt.Sprintf("got %d items", len(list.Items))
a.Fail(ExpectedNotFound(msg))
return false
}
return true
}
}
return true
}

// lenOK returns true if the subject matches the Len condition, false otherwise
func (a *assertions) lenOK() bool {
exp := a.exp
Expand Down
44 changes: 21 additions & 23 deletions compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package kube

import (
"fmt"
"io/ioutil"
"os"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -42,7 +42,7 @@ func compareConditions(
panic(msg)
}
if (!found || len(conds) == 0) && len(expected) != 0 {
for condType, _ := range expected {
for condType := range expected {
d.Add(fmt.Sprintf("no condition with type %q found", condType))
}
return d
Expand Down Expand Up @@ -130,13 +130,13 @@ func compareConditions(
// map[string]interface{} is the collection of resource fields that we will
// match against.
func matchObjectFromAny(m interface{}) map[string]interface{} {
switch m.(type) {
switch m := m.(type) {
case string:
var err error
var b []byte
v := m.(string)
v := m
if probablyFilePath(v) {
b, err = ioutil.ReadFile(v)
b, err = os.ReadFile(v)
if err != nil {
// NOTE(jaypipes): We already validated that the file exists at
// parse time. If we get an error here, just panic cuz there's
Expand All @@ -155,7 +155,7 @@ func matchObjectFromAny(m interface{}) map[string]interface{} {
}
return obj
case map[string]interface{}:
return m.(map[string]interface{})
return m
}
return map[string]interface{}{}
}
Expand Down Expand Up @@ -238,7 +238,7 @@ func collectFieldDifferences(
}
return
case int, int8, int16, int32, int64:
switch subject.(type) {
switch subject := subject.(type) {
case int, int8, int16, int32, int64:
mv := toInt64(match)
sv := toInt64(subject)
Expand All @@ -261,8 +261,7 @@ func collectFieldDifferences(
}
case string:
mv := toInt64(match)
ss := subject.(string)
sv, err := strconv.Atoi(ss)
sv, err := strconv.Atoi(subject)
if err != nil {
diff := fmt.Sprintf(
"%s had different values. expected %v but found %v",
Expand Down Expand Up @@ -296,8 +295,7 @@ func collectFieldDifferences(
}
case string:
mv, _ := match.(string)
sv, _ := subject.(string)
if mv != sv {
if mv != subject {
diff := fmt.Sprintf(
"%s had different values. expected %v but found %v",
fp, match, subject,
Expand Down Expand Up @@ -362,34 +360,34 @@ func typesComparable(a, b interface{}) bool {

// toUint64 takes an interface and returns a uint64
func toUint64(v interface{}) uint64 {
switch v.(type) {
switch v := v.(type) {
case uint64:
return v.(uint64)
return v
case uint8:
return uint64(v.(uint8))
return uint64(v)
case uint16:
return uint64(v.(uint16))
return uint64(v)
case uint32:
return uint64(v.(uint32))
return uint64(v)
case uint:
return uint64(v.(uint))
return uint64(v)
}
return 0
}

// toInt64 takes an interface and returns an int64
func toInt64(v interface{}) int64 {
switch v.(type) {
switch v := v.(type) {
case int64:
return v.(int64)
return v
case int8:
return int64(v.(int8))
return int64(v)
case int16:
return int64(v.(int16))
return int64(v)
case int32:
return int64(v.(int32))
return int64(v)
case int:
return int64(v.(int))
return int64(v)
}
return 0
}
2 changes: 1 addition & 1 deletion fixtures/kind/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (f *KindFixture) waitForDefaultServiceAccount(ctx context.Context) error {
)
ticker := backoff.NewTicker(bo)
attempts := 1
for _ = range ticker.C {
for range ticker.C {
found := true
_, err = clientset.CoreV1().ServiceAccounts("default").Get(context.TODO(), "default", metav1.GetOptions{})
if err != nil {
Expand Down
18 changes: 0 additions & 18 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,24 +356,6 @@ func (e *Expect) UnmarshalYAML(node *yaml.Node) error {
return nil
}

// expandShortcut looks at the shortcut fields (e.g. `kube.create`) and expands
// the shortcut into a full KubeSpec.
func expandShortcut(s *Spec) {
if s.Kube != nil {
return
}
ks := &KubeSpec{
Action: Action{},
}
if s.KubeCreate != "" {
ks.Create = s.KubeCreate
}
if s.KubeApply != "" {
ks.Apply = s.KubeApply
}
s.Kube = ks
}

// moreThanOneAction returns true if the test author has specified more than a
// single action in the KubeSpec.
func moreThanOneAction(a *Action) bool {
Expand Down
6 changes: 0 additions & 6 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package kube_test

import (
"path/filepath"
"runtime"
"testing"

"github.com/gdt-dev/gdt"
Expand All @@ -16,11 +15,6 @@ import (
"github.com/stretchr/testify/require"
)

func currentDir() string {
_, filename, _, _ := runtime.Caller(0)
return filepath.Dir(filename)
}

func TestFailureBadDefaults(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
Expand Down
6 changes: 6 additions & 0 deletions placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func getNodes(
Kind: "Node",
}
res, err := c.gvrFromGVK(gvk)
if err != nil {
panic(err)
}
opts := metav1.ListOptions{}
list, err := c.client.Resource(res).Namespace("").List(
ctx, opts,
Expand Down Expand Up @@ -94,6 +97,9 @@ func getPods(
Kind: "Pod",
}
res, err := c.gvrFromGVK(gvk)
if err != nil {
panic(err)
}
opts := client.ListOptions{
LabelSelector: ls,
Namespace: ns,
Expand Down

0 comments on commit f198f96

Please sign in to comment.