From 22a3e73baccf1fa9bd278acd26448cc31e25563a Mon Sep 17 00:00:00 2001 From: Margo Crawford Date: Wed, 17 Feb 2021 17:29:56 -0800 Subject: [PATCH] impersonator_config_test.go: use require.Len() when applicable Also fix a lint error in concierge_impersonation_proxy_test.go Signed-off-by: Ryan Richard --- .../impersonator_config_test.go | 39 +++++++++---------- .../concierge_impersonation_proxy_test.go | 2 +- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/internal/controller/impersonatorconfig/impersonator_config_test.go b/internal/controller/impersonatorconfig/impersonator_config_test.go index d8163e29..d441eabb 100644 --- a/internal/controller/impersonatorconfig/impersonator_config_test.go +++ b/internal/controller/impersonatorconfig/impersonator_config_test.go @@ -466,7 +466,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { startInformersAndController() r.NoError(controllerlib.TestSync(t, subject, *syncContext)) requireTLSServerWasNeverStarted() - r.Equal(1, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 1) requireNodesListed(kubeAPIClient.Actions()[0]) }) }) @@ -482,7 +482,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { startInformersAndController() r.NoError(controllerlib.TestSync(t, subject, *syncContext)) requireTLSServerWasNeverStarted() - r.Equal(2, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 2) requireNodesListed(kubeAPIClient.Actions()[0]) requireLoadBalancerDeleted(kubeAPIClient.Actions()[1]) }) @@ -500,7 +500,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { }) it("starts the load balancer automatically", func() { - r.Equal(2, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 2) requireNodesListed(kubeAPIClient.Actions()[0]) requireLoadBalancerWasCreated(kubeAPIClient.Actions()[1]) }) @@ -520,7 +520,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { }) it("does not start the load balancer automatically", func() { - r.Equal(1, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 1) requireNodesListed(kubeAPIClient.Actions()[0]) }) }) @@ -534,7 +534,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { it("only starts the impersonator once and only lists the cluster's nodes once", func() { startInformersAndController() r.NoError(controllerlib.TestSync(t, subject, *syncContext)) - r.Equal(2, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 2) requireNodesListed(kubeAPIClient.Actions()[0]) requireLoadBalancerWasCreated(kubeAPIClient.Actions()[1]) @@ -545,7 +545,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { r.NoError(controllerlib.TestSync(t, subject, *syncContext)) r.Equal(1, startTLSListenerFuncWasCalled) // wasn't started a second time requireTLSServerIsRunning() // still running - r.Equal(2, len(kubeAPIClient.Actions())) // no new API calls + r.Len(kubeAPIClient.Actions(), 2) // no new API calls }) }) @@ -602,7 +602,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { r.NoError(controllerlib.TestSync(t, subject, *syncContext)) requireTLSServerWasNeverStarted() requireNodesListed(kubeAPIClient.Actions()[0]) - r.Equal(1, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 1) }) }) @@ -616,7 +616,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { r.NoError(controllerlib.TestSync(t, subject, *syncContext)) requireTLSServerIsRunning() requireNodesListed(kubeAPIClient.Actions()[0]) - r.Equal(1, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 1) }) }) }) @@ -632,12 +632,11 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { r.NoError(controllerlib.TestSync(t, subject, *syncContext)) requireTLSServerWasNeverStarted() requireNodesListed(kubeAPIClient.Actions()[0]) - r.Equal(1, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 1) }) }) when("the configuration is enabled mode", func() { - when("there are control plane nodes", func() { it.Before(func() { addImpersonatorConfigMapToTracker(configMapResourceName, "mode: enabled") @@ -659,7 +658,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { it("does not start the load balancer", func() { startInformersAndController() r.NoError(controllerlib.TestSync(t, subject, *syncContext)) - r.Equal(1, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 1) requireNodesListed(kubeAPIClient.Actions()[0]) }) }) @@ -687,7 +686,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { it("does not start the load balancer", func() { startInformersAndController() r.NoError(controllerlib.TestSync(t, subject, *syncContext)) - r.Equal(1, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 1) requireNodesListed(kubeAPIClient.Actions()[0]) }) }) @@ -715,7 +714,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { it("stops the load balancer", func() { startInformersAndController() r.NoError(controllerlib.TestSync(t, subject, *syncContext)) - r.Equal(2, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 2) requireNodesListed(kubeAPIClient.Actions()[0]) requireLoadBalancerDeleted(kubeAPIClient.Actions()[1]) }) @@ -742,7 +741,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { it("starts the load balancer", func() { startInformersAndController() r.NoError(controllerlib.TestSync(t, subject, *syncContext)) - r.Equal(2, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 2) requireNodesListed(kubeAPIClient.Actions()[0]) requireLoadBalancerWasCreated(kubeAPIClient.Actions()[1]) }) @@ -760,7 +759,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { r.NoError(controllerlib.TestSync(t, subject, *syncContext)) requireTLSServerIsRunning() - r.Equal(2, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 2) requireNodesListed(kubeAPIClient.Actions()[0]) requireLoadBalancerWasCreated(kubeAPIClient.Actions()[1]) @@ -773,7 +772,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { r.NoError(controllerlib.TestSync(t, subject, *syncContext)) requireTLSServerIsNoLongerRunning() - r.Equal(3, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 3) requireLoadBalancerDeleted(kubeAPIClient.Actions()[2]) deleteLoadBalancerServiceFromTracker(generatedLoadBalancerServiceName, kubeInformerClient) @@ -784,7 +783,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { r.NoError(controllerlib.TestSync(t, subject, *syncContext)) requireTLSServerIsRunning() - r.Equal(4, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 4) requireLoadBalancerWasCreated(kubeAPIClient.Actions()[3]) }) @@ -821,14 +820,14 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { r.NoError(controllerlib.TestSync(t, subject, *syncContext)) - r.Equal(1, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 1) requireNodesListed(kubeAPIClient.Actions()[0]) updateImpersonatorConfigMapInTracker(configMapResourceName, "mode: enabled", "1") waitForInformerCacheToSeeResourceVersion(kubeInformers.Core().V1().ConfigMaps().Informer(), "1") r.NoError(controllerlib.TestSync(t, subject, *syncContext)) - r.Equal(2, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 2) requireLoadBalancerWasCreated(kubeAPIClient.Actions()[1]) // update manually because the kubeAPIClient isn't connected to the informer in the tests @@ -842,7 +841,7 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { waitForInformerCacheToSeeResourceVersion(kubeInformers.Core().V1().ConfigMaps().Informer(), "2") r.NoError(controllerlib.TestSync(t, subject, *syncContext)) - r.Equal(3, len(kubeAPIClient.Actions())) + r.Len(kubeAPIClient.Actions(), 3) requireLoadBalancerDeleted(kubeAPIClient.Actions()[2]) }) }) diff --git a/test/integration/concierge_impersonation_proxy_test.go b/test/integration/concierge_impersonation_proxy_test.go index c8bbb8aa..3749a97f 100644 --- a/test/integration/concierge_impersonation_proxy_test.go +++ b/test/integration/concierge_impersonation_proxy_test.go @@ -61,7 +61,7 @@ func TestImpersonationProxy(t *testing.T) { oldConfigMap, err := adminClient.CoreV1().ConfigMaps(env.ConciergeNamespace).Get(ctx, "pinniped-concierge-impersonation-proxy-config", metav1.GetOptions{}) if oldConfigMap.Data != nil { - adminClient.CoreV1().ConfigMaps(env.ConciergeNamespace).Delete(ctx, "pinniped-concierge-impersonation-proxy-config", metav1.DeleteOptions{}) + require.NoError(t, adminClient.CoreV1().ConfigMaps(env.ConciergeNamespace).Delete(ctx, "pinniped-concierge-impersonation-proxy-config", metav1.DeleteOptions{})) } serviceUnavailableError := fmt.Sprintf(`Get "%s/api/v1/namespaces": Service Unavailable`, proxyServiceURL)