Fix unit tests that expected the old FakeClient semantics

This commit is contained in:
Dan Winship 2024-01-20 11:44:16 -05:00
parent 17ab25b121
commit cd980ee076
3 changed files with 18 additions and 6 deletions

View File

@ -31,6 +31,8 @@ import (
"k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/fake"
) )
var noEndpoints = &corev1.Endpoints{}
func TestEndpointsAdapterGet(t *testing.T) { func TestEndpointsAdapterGet(t *testing.T) {
endpoints1, epSlice1 := generateEndpointsAndSlice("foo", "testing", []int{80, 443}, []string{"10.1.2.3", "10.1.2.4"}) 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": { "endpointslice exists, endpoints does not": {
expectedError: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "endpoints"}, "foo"), expectedError: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "endpoints"}, "foo"),
expectedEndpoints: nil, expectedEndpoints: noEndpoints,
initialState: []runtime.Object{epSlice1}, initialState: []runtime.Object{epSlice1},
namespaceParam: "testing", namespaceParam: "testing",
nameParam: "foo", nameParam: "foo",
}, },
"wrong-namespace": { "wrong-namespace": {
expectedError: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "endpoints"}, "foo"), expectedError: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "endpoints"}, "foo"),
expectedEndpoints: nil, expectedEndpoints: noEndpoints,
initialState: []runtime.Object{endpoints1, epSlice1}, initialState: []runtime.Object{endpoints1, epSlice1},
namespaceParam: "foo", namespaceParam: "foo",
nameParam: "foo", nameParam: "foo",
}, },
"wrong-name": { "wrong-name": {
expectedError: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "endpoints"}, "bar"), expectedError: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "endpoints"}, "bar"),
expectedEndpoints: nil, expectedEndpoints: noEndpoints,
initialState: []runtime.Object{endpoints1, epSlice1}, initialState: []runtime.Object{endpoints1, epSlice1},
namespaceParam: "testing", namespaceParam: "testing",
nameParam: "bar", nameParam: "bar",
@ -144,7 +146,7 @@ func TestEndpointsAdapterCreate(t *testing.T) {
}, },
"existing-endpoints": { "existing-endpoints": {
expectedError: errors.NewAlreadyExists(schema.GroupResource{Group: "", Resource: "endpoints"}, "foo"), expectedError: errors.NewAlreadyExists(schema.GroupResource{Group: "", Resource: "endpoints"}, "foo"),
expectedResult: nil, expectedResult: noEndpoints,
initialState: []runtime.Object{endpoints1, epSlice1}, initialState: []runtime.Object{endpoints1, epSlice1},
namespaceParam: endpoints1.Namespace, namespaceParam: endpoints1.Namespace,
endpointsParam: endpoints1, endpointsParam: endpoints1,
@ -269,7 +271,7 @@ func TestEndpointsAdapterUpdate(t *testing.T) {
}, },
"wrong-endpoints": { "wrong-endpoints": {
expectedError: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "endpoints"}, "bar"), expectedError: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "endpoints"}, "bar"),
expectedResult: nil, expectedResult: noEndpoints,
expectUpdate: []runtime.Object{endpoints3}, expectUpdate: []runtime.Object{endpoints3},
initialState: []runtime.Object{endpoints1, epSlice1}, initialState: []runtime.Object{endpoints1, epSlice1},
namespaceParam: "testing", namespaceParam: "testing",
@ -277,7 +279,7 @@ func TestEndpointsAdapterUpdate(t *testing.T) {
}, },
"missing-endpoints": { "missing-endpoints": {
expectedError: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "endpoints"}, "bar"), expectedError: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "endpoints"}, "bar"),
expectedResult: nil, expectedResult: noEndpoints,
initialState: []runtime.Object{endpoints1, epSlice1}, initialState: []runtime.Object{endpoints1, epSlice1},
namespaceParam: "testing", namespaceParam: "testing",
endpointsParam: endpoints3, endpointsParam: endpoints3,

View File

@ -83,6 +83,7 @@ func markVolumeAttached(t *testing.T, client clientset.Interface, watch *watch.R
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
attach, err = client.StorageV1().VolumeAttachments().Get(context.TODO(), attachID, metav1.GetOptions{}) attach, err = client.StorageV1().VolumeAttachments().Get(context.TODO(), attachID, metav1.GetOptions{})
if err != nil { if err != nil {
attach = nil
if apierrors.IsNotFound(err) { if apierrors.IsNotFound(err) {
<-ticker.C <-ticker.C
continue continue

View File

@ -64,6 +64,7 @@ func Test_NodesDeleted(t *testing.T) {
}, },
}, },
}, },
expectedNode: &v1.Node{},
expectedDeleted: true, expectedDeleted: true,
fakeCloud: &fakecloud.Cloud{ fakeCloud: &fakecloud.Cloud{
ExistsByProviderID: false, ExistsByProviderID: false,
@ -178,6 +179,7 @@ func Test_NodesDeleted(t *testing.T) {
}, },
}, },
}, },
expectedNode: &v1.Node{},
expectedDeleted: true, expectedDeleted: true,
fakeCloud: &fakecloud.Cloud{ fakeCloud: &fakecloud.Cloud{
ExistsByProviderID: false, ExistsByProviderID: false,
@ -289,6 +291,7 @@ func Test_NodesDeleted(t *testing.T) {
}, },
}, },
}, },
expectedNode: &v1.Node{},
expectedDeleted: true, expectedDeleted: true,
fakeCloud: &fakecloud.Cloud{ fakeCloud: &fakecloud.Cloud{
EnableInstancesV2: true, EnableInstancesV2: true,
@ -406,6 +409,7 @@ func Test_NodesDeleted(t *testing.T) {
}, },
}, },
}, },
expectedNode: &v1.Node{},
expectedDeleted: true, expectedDeleted: true,
fakeCloud: &fakecloud.Cloud{ fakeCloud: &fakecloud.Cloud{
EnableInstancesV2: true, EnableInstancesV2: true,
@ -674,6 +678,7 @@ func Test_NodesShutdown(t *testing.T) {
}, },
}, },
}, },
expectedNode: &v1.Node{},
expectedDeleted: true, expectedDeleted: true,
fakeCloud: &fakecloud.Cloud{ fakeCloud: &fakecloud.Cloud{
ErrShutdownByProviderID: nil, ErrShutdownByProviderID: nil,
@ -751,6 +756,7 @@ func Test_NodesShutdown(t *testing.T) {
}, },
}, },
}, },
expectedNode: &v1.Node{},
expectedDeleted: true, expectedDeleted: true,
fakeCloud: &fakecloud.Cloud{ fakeCloud: &fakecloud.Cloud{
ErrShutdownByProviderID: nil, ErrShutdownByProviderID: nil,
@ -777,6 +783,7 @@ func Test_NodesShutdown(t *testing.T) {
}, },
}, },
}, },
expectedNode: &v1.Node{},
expectedDeleted: true, expectedDeleted: true,
fakeCloud: &fakecloud.Cloud{ fakeCloud: &fakecloud.Cloud{
NodeShutdown: false, NodeShutdown: false,
@ -801,6 +808,7 @@ func Test_NodesShutdown(t *testing.T) {
}, },
}, },
}, },
expectedNode: &v1.Node{},
expectedDeleted: true, expectedDeleted: true,
fakeCloud: &fakecloud.Cloud{ fakeCloud: &fakecloud.Cloud{
NodeShutdown: false, NodeShutdown: false,
@ -865,6 +873,7 @@ func Test_NodesShutdown(t *testing.T) {
}, },
}, },
}, },
expectedNode: &v1.Node{},
expectedDeleted: true, expectedDeleted: true,
fakeCloud: &fakecloud.Cloud{ fakeCloud: &fakecloud.Cloud{
NodeShutdown: true, NodeShutdown: true,