Skip to content

Commit 3c085b1

Browse files
committed
E2E tests should run in both cluster/namespace-scoped modes
Signed-off-by: Jonathan West <[email protected]>
1 parent b3e573f commit 3c085b1

File tree

5 files changed

+41
-14
lines changed

5 files changed

+41
-14
lines changed

hack/run-rollouts-manager-e2e-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ set -ex
2121

2222
if [ "$NAMESPACE_SCOPED_ARGO_ROLLOUTS" == "true" ]; then
2323

24-
go test -v -p=1 -timeout=30m -race -count=1 -coverprofile=coverage.out ./tests/e2e/. ./tests/e2e/namespace-scoped
24+
go test -v -p=1 -timeout=30m -race -count=1 -coverprofile=coverage.out ./tests/e2e/namespace-scoped
2525

2626
else
2727

tests/e2e/cluster-scoped/cluster_scoped_rollouts_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import (
2323

2424
var _ = Describe("Cluster-scoped RolloutManager tests", func() {
2525

26+
// Add the tests which are designed to run in both cluster-scoped and namespace-scoped modes.
27+
utils.RunRolloutsTests(false)
28+
2629
Context("Testing cluster-scoped RolloutManager behaviour", func() {
2730

2831
var (

tests/e2e/fixture/fixture.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func EnsureCleanSlate() error {
6767
}
6868

6969
// create default namespace used for Rollouts controller
70-
err = cleaner.ensureRlloutNamespaceExists(TestE2ENamespace)
70+
err = cleaner.ensureRolloutNamespaceExists(TestE2ENamespace)
7171
if err != nil {
7272
return err
7373
}
@@ -80,7 +80,7 @@ func EnsureCleanSlate() error {
8080
return nil
8181
}
8282

83-
func (cleaner *Cleaner) ensureRlloutNamespaceExists(namespaceParam string) error {
83+
func (cleaner *Cleaner) ensureRolloutNamespaceExists(namespaceParam string) error {
8484
if err := cleaner.deleteNamespace(namespaceParam); err != nil {
8585
return fmt.Errorf("unable to delete namespace '%s': %w", namespaceParam, err)
8686
}

tests/e2e/namespace-scoped/namespace_scoped_rollouts_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import (
2525

2626
var _ = Describe("Namespace-scoped RolloutManager tests", func() {
2727

28+
// Add the tests which are designed to run in both cluster-scoped and namespace-scoped modes.
29+
utils.RunRolloutsTests(true)
30+
2831
Context("Testing namespace-scoped RolloutManager behaviour", func() {
2932

3033
var (

tests/e2e/rollouts_test.go renamed to tests/e2e/rollout_tests_all.go

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ import (
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
)
2626

27-
var _ = Describe("RolloutManager tests", func() {
27+
// This file contains tests that should run in both namespace-scoped and cluster-scoped scenarios.
28+
// As of this writing, these function is called from the 'tests/e2e/(cluster-scoped/namespace-scoped)' packages.
29+
func RunRolloutsTests(namespaceScopedParam bool) {
2830

29-
Context("RolloutManager tests", func() {
31+
testType := "cluster-scoped"
32+
if namespaceScopedParam {
33+
testType = "namespace-scoped"
34+
}
35+
36+
Context("RolloutManager tests - "+testType, func() {
3037

3138
var (
3239
k8sClient client.Client
@@ -48,7 +55,7 @@ var _ = Describe("RolloutManager tests", func() {
4855
Namespace: fixture.TestE2ENamespace,
4956
},
5057
Spec: rolloutsmanagerv1alpha1.RolloutManagerSpec{
51-
NamespaceScoped: true,
58+
NamespaceScoped: namespaceScopedParam,
5259
},
5360
}
5461
})
@@ -57,11 +64,11 @@ var _ = Describe("RolloutManager tests", func() {
5764
It("should create the appropriate K8s resources", func() {
5865
Expect(k8sClient.Create(ctx, &rolloutManager)).To(Succeed())
5966

60-
By("setting the phase to \"Available\"")
67+
By("waiting for phase to be \"Available\"")
6168
Eventually(rolloutManager, "60s", "1s").Should(rolloutManagerFixture.HavePhase(rolloutsmanagerv1alpha1.PhaseAvailable))
6269

6370
By("Verify that expected resources are created.")
64-
ValidateArgoRolloutManagerResources(ctx, rolloutManager, k8sClient, true)
71+
ValidateArgoRolloutManagerResources(ctx, rolloutManager, k8sClient, namespaceScopedParam)
6572
})
6673
})
6774

@@ -127,7 +134,7 @@ var _ = Describe("RolloutManager tests", func() {
127134
"--loglevel",
128135
"error",
129136
},
130-
NamespaceScoped: true,
137+
NamespaceScoped: namespaceScopedParam,
131138
}
132139
Expect(k8sClient.Create(ctx, &rolloutManager)).To(Succeed())
133140
Eventually(rolloutManager, "1m", "1s").Should(rolloutManagerFixture.HavePhase(rolloutsmanagerv1alpha1.PhaseAvailable))
@@ -136,7 +143,15 @@ var _ = Describe("RolloutManager tests", func() {
136143
ObjectMeta: metav1.ObjectMeta{Name: controllers.DefaultArgoRolloutsResourceName, Namespace: rolloutManager.Namespace},
137144
}
138145
Eventually(&deployment, "10s", "1s").Should(k8s.ExistByName(k8sClient))
139-
Expect(deployment.Spec.Template.Spec.Containers[0].Args).To(Equal([]string{"--namespaced", "--loglevel", "error"}))
146+
147+
var expectedContainerArgs []string
148+
if namespaceScopedParam {
149+
expectedContainerArgs = []string{"--namespaced", "--loglevel", "error"}
150+
} else {
151+
expectedContainerArgs = []string{"--loglevel", "error"}
152+
}
153+
154+
Expect(deployment.Spec.Template.Spec.Containers[0].Args).To(Equal(expectedContainerArgs))
140155

141156
By("updating the deployment when the argument in the RolloutManager is updated")
142157

@@ -149,15 +164,21 @@ var _ = Describe("RolloutManager tests", func() {
149164
"--logformat",
150165
"text",
151166
},
152-
NamespaceScoped: true,
167+
NamespaceScoped: namespaceScopedParam,
153168
}
154169
})
155170
Expect(err).ToNot(HaveOccurred())
156171

172+
if namespaceScopedParam {
173+
expectedContainerArgs = []string{"--namespaced", "--logformat", "text"}
174+
} else {
175+
expectedContainerArgs = []string{"--logformat", "text"}
176+
}
177+
157178
Eventually(func() []string {
158179
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(&deployment), &deployment)).To(Succeed())
159180
return deployment.Spec.Template.Spec.Containers[0].Args
160-
}, "10s", "1s").Should(Equal([]string{"--namespaced", "--logformat", "text"}))
181+
}, "10s", "1s").Should(Equal(expectedContainerArgs))
161182
})
162183
})
163184

@@ -301,7 +322,7 @@ var _ = Describe("RolloutManager tests", func() {
301322
"foo-label2": "bar-label2",
302323
},
303324
},
304-
NamespaceScoped: true,
325+
NamespaceScoped: namespaceScopedParam,
305326
},
306327
}
307328

@@ -343,4 +364,4 @@ var _ = Describe("RolloutManager tests", func() {
343364
})
344365
})
345366
})
346-
})
367+
}

0 commit comments

Comments
 (0)