Skip to content

Commit 416c539

Browse files
committed
Add 'disabled' field to IntegrationTestScenario spec
Add a boolean 'disabled' field to IntegrationTestScenarioSpec that allows users to skip a scenario without deleting it. When set to true, the scenario is filtered out in IsScenarioApplicableToSnapshotsContext before any context matching occurs. This provides a first-class mechanism to temporarily disable integration tests, replacing the current workaround of using unrecognized context names. Closes #1501
1 parent 9fff25a commit 416c539

4 files changed

Lines changed: 27 additions & 1 deletion

File tree

api/v1beta2/integrationtestscenario_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ type IntegrationTestScenarioSpec struct {
5454
Params []PipelineParameter `json:"params,omitempty"`
5555
// Contexts where this IntegrationTestScenario can be applied, for specific component for example
5656
Contexts []TestContext `json:"contexts,omitempty"`
57+
// Disabled indicates whether the IntegrationTestScenario should be skipped.
58+
// When set to true, the scenario will not be triggered for any Snapshot.
59+
// +optional
60+
Disabled bool `json:"disabled,omitempty"`
5761
// List of IntegrationTestScenario which are blocked by the successful completion of this IntegrationTestScenario
5862
Dependents []string `json:"dependents,omitempty"`
5963
}

config/crd/bases/appstudio.redhat.com_integrationtestscenarios.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,11 @@ spec:
519519
items:
520520
type: string
521521
type: array
522+
disabled:
523+
description: |-
524+
Disabled indicates whether the IntegrationTestScenario should be skipped.
525+
When set to true, the scenario will not be triggered for any Snapshot.
526+
type: boolean
522527
params:
523528
description: Params to pass to the pipeline
524529
items:

gitops/snapshot.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,10 @@ func IsContextValidForSnapshot(scenarioContextName string, snapshot *application
12561256
// IsScenarioApplicableToSnapshotsContext checks the contexts list for a given IntegrationTestScenario and
12571257
// compares it against the Snapshot to determine if the scenario applies to it
12581258
func IsScenarioApplicableToSnapshotsContext(scenario *v1beta2.IntegrationTestScenario, snapshot *applicationapiv1alpha1.Snapshot) bool {
1259+
// If the scenario is disabled, it should not be triggered for any Snapshot
1260+
if scenario.Spec.Disabled {
1261+
return false
1262+
}
12591263
// If the contexts list is empty, we assume that the scenario applies to all contexts by default
12601264
if len(scenario.Spec.Contexts) == 0 {
12611265
return true

gitops/snapshot_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,9 +1095,12 @@ var _ = Describe("Gitops functions for managing Snapshots", Ordered, func() {
10951095
unsupportedScenario := integrationTestScenario.DeepCopy()
10961096
unsupportedScenario.Spec.Contexts = []v1beta2.TestContext{{Name: "n/a"}}
10971097

1098+
disabledScenario := integrationTestScenario.DeepCopy()
1099+
disabledScenario.Spec.Disabled = true
1100+
10981101
allScenarios := []v1beta2.IntegrationTestScenario{*integrationTestScenario, *applicationScenario,
10991102
*componentScenario, *componentSampleScenario, *componentSample2Scenario, *pullRequestScenario,
1100-
*pushScenario, *groupScenario, *componentAndGroupScenario, *unsupportedScenario}
1103+
*pushScenario, *groupScenario, *componentAndGroupScenario, *unsupportedScenario, *disabledScenario}
11011104

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

1133+
It("Filters out disabled scenarios regardless of context or snapshot type", func() {
1134+
Expect(gitops.IsScenarioApplicableToSnapshotsContext(disabledScenario, hasSnapshot)).To(BeFalse())
1135+
1136+
// Also ensure a disabled scenario with explicit contexts is still filtered out
1137+
disabledWithContext := integrationTestScenario.DeepCopy()
1138+
disabledWithContext.Spec.Disabled = true
1139+
disabledWithContext.Spec.Contexts = []v1beta2.TestContext{{Name: "application"}}
1140+
Expect(gitops.IsScenarioApplicableToSnapshotsContext(disabledWithContext, hasSnapshot)).To(BeFalse())
1141+
})
1142+
11301143
It("Testing annotating snapshot", func() {
11311144
hasSnapshot.Labels[gitops.PipelineAsCodeEventTypeLabel] = gitops.PipelineAsCodePullRequestType
11321145
componentSnapshotInfos := []gitops.ComponentSnapshotInfo{

0 commit comments

Comments
 (0)