From c08394cfa2773c269ebea71e2ec1b2fa35829f52 Mon Sep 17 00:00:00 2001 From: marcobebway Date: Thu, 7 Dec 2023 09:53:44 +0100 Subject: [PATCH] Update tests --- .../controller/integration_test.go | 54 +++---------------- testutils/integration/integration.go | 19 +++++++ 2 files changed, 25 insertions(+), 48 deletions(-) diff --git a/internal/controller/nats/integrationtests/controller/integration_test.go b/internal/controller/nats/integrationtests/controller/integration_test.go index 68b19841..a850fe55 100644 --- a/internal/controller/nats/integrationtests/controller/integration_test.go +++ b/internal/controller/nats/integrationtests/controller/integration_test.go @@ -183,22 +183,8 @@ func Test_CreateNATSCR(t *testing.T) { testEnvironment.EnsureNATSSpecFileStorageReflected(t, *tc.givenNATS) } - // check url in the NATS CR status - natsCR, err := testEnvironment.GetNATSFromK8s(tc.givenNATS.Name, givenNamespace) - require.NoError(t, err) - require.NotNil(t, natsCR) - switch natsCR.Status.State { - case v1alpha1.StateReady: - { - wantURL := fmt.Sprintf("nats://%s.%s.svc.cluster.local:4222", natsCR.Name, natsCR.Namespace) - require.Equal(t, wantURL, natsCR.Status.URL) - } - default: - { - const wantURL = "" - require.Equal(t, wantURL, natsCR.Status.URL) - } - } + // check the url in the NATS CR status + testEnvironment.EnsureURLInNATSStatus(t, tc.givenNATS.Name, givenNamespace) }) } } @@ -282,22 +268,8 @@ func Test_UpdateNATSCR(t *testing.T) { givenNamespace, tc.givenUpdateNATS.Spec.Annotations) testEnvironment.EnsureNATSSpecMemStorageReflected(t, *tc.givenUpdateNATS) - // check url in the NATS CR status - natsCR, err := testEnvironment.GetNATSFromK8s(tc.givenNATS.Name, givenNamespace) - require.NoError(t, err) - require.NotNil(t, natsCR) - switch natsCR.Status.State { - case v1alpha1.StateReady: - { - wantURL := fmt.Sprintf("nats://%s.%s.svc.cluster.local:4222", natsCR.Name, natsCR.Namespace) - require.Equal(t, wantURL, natsCR.Status.URL) - } - default: - { - const wantURL = "" - require.Equal(t, wantURL, natsCR.Status.URL) - } - } + // check the url in the NATS CR status + testEnvironment.EnsureURLInNATSStatus(t, tc.givenNATS.Name, givenNamespace) }) } } @@ -625,22 +597,8 @@ func Test_DoubleReconcileNATSCR(t *testing.T) { // check NATS CR status again. testEnvironment.GetNATSAssert(g, tc.givenNATS).Should(tc.wantMatchers) - // check url in the NATS CR status - natsCR, err := testEnvironment.GetNATSFromK8s(tc.givenNATS.Name, givenNamespace) - require.NoError(t, err) - require.NotNil(t, natsCR) - switch natsCR.Status.State { - case v1alpha1.StateReady: - { - wantURL := fmt.Sprintf("nats://%s.%s.svc.cluster.local:4222", natsCR.Name, natsCR.Namespace) - require.Equal(t, wantURL, natsCR.Status.URL) - } - default: - { - const wantURL = "" - require.Equal(t, wantURL, natsCR.Status.URL) - } - } + // check the url in the NATS CR status + testEnvironment.EnsureURLInNATSStatus(t, tc.givenNATS.Name, givenNamespace) }) } } diff --git a/testutils/integration/integration.go b/testutils/integration/integration.go index 6dc3e3a2..02cfe25f 100644 --- a/testutils/integration/integration.go +++ b/testutils/integration/integration.go @@ -533,6 +533,25 @@ func (env TestEnvironment) EnsureNATSSpecMemStorageReflected(t *testing.T, nats }, SmallTimeOut, SmallPollingInterval, "failed to ensure NATS CR Spec.jetStream.memStorage") } +func (env TestEnvironment) EnsureURLInNATSStatus(t *testing.T, name, namespace string) { + natsCR, err := env.GetNATSFromK8s(name, namespace) + require.NoError(t, err) + require.NotNil(t, natsCR) + + switch natsCR.Status.State { + case natsv1alpha1.StateReady: + { + wantURL := fmt.Sprintf("nats://%s.%s.svc.cluster.local:4222", natsCR.Name, natsCR.Namespace) + require.Equal(t, wantURL, natsCR.Status.URL) + } + default: + { + const wantURL = "" + require.Equal(t, wantURL, natsCR.Status.URL) + } + } +} + func (env TestEnvironment) GetNATSFromK8s(name, namespace string) (natsv1alpha1.NATS, error) { var nats natsv1alpha1.NATS err := env.k8sClient.Get(env.Context, k8stypes.NamespacedName{