Skip to content
Open
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
4 changes: 4 additions & 0 deletions api/v1beta2/integrationtestscenario_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ type IntegrationTestScenarioSpec struct {
Params []PipelineParameter `json:"params,omitempty"`
// Contexts where this IntegrationTestScenario can be applied, for specific component for example
Contexts []TestContext `json:"contexts,omitempty"`
// Disabled indicates whether the IntegrationTestScenario should be skipped.
// When set to true, the scenario will not be triggered for any Snapshot.
// +optional
Disabled bool `json:"disabled,omitempty"`
// List of IntegrationTestScenario which are blocked by the successful completion of this IntegrationTestScenario
Dependents []string `json:"dependents,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@ spec:
items:
type: string
type: array
disabled:
description: |-
Disabled indicates whether the IntegrationTestScenario should be skipped.
When set to true, the scenario will not be triggered for any Snapshot.
type: boolean
params:
description: Params to pass to the pipeline
items:
Expand Down
4 changes: 4 additions & 0 deletions gitops/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,10 @@ func IsContextValidForSnapshot(scenarioContextName string, snapshot *application
// IsScenarioApplicableToSnapshotsContext checks the contexts list for a given IntegrationTestScenario and
// compares it against the Snapshot to determine if the scenario applies to it
func IsScenarioApplicableToSnapshotsContext(scenario *v1beta2.IntegrationTestScenario, snapshot *applicationapiv1alpha1.Snapshot) bool {
// If the scenario is disabled, it should not be triggered for any Snapshot
if scenario.Spec.Disabled {
return false
}
// If the contexts list is empty, we assume that the scenario applies to all contexts by default
if len(scenario.Spec.Contexts) == 0 {
return true
Expand Down
15 changes: 14 additions & 1 deletion gitops/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,9 +1095,12 @@ var _ = Describe("Gitops functions for managing Snapshots", Ordered, func() {
unsupportedScenario := integrationTestScenario.DeepCopy()
unsupportedScenario.Spec.Contexts = []v1beta2.TestContext{{Name: "n/a"}}

disabledScenario := integrationTestScenario.DeepCopy()
disabledScenario.Spec.Disabled = true

allScenarios := []v1beta2.IntegrationTestScenario{*integrationTestScenario, *applicationScenario,
*componentScenario, *componentSampleScenario, *componentSample2Scenario, *pullRequestScenario,
*pushScenario, *groupScenario, *componentAndGroupScenario, *unsupportedScenario}
*pushScenario, *groupScenario, *componentAndGroupScenario, *unsupportedScenario, *disabledScenario}

It("Returns only the scenarios matching the context for a given kind of Snapshot", func() {
// A component Snapshot for a push event referencing the component-sample
Expand Down Expand Up @@ -1127,6 +1130,16 @@ var _ = Describe("Gitops functions for managing Snapshots", Ordered, func() {
Expect(*filteredScenarios).To(HaveLen(3))
})

It("Filters out disabled scenarios regardless of context or snapshot type", func() {
Expect(gitops.IsScenarioApplicableToSnapshotsContext(disabledScenario, hasSnapshot)).To(BeFalse())

// Also ensure a disabled scenario with explicit contexts is still filtered out
disabledWithContext := integrationTestScenario.DeepCopy()
disabledWithContext.Spec.Disabled = true
disabledWithContext.Spec.Contexts = []v1beta2.TestContext{{Name: "application"}}
Expect(gitops.IsScenarioApplicableToSnapshotsContext(disabledWithContext, hasSnapshot)).To(BeFalse())
})

It("Testing annotating snapshot", func() {
hasSnapshot.Labels[gitops.PipelineAsCodeEventTypeLabel] = gitops.PipelineAsCodePullRequestType
componentSnapshotInfos := []gitops.ComponentSnapshotInfo{
Expand Down
Loading