-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add e2e tests for the deleteNamespace feature
- Loading branch information
1 parent
f7f742b
commit 1ff1997
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
kind: GitRepo | ||
apiVersion: fleet.cattle.io/v1alpha1 | ||
metadata: | ||
name: my-gitrepo | ||
spec: | ||
repo: https://github.com/rancher/fleet-test-data | ||
branch: master | ||
paths: | ||
- helm-verify | ||
targetNamespace: {{.TargetNamespace}} | ||
deleteNamespace: {{.DeleteNamespace}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package singlecluster_test | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/rancher/fleet/e2e/testenv" | ||
"github.com/rancher/fleet/e2e/testenv/kubectl" | ||
) | ||
|
||
var _ = Describe("delete namespaces", func() { | ||
var ( | ||
k kubectl.Command | ||
targetNamespace string | ||
deleteNamespace bool | ||
) | ||
|
||
type TemplateData struct { | ||
TargetNamespace string | ||
DeleteNamespace bool | ||
} | ||
|
||
BeforeEach(func() { | ||
k = env.Kubectl.Namespace(env.Namespace) | ||
deleteNamespace = false | ||
|
||
DeferCleanup(func() { | ||
_, _ = k.Delete("ns", "my-custom-namespace", "--wait=false") | ||
}) | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
err := testenv.ApplyTemplate(k, testenv.AssetPath("single-cluster/delete-namespace/gitrepo.yaml"), | ||
TemplateData{targetNamespace, deleteNamespace}) | ||
|
||
Expect(err).ToNot(HaveOccurred()) | ||
Eventually(func() error { | ||
out, err := k.Namespace(targetNamespace).Get("configmaps") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !strings.Contains(out, "app-config") { | ||
return errors.New("expected configmap is not found") | ||
} | ||
|
||
return nil | ||
}).ShouldNot(HaveOccurred()) | ||
}) | ||
|
||
When("delete namespaces is false", func() { | ||
BeforeEach(func() { | ||
targetNamespace = "my-custom-namespace" | ||
}) | ||
|
||
It("preserves targetNamespace when GitRepo is deleted", func() { | ||
out, err := k.Delete("gitrepo", "my-gitrepo", "-n", "fleet-local") | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
|
||
Eventually(func() error { | ||
_, err := k.Get("namespaces", targetNamespace) | ||
return err | ||
}).ShouldNot(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
When("delete namespaces is true", func() { | ||
BeforeEach(func() { | ||
deleteNamespace = true | ||
}) | ||
|
||
It("targetNamespace is deleted after deleting gitRepo", func() { | ||
_, err := k.Get("namespaces", targetNamespace) | ||
Expect(err).To(BeNil()) | ||
|
||
out, err := k.Delete("gitrepo", "my-gitrepo", "-n", "fleet-local") | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
|
||
Eventually(func() error { | ||
_, err = k.Get("namespaces", targetNamespace) | ||
return err | ||
}).ShouldNot(BeNil()) | ||
}) | ||
}) | ||
|
||
When("delete namespaces is true but resources are deployed in default namespace", func() { | ||
BeforeEach(func() { | ||
deleteNamespace = true | ||
targetNamespace = "default" | ||
}) | ||
|
||
It("default namespace exists", func() { | ||
out, err := k.Delete("gitrepo", "my-gitrepo", "-n", "fleet-local") | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
|
||
Eventually(func() string { | ||
out, _ = k.Namespace(targetNamespace).Get("configmap", "app-config", "-o", "yaml") | ||
return out | ||
}).Should(ContainSubstring("Error from server (NotFound)")) | ||
|
||
_, err = k.Get("namespaces", targetNamespace) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
}) | ||
}) |