Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobebway committed Dec 7, 2023
1 parent 05c404f commit c08394c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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)
})
}
}
Expand Down
19 changes: 19 additions & 0 deletions testutils/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit c08394c

Please sign in to comment.