Skip to content

Commit

Permalink
feat(STONEINTG-702): add tests for integration pipeline re-runs
Browse files Browse the repository at this point in the history
* The integration service recreates a new Integration PipelineRun
  based on the value of the test.appstudio.openshift.io/run=<ITSName>
  label on a Snapshot
* This change adds e2e tests for the new functionality by
  adding the label in integration e2e tests and observing the
  retriggered pipelineRun is handled correctly

Signed-off-by: dirgim <[email protected]>
  • Loading branch information
dirgim committed Dec 11, 2023
1 parent 433f6ac commit e10d907
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/clients/integration/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ func (i *IntegrationController) DeleteSnapshot(hasSnapshot *appstudioApi.Snapsho
return err
}

// PatchSnapshot patches the given snapshot with the provided patch.
func (i *IntegrationController) PatchSnapshot(oldSnapshot *appstudioApi.Snapshot, newSnapshot *appstudioApi.Snapshot) error {
patch := client.MergeFrom(oldSnapshot)
err := i.KubeRest().Patch(context.Background(), newSnapshot, patch)
return err
}

// DeleteAllSnapshotsInASpecificNamespace removes all snapshots from a specific namespace. Useful when creating a lot of resources and want to remove all of them
func (i *IntegrationController) DeleteAllSnapshotsInASpecificNamespace(namespace string, timeout time.Duration) error {
if err := i.KubeRest().DeleteAllOf(context.Background(), &appstudioApi.Snapshot{}, client.InNamespace(namespace)); err != nil {
Expand Down
1 change: 1 addition & 0 deletions tests/integration-service/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
snapshotAnnotation = "appstudio.openshift.io/snapshot"
scenarioAnnotation = "test.appstudio.openshift.io/scenario"
pipelinerunFinalizerByIntegrationService = "test.appstudio.openshift.io/pipelinerun"
snapshotRerunLabel = "test.appstudio.openshift.io/run"
)

var (
Expand Down
61 changes: 61 additions & 0 deletions tests/integration-service/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integration

import (
"fmt"
"github.com/redhat-appstudio/release-service/metadata"
"time"

"github.com/devfile/library/v2/pkg/util"
Expand All @@ -28,6 +29,7 @@ var _ = framework.IntegrationServiceSuiteDescribe("Integration Service E2E tests

var applicationName, componentName, testNamespace string
var integrationTestScenario *integrationv1alpha1.IntegrationTestScenario
var newIntegrationTestScenario *integrationv1alpha1.IntegrationTestScenario
var timeout, interval time.Duration
var originalComponent *appstudioApi.Component
var pipelineRun *v1beta1.PipelineRun
Expand Down Expand Up @@ -263,6 +265,65 @@ 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() {
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})
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 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())
})

It("checks if the rerun label was removed from the Snapshot", FlakeAttempts(3), func() {
Eventually(func() error {
snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshot.Name, "", "", testNamespace)
Expect(err).ShouldNot(HaveOccurred())

Expect(metadata.GetLabelsWithPrefix(snapshot, snapshotRerunLabel)).To(BeEmpty())
return nil
}, timeout, interval).Should(Succeed())
})

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() error {
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))
return nil
}, timeout, interval).Should(Succeed())
})

It("checks if snapshot is still marked as failed", func() {
snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshot.Name, "", "", testNamespace)
Expect(err).ShouldNot(HaveOccurred())
Expect(f.AsKubeAdmin.CommonController.HaveTestsSucceeded(snapshot)).To(BeFalse(), "expected tests to fail for snapshot %s/%s", snapshot.GetNamespace(), snapshot.GetName())
})

})

It("creates an snapshot of push event", func() {
sampleImage := "quay.io/redhat-appstudio/sample-image@sha256:841328df1b9f8c4087adbdcfec6cc99ac8308805dea83f6d415d6fb8d40227c1"
snapshotPush, err = f.AsKubeAdmin.IntegrationController.CreateSnapshotWithImage(componentName, applicationName, testNamespace, sampleImage)
Expand Down

0 comments on commit e10d907

Please sign in to comment.