From e80d71f58881b3d26e73caeb1cbfeb57fc5a16bd Mon Sep 17 00:00:00 2001 From: dirgim Date: Tue, 12 Dec 2023 10:09:14 +0100 Subject: [PATCH] feat(STONEINTG-702): add tests for namespace-backed integration re-runs * This change adds e2e tests for the new functionality by adding the label in integration namespace-backed environment e2e tests and observing the retriggered pipelineRun is handled correctly Signed-off-by: dirgim --- go.mod | 2 +- tests/integration-service/integration.go | 20 ++-- .../namespace-backed-environments.go | 104 ++++++++++++++++++ 3 files changed, 117 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 0365150d50..79cb6db638 100644 --- a/go.mod +++ b/go.mod @@ -38,6 +38,7 @@ require ( github.com/redhat-appstudio/integration-service v0.0.0-20231017154915-ca19edc57d63 github.com/redhat-appstudio/jvm-build-service v0.0.0-20230821060312-4172397d68e8 github.com/redhat-appstudio/managed-gitops/backend-shared v0.0.0 + github.com/redhat-appstudio/operator-toolkit v0.0.0-20230913085326-6c5e9d368a6a github.com/redhat-appstudio/release-service v0.0.0-20231012135118-498f8de95cc4 github.com/redhat-appstudio/remote-secret v0.0.0-20230713072146-a6094c712436 github.com/redhat-appstudio/service-provider-integration-operator v0.2023.22-0.20230713080056-eae17aa8c172 @@ -260,7 +261,6 @@ require ( github.com/prometheus/procfs v0.11.1 // indirect github.com/prometheus/statsd_exporter v0.23.1 // indirect github.com/redhat-appstudio/application-service v0.0.0-20230717184417-67d31a01a776 // indirect - github.com/redhat-appstudio/operator-toolkit v0.0.0-20230913085326-6c5e9d368a6a // indirect github.com/redhat-developer/alizer/go v0.0.0-20230516215932-135a2bb3fb90 // indirect github.com/redhat-developer/gitops-generator v0.0.0-20230614175323-aff86c6bc55e // indirect github.com/redis/go-redis/v9 v9.0.5 // indirect diff --git a/tests/integration-service/integration.go b/tests/integration-service/integration.go index bbfb90574f..574bca7f5c 100644 --- a/tests/integration-service/integration.go +++ b/tests/integration-service/integration.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "github.com/redhat-appstudio/release-service/metadata" + "github.com/redhat-appstudio/operator-toolkit/metadata" "time" "github.com/devfile/library/v2/pkg/util" @@ -265,14 +265,15 @@ var _ = framework.IntegrationServiceSuiteDescribe("Integration Service E2E tests Expect(f.AsKubeAdmin.CommonController.HaveTestsSucceeded(snapshot)).To(BeFalse(), "expected tests to fail for snapshot %s/%s", snapshot.GetNamespace(), snapshot.GetName()) }) - It("creates a new IntegrationTestScenario", FlakeAttempts(3), func() { + It("creates a new IntegrationTestScenario", func() { newIntegrationTestScenario, err = f.AsKubeAdmin.IntegrationController.CreateIntegrationTestScenario(applicationName, testNamespace, BundleURL, InPipelineName) Expect(err).ShouldNot(HaveOccurred()) }) It("updates the Snapshot with the re-run label for the new scenario", FlakeAttempts(3), func() { updatedSnapshot := snapshot.DeepCopy() - metadata.AddLabels(updatedSnapshot, map[string]string{snapshotRerunLabel: newIntegrationTestScenario.Name}) + err := metadata.AddLabels(updatedSnapshot, map[string]string{snapshotRerunLabel: newIntegrationTestScenario.Name}) + Expect(err).ShouldNot(HaveOccurred()) Expect(f.AsKubeAdmin.IntegrationController.PatchSnapshot(snapshot, updatedSnapshot)).Should(Succeed()) Expect(metadata.GetLabelsWithPrefix(updatedSnapshot, snapshotRerunLabel)).NotTo(BeEmpty()) }) @@ -284,12 +285,16 @@ var _ = framework.IntegrationServiceSuiteDescribe("Integration Service E2E tests Expect(reRunPipelineRun).ShouldNot(BeNil()) }) - It("checks if the rerun label was removed from the Snapshot", FlakeAttempts(3), func() { + It("checks if the rerun label was removed from the Snapshot", func() { Eventually(func() error { snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshot.Name, "", "", testNamespace) - Expect(err).ShouldNot(HaveOccurred()) + if err != nil { + return fmt.Errorf("encountered errror while getting Snapshot %s/%s: %w", snapshot.Name, snapshot.Namespace, err) + } - Expect(metadata.GetLabelsWithPrefix(snapshot, snapshotRerunLabel)).To(BeEmpty()) + if metadata.HasLabel(snapshot, snapshotRerunLabel) { + return fmt.Errorf("the Snapshot %s/%s shouldn't contain the %s label", snapshot.Name, snapshot.Namespace, snapshotRerunLabel) + } return nil }, timeout, interval).Should(Succeed()) }) @@ -299,7 +304,7 @@ var _ = framework.IntegrationServiceSuiteDescribe("Integration Service E2E tests }) It("checks if the status of the re-triggered integration test is reported in the Snapshot", FlakeAttempts(3), func() { - Eventually(func() error { + Eventually(func(g Gomega) { snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshot.Name, "", "", testNamespace) Expect(err).ShouldNot(HaveOccurred()) @@ -312,7 +317,6 @@ var _ = framework.IntegrationServiceSuiteDescribe("Integration Service E2E tests Expect(integrationPipelineRun).NotTo(BeNil()) Expect(statusDetail.TestPipelineRunName).To(Equal(integrationPipelineRun.Name)) - return nil }, timeout, interval).Should(Succeed()) }) diff --git a/tests/integration-service/namespace-backed-environments.go b/tests/integration-service/namespace-backed-environments.go index 322190f2d4..0faefae519 100644 --- a/tests/integration-service/namespace-backed-environments.go +++ b/tests/integration-service/namespace-backed-environments.go @@ -2,6 +2,7 @@ package integration import ( "fmt" + "github.com/redhat-appstudio/operator-toolkit/metadata" "reflect" "strings" "time" @@ -33,6 +34,7 @@ var _ = framework.IntegrationServiceSuiteDescribe("Namespace-backed Environment var originalComponent *appstudioApi.Component var snapshot, snapshot_push *appstudioApi.Snapshot var integrationTestScenario *integrationv1beta1.IntegrationTestScenario + var newIntegrationTestScenario *integrationv1beta1.IntegrationTestScenario var env, ephemeralEnvironment, userPickedEnvironment *appstudioApi.Environment var dtcl *appstudioApi.DeploymentTargetClaimList var dtl *appstudioApi.DeploymentTargetList @@ -260,6 +262,108 @@ var _ = framework.IntegrationServiceSuiteDescribe("Namespace-backed Environment Expect(err.Error()).To(ContainSubstring(constants.EphemeralEnvAbsenceErrorString)) }) }) + + It("creates a new IntegrationTestScenario with ephemeral environment", func() { + var err error + newIntegrationTestScenario, err = f.AsKubeAdmin.IntegrationController.CreateIntegrationTestScenarioWithEnvironment(applicationName, testNamespace, gitURL, revisionForNBE, pathInRepoForNBE, userPickedEnvironment) + Expect(err).ShouldNot(HaveOccurred()) + }) + + It("updates the Snapshot with the re-run label for the new scenario", FlakeAttempts(3), func() { + updatedSnapshot := snapshot.DeepCopy() + err := metadata.AddLabels(updatedSnapshot, map[string]string{snapshotRerunLabel: newIntegrationTestScenario.Name}) + Expect(err).ShouldNot(HaveOccurred()) + Expect(f.AsKubeAdmin.IntegrationController.PatchSnapshot(snapshot, updatedSnapshot)).Should(Succeed()) + Expect(metadata.GetLabelsWithPrefix(updatedSnapshot, snapshotRerunLabel)).NotTo(BeEmpty()) + }) + + When("An snapshot is updated with a rerun label for a given scenario", func() { + It("checks if the rerun label was removed from the Snapshot", func() { + Eventually(func() error { + snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshot.Name, "", "", testNamespace) + if err != nil { + return fmt.Errorf("encountered errror while getting Snapshot %s/%s: %w", snapshot.Name, snapshot.Namespace, err) + } + + if metadata.HasLabel(snapshot, snapshotRerunLabel) { + return fmt.Errorf("the Snapshot %s/%s shouldn't contain the %s label", snapshot.Name, snapshot.Namespace, snapshotRerunLabel) + } + return nil + }, time.Minute*2, time.Second*5).Should(Succeed()) + }) + + It("creates an Ephemeral Environment", func() { + Eventually(func() error { + ephemeralEnvironment, err = f.AsKubeAdmin.GitOpsController.GetEphemeralEnvironment(snapshot.Spec.Application, snapshot.Name, newIntegrationTestScenario.Name, testNamespace) + return err + }, time.Minute*3, time.Second*1).Should(Succeed(), fmt.Sprintf("timed out when waiting for the creation of Ephemeral Environment related to snapshot %s", snapshot.Name)) + Expect(err).ToNot(HaveOccurred()) + Expect(ephemeralEnvironment.Name).ToNot(BeEmpty()) + }) + + It("checks for SEB after Ephemeral env has been created", func() { + seb, err = f.AsKubeAdmin.CommonController.GetSnapshotEnvironmentBinding(applicationName, testNamespace, ephemeralEnvironment) + Expect(err).ToNot(HaveOccurred()) + Expect(seb).ToNot(BeNil()) + Expect(seb.Spec.Snapshot).To(Equal(snapshot.Name)) + Expect(seb.Spec.Application).To(Equal(applicationName)) + Expect(seb.Spec.Environment).To(Equal(ephemeralEnvironment.Name)) + Expect(seb.Spec.Components).ToNot(BeEmpty()) + }) + + It("checks if the new integration pipelineRun started", Label("slow"), func() { + reRunPipelineRun, err := f.AsKubeDeveloper.IntegrationController.WaitForIntegrationPipelineToGetStarted(newIntegrationTestScenario.Name, snapshot.Name, testNamespace) + Expect(err).ShouldNot(HaveOccurred()) + Expect(reRunPipelineRun).ShouldNot(BeNil()) + + Expect(reRunPipelineRun.Labels[snapshotAnnotation]).To(ContainSubstring(snapshot.Name)) + Expect(reRunPipelineRun.Labels[scenarioAnnotation]).To(ContainSubstring(newIntegrationTestScenario.Name)) + Expect(reRunPipelineRun.Labels[environmentLabel]).To(ContainSubstring(ephemeralEnvironment.Name)) + }) + + It("checks if all integration pipelineRuns finished successfully", Label("slow"), func() { + Expect(f.AsKubeDeveloper.IntegrationController.WaitForAllIntegrationPipelinesToBeFinished(testNamespace, applicationName, snapshot)).To(Succeed()) + }) + + It("checks if the status of the re-triggered integration test is reported in the Snapshot", FlakeAttempts(3), func() { + Eventually(func(g Gomega) { + snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshot.Name, "", "", testNamespace) + Expect(err).ShouldNot(HaveOccurred()) + + statusDetail, err := f.AsKubeDeveloper.IntegrationController.GetIntegrationTestStatusDetailFromSnapshot(snapshot, newIntegrationTestScenario.Name) + Expect(err).ToNot(HaveOccurred()) + Expect(statusDetail).NotTo(BeNil()) + + integrationPipelineRun, err := f.AsKubeDeveloper.IntegrationController.GetIntegrationPipelineRun(newIntegrationTestScenario.Name, snapshot.Name, testNamespace) + Expect(err).ToNot(HaveOccurred()) + Expect(integrationPipelineRun).NotTo(BeNil()) + + Expect(statusDetail.TestPipelineRunName).To(Equal(integrationPipelineRun.Name)) + }, time.Minute*2, time.Second*5).Should(Succeed()) + }) + + It("checks if snapshot is still marked as successful", func() { + snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshot.Name, "", "", testNamespace) + Expect(err).ShouldNot(HaveOccurred()) + Expect(f.AsKubeAdmin.CommonController.HaveTestsSucceeded(snapshot)).To(BeTrue(), "expected tests to succeed for snapshot %s/%s", snapshot.GetNamespace(), snapshot.GetName()) + }) + + It("should lead to ephemeral environment getting deleted", func() { + Eventually(func() error { + ephemeralEnvironment, err = f.AsKubeAdmin.GitOpsController.GetEphemeralEnvironment(snapshot.Spec.Application, snapshot.Name, newIntegrationTestScenario.Name, testNamespace) + return err + }, time.Minute*3, time.Second*1).ShouldNot(Succeed(), fmt.Sprintf("timed out when waiting for the Ephemeral Environment %s to be deleted", ephemeralEnvironment.Name)) + Expect(err.Error()).To(ContainSubstring(constants.EphemeralEnvAbsenceErrorString)) + }) + + It("should lead to SnapshotEnvironmentBinding getting deleted", func() { + Eventually(func() error { + _, err = f.AsKubeAdmin.CommonController.GetSnapshotEnvironmentBinding(applicationName, testNamespace, ephemeralEnvironment) + return err + }, time.Minute*3, time.Second*5).ShouldNot(Succeed(), fmt.Sprintf("timed out when waiting for SnapshotEnvironmentBinding to be deleted for application %s/%s", testNamespace, applicationName)) + Expect(err.Error()).To(ContainSubstring(constants.SEBAbsenceErrorString)) + }) + }) }) Describe("when valid DeploymentTargetClass doesn't exist", Ordered, func() {