From cd980ee07649f7d042569048896a8829c12a8569 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Sat, 20 Jan 2024 11:44:16 -0500 Subject: [PATCH] Fix unit tests that expected the old FakeClient semantics --- .../reconcilers/endpointsadapter_test.go | 14 ++++++++------ pkg/volume/csi/csi_attacher_test.go | 1 + .../node_lifecycle_controller_test.go | 9 +++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pkg/controlplane/reconcilers/endpointsadapter_test.go b/pkg/controlplane/reconcilers/endpointsadapter_test.go index a8d5489fb83..e96bf5d9313 100644 --- a/pkg/controlplane/reconcilers/endpointsadapter_test.go +++ b/pkg/controlplane/reconcilers/endpointsadapter_test.go @@ -31,6 +31,8 @@ import ( "k8s.io/client-go/kubernetes/fake" ) +var noEndpoints = &corev1.Endpoints{} + func TestEndpointsAdapterGet(t *testing.T) { endpoints1, epSlice1 := generateEndpointsAndSlice("foo", "testing", []int{80, 443}, []string{"10.1.2.3", "10.1.2.4"}) @@ -57,21 +59,21 @@ func TestEndpointsAdapterGet(t *testing.T) { }, "endpointslice exists, endpoints does not": { expectedError: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "endpoints"}, "foo"), - expectedEndpoints: nil, + expectedEndpoints: noEndpoints, initialState: []runtime.Object{epSlice1}, namespaceParam: "testing", nameParam: "foo", }, "wrong-namespace": { expectedError: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "endpoints"}, "foo"), - expectedEndpoints: nil, + expectedEndpoints: noEndpoints, initialState: []runtime.Object{endpoints1, epSlice1}, namespaceParam: "foo", nameParam: "foo", }, "wrong-name": { expectedError: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "endpoints"}, "bar"), - expectedEndpoints: nil, + expectedEndpoints: noEndpoints, initialState: []runtime.Object{endpoints1, epSlice1}, namespaceParam: "testing", nameParam: "bar", @@ -144,7 +146,7 @@ func TestEndpointsAdapterCreate(t *testing.T) { }, "existing-endpoints": { expectedError: errors.NewAlreadyExists(schema.GroupResource{Group: "", Resource: "endpoints"}, "foo"), - expectedResult: nil, + expectedResult: noEndpoints, initialState: []runtime.Object{endpoints1, epSlice1}, namespaceParam: endpoints1.Namespace, endpointsParam: endpoints1, @@ -269,7 +271,7 @@ func TestEndpointsAdapterUpdate(t *testing.T) { }, "wrong-endpoints": { expectedError: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "endpoints"}, "bar"), - expectedResult: nil, + expectedResult: noEndpoints, expectUpdate: []runtime.Object{endpoints3}, initialState: []runtime.Object{endpoints1, epSlice1}, namespaceParam: "testing", @@ -277,7 +279,7 @@ func TestEndpointsAdapterUpdate(t *testing.T) { }, "missing-endpoints": { expectedError: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "endpoints"}, "bar"), - expectedResult: nil, + expectedResult: noEndpoints, initialState: []runtime.Object{endpoints1, epSlice1}, namespaceParam: "testing", endpointsParam: endpoints3, diff --git a/pkg/volume/csi/csi_attacher_test.go b/pkg/volume/csi/csi_attacher_test.go index 9e1281a3ac4..5e2fff1d964 100644 --- a/pkg/volume/csi/csi_attacher_test.go +++ b/pkg/volume/csi/csi_attacher_test.go @@ -83,6 +83,7 @@ func markVolumeAttached(t *testing.T, client clientset.Interface, watch *watch.R for i := 0; i < 100; i++ { attach, err = client.StorageV1().VolumeAttachments().Get(context.TODO(), attachID, metav1.GetOptions{}) if err != nil { + attach = nil if apierrors.IsNotFound(err) { <-ticker.C continue diff --git a/staging/src/k8s.io/cloud-provider/controllers/nodelifecycle/node_lifecycle_controller_test.go b/staging/src/k8s.io/cloud-provider/controllers/nodelifecycle/node_lifecycle_controller_test.go index 2132831d44a..b46a24436ad 100644 --- a/staging/src/k8s.io/cloud-provider/controllers/nodelifecycle/node_lifecycle_controller_test.go +++ b/staging/src/k8s.io/cloud-provider/controllers/nodelifecycle/node_lifecycle_controller_test.go @@ -64,6 +64,7 @@ func Test_NodesDeleted(t *testing.T) { }, }, }, + expectedNode: &v1.Node{}, expectedDeleted: true, fakeCloud: &fakecloud.Cloud{ ExistsByProviderID: false, @@ -178,6 +179,7 @@ func Test_NodesDeleted(t *testing.T) { }, }, }, + expectedNode: &v1.Node{}, expectedDeleted: true, fakeCloud: &fakecloud.Cloud{ ExistsByProviderID: false, @@ -289,6 +291,7 @@ func Test_NodesDeleted(t *testing.T) { }, }, }, + expectedNode: &v1.Node{}, expectedDeleted: true, fakeCloud: &fakecloud.Cloud{ EnableInstancesV2: true, @@ -406,6 +409,7 @@ func Test_NodesDeleted(t *testing.T) { }, }, }, + expectedNode: &v1.Node{}, expectedDeleted: true, fakeCloud: &fakecloud.Cloud{ EnableInstancesV2: true, @@ -674,6 +678,7 @@ func Test_NodesShutdown(t *testing.T) { }, }, }, + expectedNode: &v1.Node{}, expectedDeleted: true, fakeCloud: &fakecloud.Cloud{ ErrShutdownByProviderID: nil, @@ -751,6 +756,7 @@ func Test_NodesShutdown(t *testing.T) { }, }, }, + expectedNode: &v1.Node{}, expectedDeleted: true, fakeCloud: &fakecloud.Cloud{ ErrShutdownByProviderID: nil, @@ -777,6 +783,7 @@ func Test_NodesShutdown(t *testing.T) { }, }, }, + expectedNode: &v1.Node{}, expectedDeleted: true, fakeCloud: &fakecloud.Cloud{ NodeShutdown: false, @@ -801,6 +808,7 @@ func Test_NodesShutdown(t *testing.T) { }, }, }, + expectedNode: &v1.Node{}, expectedDeleted: true, fakeCloud: &fakecloud.Cloud{ NodeShutdown: false, @@ -865,6 +873,7 @@ func Test_NodesShutdown(t *testing.T) { }, }, }, + expectedNode: &v1.Node{}, expectedDeleted: true, fakeCloud: &fakecloud.Cloud{ NodeShutdown: true,