diff --git a/helpers/scenario.go b/helpers/scenario.go index 802f8e383..05b4d10a7 100644 --- a/helpers/scenario.go +++ b/helpers/scenario.go @@ -59,3 +59,14 @@ func SetScenarioIntegrationStatusAsValid(scenario *v1beta2.IntegrationTestScenar func IsIntegrationTestScenarioOptional(scenario *v1beta2.IntegrationTestScenario) bool { return metadata.HasLabelWithValue(scenario, "test.appstudio.openshift.io/optional", "true") } + +// ScenarioValidationMessage returns the message of the scenario's +// IntegrationTestScenarioValid condition, or "" when the condition has not +// been set yet. +func ScenarioValidationMessage(scenario *v1beta2.IntegrationTestScenario) string { + cond := meta.FindStatusCondition(scenario.Status.Conditions, IntegrationTestScenarioValid) + if cond == nil { + return "" + } + return cond.Message +} diff --git a/helpers/scenario_test.go b/helpers/scenario_test.go index 31c678c07..197ca78d4 100644 --- a/helpers/scenario_test.go +++ b/helpers/scenario_test.go @@ -23,6 +23,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/konflux-ci/integration-service/api/v1beta2" + "github.com/konflux-ci/integration-service/helpers" ) var _ = Describe("Gitops functions for managing Snapshots", Ordered, func() { @@ -70,3 +71,16 @@ var _ = Describe("Gitops functions for managing Snapshots", Ordered, func() { Expect(err == nil || errors.IsNotFound(err)).To(BeTrue()) }) }) + +var _ = Describe("ScenarioValidationMessage", func() { + It("returns an empty message when the condition has not been set", func() { + scenario := &v1beta2.IntegrationTestScenario{} + Expect(helpers.ScenarioValidationMessage(scenario)).To(BeEmpty()) + }) + + It("returns the message of the IntegrationTestScenarioValid condition", func() { + scenario := &v1beta2.IntegrationTestScenario{} + helpers.SetScenarioIntegrationStatusAsInvalid(scenario, "pipeline not found") + Expect(helpers.ScenarioValidationMessage(scenario)).To(Equal("pipeline not found")) + }) +})