Clean context.TODO in pkg and other minor nits (#1337)

- TODO is for migration, we know we want background there
- other nits
This commit is contained in:
Victor Agababov 2020-05-15 10:58:02 -07:00 committed by GitHub
parent 4419e613c1
commit f6cfa4c47c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 19 deletions

View File

@ -18,7 +18,7 @@ package storageversion
import (
"context"
"fmt"
"errors"
"testing"
"github.com/google/go-cmp/cmp"
@ -71,8 +71,8 @@ func TestMigrate(t *testing.T) {
cclient := apixFake.NewSimpleClientset(fakeCRD)
m := NewMigrator(dclient, cclient)
if err := m.Migrate(context.TODO(), fakeGR); err != nil {
t.Fatalf("Migrate() = %s", err)
if err := m.Migrate(context.Background(), fakeGR); err != nil {
t.Fatalf("Migrate() = %v", err)
}
assertPatches(t, dclient.Actions(),
@ -102,7 +102,7 @@ func TestMigrate_Errors(t *testing.T) {
crd: func(fake *k8stesting.Fake) {
fake.PrependReactor("get", "*",
func(k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, fmt.Errorf("failed to get crd")
return true, nil, errors.New("failed to get crd")
})
},
}, {
@ -110,7 +110,7 @@ func TestMigrate_Errors(t *testing.T) {
dyn: func(fake *k8stesting.Fake) {
fake.PrependReactor("list", "*",
func(k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, fmt.Errorf("failed to list resources")
return true, nil, errors.New("failed to list resources")
})
},
}, {
@ -118,7 +118,7 @@ func TestMigrate_Errors(t *testing.T) {
dyn: func(fake *k8stesting.Fake) {
fake.PrependReactor("patch", "*",
func(k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, fmt.Errorf("failed to patch resources")
return true, nil, errors.New("failed to patch resources")
})
},
}, {
@ -126,7 +126,7 @@ func TestMigrate_Errors(t *testing.T) {
crd: func(fake *k8stesting.Fake) {
fake.PrependReactor("patch", "*",
func(k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, fmt.Errorf("failed to patch definition")
return true, nil, errors.New("failed to patch definition")
})
},
},
@ -148,7 +148,7 @@ func TestMigrate_Errors(t *testing.T) {
}
m := NewMigrator(dclient, cclient)
if err := m.Migrate(context.TODO(), fakeGR); err == nil {
if err := m.Migrate(context.Background(), fakeGR); err == nil {
t.Error("Migrate should have returned an error")
}
})
@ -160,7 +160,7 @@ func assertPatches(t *testing.T, actions []k8stesting.Action, want ...k8stesting
got := getPatchActions(actions)
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("unexpected patches: %s", diff)
t.Error("Unexpected patches:", diff)
}
}

View File

@ -490,7 +490,7 @@ func TestCheckDeprecatedUpdate(t *testing.T) {
}
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {
ctx := context.TODO()
ctx := context.Background()
if tc.strict {
ctx = apis.DisallowDeprecated(ctx)
}

View File

@ -57,7 +57,7 @@ func TestSameGVR(t *testing.T) {
// counts the number of calls to cif.Get that returned
retGetCount := int32(0)
errGrp, _ := errgroup.WithContext(context.TODO())
errGrp, _ := errgroup.WithContext(context.Background())
// Use the same GVR each iteration to ensure we hit the cache and don't
// initialize the informerCache for that GVR multiple times through our
@ -116,7 +116,7 @@ func TestDifferentGVRs(t *testing.T) {
// counts the number of calls to cif.Get that returned
retGetCount := int32(0)
errGrp, _ := errgroup.WithContext(context.TODO())
errGrp, _ := errgroup.WithContext(context.Background())
const iter = 10
for i := 0; i < iter; i++ {

View File

@ -32,7 +32,7 @@ const (
)
func TestValidateDestination(t *testing.T) {
ctx := context.TODO()
ctx := context.Background()
validRef := corev1.ObjectReference{
Kind: kind,
@ -205,7 +205,7 @@ func TestValidateDestination(t *testing.T) {
}
func TestValidateDestinationDisallowDeprecated(t *testing.T) {
ctx := context.TODO()
ctx := context.Background()
validRef := corev1.ObjectReference{
Kind: kind,

View File

@ -41,5 +41,5 @@ func ClearAll() {}
// TestContextWithLogger returns a context with a logger to be used in tests
func TestContextWithLogger(t zaptest.TestingT) context.Context {
return logging.WithLogger(context.TODO(), TestLogger(t))
return logging.WithLogger(context.Background(), TestLogger(t))
}

View File

@ -23,15 +23,15 @@ import (
func TestInnerDefaultResource_Validate(t *testing.T) {
r := InnerDefaultResource{}
if err := r.Validate(context.TODO()); err != nil {
t.Fatalf("Expected no validation errors. Actual %v", err)
if err := r.Validate(context.Background()); err != nil {
t.Error("Expected no validation errors. Actual:", err)
}
}
func TestInnerDefaultResource_SetDefaults(t *testing.T) {
r := InnerDefaultResource{}
r.SetDefaults(context.TODO())
r.SetDefaults(context.Background())
if r.Spec.FieldWithDefault != "I'm a default." {
t.Fatalf("Unexpected defaulted value: %v", r.Spec.FieldWithDefault)
t.Errorf("Unexpected defaulted value: %v", r.Spec.FieldWithDefault)
}
}