Fixing a flaky EndpointSliceMirroring integration test

This test was trying to create an Endpoints resource that the Endpoints
controller would also attempt to create. This could result in a failure
if the Endpoints controller created the resource before the test did.
This commit is contained in:
Rob Scott 2020-08-18 12:52:54 -07:00
parent 544b74c2cb
commit 43ce0c53cc
No known key found for this signature in database
GPG Key ID: 90C19B2D4A99C91B

View File

@ -84,7 +84,7 @@ func TestEndpointSliceMirroring(t *testing.T) {
testCases := []struct {
testName string
service *corev1.Service
endpoints *corev1.Endpoints
customEndpoints *corev1.Endpoints
expectEndpointSlice bool
expectEndpointSliceManagedBy string
}{{
@ -102,11 +102,6 @@ func TestEndpointSliceMirroring(t *testing.T) {
},
},
},
endpoints: &corev1.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Name: "test-123",
},
},
expectEndpointSlice: true,
expectEndpointSliceManagedBy: "endpointslice-controller.k8s.io",
}, {
@ -121,7 +116,7 @@ func TestEndpointSliceMirroring(t *testing.T) {
}},
},
},
endpoints: &corev1.Endpoints{
customEndpoints: &corev1.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Name: "test-123",
},
@ -151,13 +146,13 @@ func TestEndpointSliceMirroring(t *testing.T) {
},
},
},
endpoints: nil,
customEndpoints: nil,
expectEndpointSlice: true,
expectEndpointSliceManagedBy: "endpointslice-controller.k8s.io",
}, {
testName: "Endpoints without Service",
service: nil,
endpoints: &corev1.Endpoints{
customEndpoints: &corev1.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Name: "test-123",
},
@ -180,10 +175,10 @@ func TestEndpointSliceMirroring(t *testing.T) {
}
}
if tc.endpoints != nil {
resourceName = tc.endpoints.Name
tc.endpoints.Namespace = ns.Name
_, err = client.CoreV1().Endpoints(ns.Name).Create(context.TODO(), tc.endpoints, metav1.CreateOptions{})
if tc.customEndpoints != nil {
resourceName = tc.customEndpoints.Name
tc.customEndpoints.Namespace = ns.Name
_, err = client.CoreV1().Endpoints(ns.Name).Create(context.TODO(), tc.customEndpoints, metav1.CreateOptions{})
if err != nil {
t.Fatalf("Error creating endpoints: %v", err)
}