Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run the E2E tests that work for both cluster-scoped and namespace-scope modes, on both #64

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hack/run-rollouts-manager-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set -ex

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

go test -v -p=1 -timeout=30m -race -count=1 -coverprofile=coverage.out ./tests/e2e/. ./tests/e2e/namespace-scoped
go test -v -p=1 -timeout=30m -race -count=1 -coverprofile=coverage.out ./tests/e2e/namespace-scoped
Copy link
Member Author

@jgwest jgwest Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed ./tests because that logic is now invoked directly from the namespace/cluster-scoped tests


else

Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/cluster-scoped/cluster_scoped_rollouts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (

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

// Add the tests which are designed to run in both cluster-scoped and namespace-scoped modes.
utils.RunRolloutsTests(false)

Context("Testing cluster-scoped RolloutManager behaviour", func() {

var (
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/fixture/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func EnsureCleanSlate() error {
}

// create default namespace used for Rollouts controller
err = cleaner.ensureRlloutNamespaceExists(TestE2ENamespace)
err = cleaner.ensureRolloutNamespaceExists(TestE2ENamespace)
if err != nil {
return err
}
Expand All @@ -80,7 +80,7 @@ func EnsureCleanSlate() error {
return nil
}

func (cleaner *Cleaner) ensureRlloutNamespaceExists(namespaceParam string) error {
func (cleaner *Cleaner) ensureRolloutNamespaceExists(namespaceParam string) error {
if err := cleaner.deleteNamespace(namespaceParam); err != nil {
return fmt.Errorf("unable to delete namespace '%s': %w", namespaceParam, err)
}
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/namespace-scoped/namespace_scoped_rollouts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (

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

// Add the tests which are designed to run in both cluster-scoped and namespace-scoped modes.
utils.RunRolloutsTests(true)

Context("Testing namespace-scoped RolloutManager behaviour", func() {

var (
Expand Down
43 changes: 32 additions & 11 deletions tests/e2e/rollouts_test.go → tests/e2e/rollout_tests_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

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

Context("RolloutManager tests", func() {
testType := "cluster-scoped"
if namespaceScopedParam {
testType = "namespace-scoped"
}

Context("RolloutManager tests - "+testType, func() {

var (
k8sClient client.Client
Expand All @@ -48,7 +55,7 @@ var _ = Describe("RolloutManager tests", func() {
Namespace: fixture.TestE2ENamespace,
},
Spec: rolloutsmanagerv1alpha1.RolloutManagerSpec{
NamespaceScoped: true,
NamespaceScoped: namespaceScopedParam,
},
}
})
Expand All @@ -57,11 +64,11 @@ var _ = Describe("RolloutManager tests", func() {
It("should create the appropriate K8s resources", func() {
Expect(k8sClient.Create(ctx, &rolloutManager)).To(Succeed())

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

By("Verify that expected resources are created.")
ValidateArgoRolloutManagerResources(ctx, rolloutManager, k8sClient, true)
ValidateArgoRolloutManagerResources(ctx, rolloutManager, k8sClient, namespaceScopedParam)
})
})

Expand Down Expand Up @@ -127,7 +134,7 @@ var _ = Describe("RolloutManager tests", func() {
"--loglevel",
"error",
},
NamespaceScoped: true,
NamespaceScoped: namespaceScopedParam,
}
Expect(k8sClient.Create(ctx, &rolloutManager)).To(Succeed())
Eventually(rolloutManager, "1m", "1s").Should(rolloutManagerFixture.HavePhase(rolloutsmanagerv1alpha1.PhaseAvailable))
Expand All @@ -136,7 +143,15 @@ var _ = Describe("RolloutManager tests", func() {
ObjectMeta: metav1.ObjectMeta{Name: controllers.DefaultArgoRolloutsResourceName, Namespace: rolloutManager.Namespace},
}
Eventually(&deployment, "10s", "1s").Should(k8s.ExistByName(k8sClient))
Expect(deployment.Spec.Template.Spec.Containers[0].Args).To(Equal([]string{"--namespaced", "--loglevel", "error"}))

var expectedContainerArgs []string
if namespaceScopedParam {
expectedContainerArgs = []string{"--namespaced", "--loglevel", "error"}
} else {
expectedContainerArgs = []string{"--loglevel", "error"}
}

Expect(deployment.Spec.Template.Spec.Containers[0].Args).To(Equal(expectedContainerArgs))

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

Expand All @@ -149,15 +164,21 @@ var _ = Describe("RolloutManager tests", func() {
"--logformat",
"text",
},
NamespaceScoped: true,
NamespaceScoped: namespaceScopedParam,
}
})
Expect(err).ToNot(HaveOccurred())

if namespaceScopedParam {
expectedContainerArgs = []string{"--namespaced", "--logformat", "text"}
} else {
expectedContainerArgs = []string{"--logformat", "text"}
}

Eventually(func() []string {
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(&deployment), &deployment)).To(Succeed())
return deployment.Spec.Template.Spec.Containers[0].Args
}, "10s", "1s").Should(Equal([]string{"--namespaced", "--logformat", "text"}))
}, "10s", "1s").Should(Equal(expectedContainerArgs))
})
})

Expand Down Expand Up @@ -301,7 +322,7 @@ var _ = Describe("RolloutManager tests", func() {
"foo-label2": "bar-label2",
},
},
NamespaceScoped: true,
NamespaceScoped: namespaceScopedParam,
},
}

Expand Down Expand Up @@ -343,4 +364,4 @@ var _ = Describe("RolloutManager tests", func() {
})
})
})
})
}
Loading