Skip to content

Commit

Permalink
tests: keep all suite cleanup functions in suite_test.go
Browse files Browse the repository at this point in the history
Signed-off-by: Raghavendra Talur <[email protected]>
  • Loading branch information
raghavendra-talur authored and ShyamsundarR committed Sep 6, 2024
1 parent 91ebfba commit b635a80
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
24 changes: 22 additions & 2 deletions internal/controller/ramenconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ package controllers_test
import (
"context"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
ramen "github.com/ramendr/ramen/api/v1alpha1"
controllers "github.com/ramendr/ramen/internal/controller"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/yaml"
Expand All @@ -26,10 +26,30 @@ func configMapCreate(ramenConfig *ramen.RamenConfig) {
configMap, err := controllers.ConfigMapNew(ramenNamespace, configMapName, ramenConfig)
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient.Create(context.TODO(), configMap)).To(Succeed())
DeferCleanup(k8sClient.Delete, context.TODO(), configMap)
}
}

func configMapDelete() error {
for _, configMapName := range configMapNames {
cm := &corev1.ConfigMap{}

err := k8sClient.Get(context.TODO(), types.NamespacedName{
Namespace: ramenNamespace,
Name: configMapName,
}, cm)
if err != nil && !errors.IsNotFound(err) {
return err
}

err = k8sClient.Delete(context.TODO(), cm)
if err != nil && !errors.IsNotFound(err) {
return err
}
}

return nil
}

func configMapUpdate() {
ramenConfigYaml, err := yaml.Marshal(ramenConfig)
Expect(err).NotTo(HaveOccurred())
Expand Down
1 change: 1 addition & 0 deletions internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ var _ = BeforeSuite(func() {
ramenConfig.DrClusterOperator.S3SecretDistributionEnabled = true
ramenConfig.MultiNamespace.FeatureEnabled = true
configMapCreate(ramenConfig)
DeferCleanup(configMapDelete)

s3Secrets[0] = corev1.Secret{
ObjectMeta: metav1.ObjectMeta{Namespace: ramenNamespace, Name: "s3secret0"},
Expand Down

0 comments on commit b635a80

Please sign in to comment.