Skip to content

Commit

Permalink
Simplify code.
Browse files Browse the repository at this point in the history
  • Loading branch information
friedrichwilken committed Dec 8, 2023
1 parent 54ae363 commit a4addaa
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions e2e/cleanup/cleanup_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit a4addaa

Please sign in to comment.