mirror of https://github.com/knative/pkg.git
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:
parent
4419e613c1
commit
f6cfa4c47c
|
@ -18,7 +18,7 @@ package storageversion
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
@ -71,8 +71,8 @@ func TestMigrate(t *testing.T) {
|
||||||
cclient := apixFake.NewSimpleClientset(fakeCRD)
|
cclient := apixFake.NewSimpleClientset(fakeCRD)
|
||||||
m := NewMigrator(dclient, cclient)
|
m := NewMigrator(dclient, cclient)
|
||||||
|
|
||||||
if err := m.Migrate(context.TODO(), fakeGR); err != nil {
|
if err := m.Migrate(context.Background(), fakeGR); err != nil {
|
||||||
t.Fatalf("Migrate() = %s", err)
|
t.Fatalf("Migrate() = %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assertPatches(t, dclient.Actions(),
|
assertPatches(t, dclient.Actions(),
|
||||||
|
@ -102,7 +102,7 @@ func TestMigrate_Errors(t *testing.T) {
|
||||||
crd: func(fake *k8stesting.Fake) {
|
crd: func(fake *k8stesting.Fake) {
|
||||||
fake.PrependReactor("get", "*",
|
fake.PrependReactor("get", "*",
|
||||||
func(k8stesting.Action) (bool, runtime.Object, error) {
|
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) {
|
dyn: func(fake *k8stesting.Fake) {
|
||||||
fake.PrependReactor("list", "*",
|
fake.PrependReactor("list", "*",
|
||||||
func(k8stesting.Action) (bool, runtime.Object, error) {
|
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) {
|
dyn: func(fake *k8stesting.Fake) {
|
||||||
fake.PrependReactor("patch", "*",
|
fake.PrependReactor("patch", "*",
|
||||||
func(k8stesting.Action) (bool, runtime.Object, error) {
|
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) {
|
crd: func(fake *k8stesting.Fake) {
|
||||||
fake.PrependReactor("patch", "*",
|
fake.PrependReactor("patch", "*",
|
||||||
func(k8stesting.Action) (bool, runtime.Object, error) {
|
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)
|
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")
|
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)
|
got := getPatchActions(actions)
|
||||||
if diff := cmp.Diff(got, want); diff != "" {
|
if diff := cmp.Diff(got, want); diff != "" {
|
||||||
t.Errorf("unexpected patches: %s", diff)
|
t.Error("Unexpected patches:", diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -490,7 +490,7 @@ func TestCheckDeprecatedUpdate(t *testing.T) {
|
||||||
}
|
}
|
||||||
for n, tc := range testCases {
|
for n, tc := range testCases {
|
||||||
t.Run(n, func(t *testing.T) {
|
t.Run(n, func(t *testing.T) {
|
||||||
ctx := context.TODO()
|
ctx := context.Background()
|
||||||
if tc.strict {
|
if tc.strict {
|
||||||
ctx = apis.DisallowDeprecated(ctx)
|
ctx = apis.DisallowDeprecated(ctx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ func TestSameGVR(t *testing.T) {
|
||||||
// counts the number of calls to cif.Get that returned
|
// counts the number of calls to cif.Get that returned
|
||||||
retGetCount := int32(0)
|
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
|
// 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
|
// 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
|
// counts the number of calls to cif.Get that returned
|
||||||
retGetCount := int32(0)
|
retGetCount := int32(0)
|
||||||
|
|
||||||
errGrp, _ := errgroup.WithContext(context.TODO())
|
errGrp, _ := errgroup.WithContext(context.Background())
|
||||||
|
|
||||||
const iter = 10
|
const iter = 10
|
||||||
for i := 0; i < iter; i++ {
|
for i := 0; i < iter; i++ {
|
||||||
|
|
|
@ -32,7 +32,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValidateDestination(t *testing.T) {
|
func TestValidateDestination(t *testing.T) {
|
||||||
ctx := context.TODO()
|
ctx := context.Background()
|
||||||
|
|
||||||
validRef := corev1.ObjectReference{
|
validRef := corev1.ObjectReference{
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
|
@ -205,7 +205,7 @@ func TestValidateDestination(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateDestinationDisallowDeprecated(t *testing.T) {
|
func TestValidateDestinationDisallowDeprecated(t *testing.T) {
|
||||||
ctx := context.TODO()
|
ctx := context.Background()
|
||||||
|
|
||||||
validRef := corev1.ObjectReference{
|
validRef := corev1.ObjectReference{
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
|
|
|
@ -41,5 +41,5 @@ func ClearAll() {}
|
||||||
|
|
||||||
// TestContextWithLogger returns a context with a logger to be used in tests
|
// TestContextWithLogger returns a context with a logger to be used in tests
|
||||||
func TestContextWithLogger(t zaptest.TestingT) context.Context {
|
func TestContextWithLogger(t zaptest.TestingT) context.Context {
|
||||||
return logging.WithLogger(context.TODO(), TestLogger(t))
|
return logging.WithLogger(context.Background(), TestLogger(t))
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,15 +23,15 @@ import (
|
||||||
|
|
||||||
func TestInnerDefaultResource_Validate(t *testing.T) {
|
func TestInnerDefaultResource_Validate(t *testing.T) {
|
||||||
r := InnerDefaultResource{}
|
r := InnerDefaultResource{}
|
||||||
if err := r.Validate(context.TODO()); err != nil {
|
if err := r.Validate(context.Background()); err != nil {
|
||||||
t.Fatalf("Expected no validation errors. Actual %v", err)
|
t.Error("Expected no validation errors. Actual:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInnerDefaultResource_SetDefaults(t *testing.T) {
|
func TestInnerDefaultResource_SetDefaults(t *testing.T) {
|
||||||
r := InnerDefaultResource{}
|
r := InnerDefaultResource{}
|
||||||
r.SetDefaults(context.TODO())
|
r.SetDefaults(context.Background())
|
||||||
if r.Spec.FieldWithDefault != "I'm a default." {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue