From a4addaa4259412369a810eca9b4415bf23eb56b0 Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Sat, 9 Dec 2023 00:00:27 +0100 Subject: [PATCH] Simplify code. --- e2e/cleanup/cleanup_test.go | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/e2e/cleanup/cleanup_test.go b/e2e/cleanup/cleanup_test.go index 40e58973..4f293bd6 100644 --- a/e2e/cleanup/cleanup_test.go +++ b/e2e/cleanup/cleanup_test.go @@ -1,6 +1,3 @@ -//go:build e2e -// +build e2e - // Package cleanup-test is part of the end-to-end-tests. This package contains tests that evaluate the deletion of NATS // CRs and the cascading deletion of all correlated Kubernetes resources. // To run the tests a k8s cluster and a NATS-CR need to be available and configured. For this reason, the tests are @@ -58,9 +55,8 @@ func TestMain(m *testing.M) { } // Delete the NATS CR. - ctx := context.TODO() err = Retry(attempts, interval, func() error { - errDel := k8sClient.Delete(ctx, NATSCR()) + errDel := k8sClient.Delete(context.TODO(), NATSCR()) // If it is gone already, that's fine too. if k8serrors.IsNotFound(errDel) { return nil @@ -80,10 +76,9 @@ func TestMain(m *testing.M) { func Test_NoPodsExists(t *testing.T) { t.Parallel() - ctx := context.TODO() err := Retry(attempts, interval, func() error { // Try to get the Pods. - pods, podErr := clientSet.CoreV1().Pods(NamespaceName).List(ctx, PodListOpts()) + pods, podErr := clientSet.CoreV1().Pods(NamespaceName).List(context.TODO(), PodListOpts()) if podErr != nil { return podErr } @@ -101,10 +96,9 @@ func Test_NoPodsExists(t *testing.T) { func Test_NoPVCsExists(t *testing.T) { t.Parallel() - ctx := context.TODO() err := Retry(attempts, interval, func() error { // Try to get the PVCs. - pvcs, pvcErr := clientSet.CoreV1().PersistentVolumeClaims(NamespaceName).List(ctx, PVCListOpts()) + pvcs, pvcErr := clientSet.CoreV1().PersistentVolumeClaims(NamespaceName).List(context.TODO(), PVCListOpts()) if pvcErr != nil { return pvcErr } @@ -122,10 +116,9 @@ func Test_NoPVCsExists(t *testing.T) { func Test_NoSTSExists(t *testing.T) { t.Parallel() - ctx := context.TODO() err := Retry(attempts, interval, func() error { // Try to get the STS. - _, stsErr := clientSet.AppsV1().StatefulSets(NamespaceName).Get(ctx, STSName, v1.GetOptions{}) + _, stsErr := clientSet.AppsV1().StatefulSets(NamespaceName).Get(context.TODO(), STSName, v1.GetOptions{}) // This is what we want here. if k8serrors.IsNotFound(stsErr) { return nil @@ -134,7 +127,7 @@ func Test_NoSTSExists(t *testing.T) { if stsErr != nil { return stsErr } - // If we still find and STS we will return an error. + // If we still find the STS we will return an error. return errors.New("found StatefulSet, but wanted the StatefulSet to be deleted") }) require.NoError(t, err) @@ -143,9 +136,8 @@ func Test_NoSTSExists(t *testing.T) { func Test_NoNATSSecretExists(t *testing.T) { t.Parallel() - ctx := context.TODO() err := Retry(attempts, interval, func() error { - _, secErr := clientSet.CoreV1().Secrets(NamespaceName).Get(ctx, SecretName, v1.GetOptions{}) + _, secErr := clientSet.CoreV1().Secrets(NamespaceName).Get(context.TODO(), SecretName, v1.GetOptions{}) // This is what we want here. if k8serrors.IsNotFound(secErr) { return nil @@ -163,9 +155,8 @@ func Test_NoNATSSecretExists(t *testing.T) { func Test_NoNATSCRExists(t *testing.T) { t.Parallel() - ctx := context.TODO() err := Retry(attempts, interval, func() error { - _, crErr := getNATSCR(ctx, CRName, NamespaceName) + _, crErr := getNATSCR(CRName, NamespaceName) // This is what we want here. if k8serrors.IsNotFound(crErr) { return nil @@ -180,9 +171,9 @@ func Test_NoNATSCRExists(t *testing.T) { require.NoError(t, err) } -func getNATSCR(ctx context.Context, name, namespace string) (*natsv1alpha1.NATS, error) { +func getNATSCR(name, namespace string) (*natsv1alpha1.NATS, error) { var natsCR natsv1alpha1.NATS - err := k8sClient.Get(ctx, k8stypes.NamespacedName{ + err := k8sClient.Get(context.TODO(), k8stypes.NamespacedName{ Name: name, Namespace: namespace, }, &natsCR)