Skip to content

Commit dc6ad6d

Browse files
fix(STONEINTG-871): include an optional ITS (#1745)
Signed-off-by: nbyrne <nbyrne@redhat.com> Co-authored-by: Kasem Alem <kalem@redhat.com>
1 parent 9b9a6cf commit dc6ad6d

3 files changed

Lines changed: 92 additions & 1 deletion

File tree

pkg/clients/integration/integration_test_scenarios.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,64 @@ func (i *IntegrationController) CreateIntegrationTestScenario(itsName, applicati
6868
return integrationTestScenario, nil
6969
}
7070

71+
// CreateOptionalIntegrationTestScenario creates a beta1 version integrationTestScenario with optional: true label.
72+
// This function is identical to CreateIntegrationTestScenario except it sets the optional label to "true".
73+
func (i *IntegrationController) CreateOptionalIntegrationTestScenario(itsName, applicationName, namespace, gitURL, revision, pathInRepo, kind string, contexts []string) (*integrationv1beta2.IntegrationTestScenario, error) {
74+
if itsName == "" {
75+
itsName = "my-integration-test-" + util.GenerateRandomString(4)
76+
}
77+
78+
params := []integrationv1beta2.ResolverParameter{
79+
{
80+
Name: "url",
81+
Value: gitURL,
82+
},
83+
{
84+
Name: "revision",
85+
Value: revision,
86+
},
87+
{
88+
Name: "pathInRepo",
89+
Value: pathInRepo,
90+
},
91+
}
92+
93+
integrationTestScenario := &integrationv1beta2.IntegrationTestScenario{
94+
ObjectMeta: metav1.ObjectMeta{
95+
Name: itsName,
96+
Namespace: namespace,
97+
Labels: map[string]string{"test.appstudio.openshift.io/optional": "true"}, // NEW: Sets optional to true
98+
},
99+
Spec: integrationv1beta2.IntegrationTestScenarioSpec{
100+
Application: applicationName,
101+
ResolverRef: integrationv1beta2.ResolverRef{
102+
Resolver: "git",
103+
Params: params,
104+
},
105+
Contexts: []integrationv1beta2.TestContext{},
106+
},
107+
}
108+
109+
// Add kind parameter if provided and is "pipelineRun"
110+
if strings.EqualFold(kind, "pipelineRun") {
111+
integrationTestScenario.Spec.ResolverRef.ResourceKind = "pipelinerun"
112+
113+
}
114+
115+
if len(contexts) > 0 {
116+
for _, testContext := range contexts {
117+
integrationTestScenario.Spec.Contexts = append(integrationTestScenario.Spec.Contexts,
118+
integrationv1beta2.TestContext{Name: testContext, Description: testContext})
119+
}
120+
}
121+
122+
err := i.KubeRest().Create(context.Background(), integrationTestScenario)
123+
if err != nil {
124+
return nil, err
125+
}
126+
return integrationTestScenario, nil
127+
}
128+
71129
// Get return the status from the Application Custom Resource object.
72130
func (i *IntegrationController) GetIntegrationTestScenarios(applicationName, namespace string) (*[]integrationv1beta2.IntegrationTestScenario, error) {
73131
opts := []client.ListOption{

pkg/constants/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ const (
252252
CheckrunConclusionSuccess = "success"
253253
CheckrunConclusionFailure = "failure"
254254
CheckrunStatusCompleted = "completed"
255+
CheckrunConclusionNeutral = "neutral"
255256

256257
DockerBuild BuildPipelineType = "docker-build"
257258
DockerBuildOciTA BuildPipelineType = "docker-build-oci-ta"

tests/integration-service/status-reporting-to-pullrequest.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
appstudioApi "github.com/konflux-ci/application-api/api/v1alpha1"
1717
integrationv1beta2 "github.com/konflux-ci/integration-service/api/v1beta2"
18+
intgteststat "github.com/konflux-ci/integration-service/pkg/integrationteststatus"
1819
"github.com/konflux-ci/operator-toolkit/metadata"
1920
. "github.com/onsi/ginkgo/v2"
2021
. "github.com/onsi/gomega"
@@ -33,7 +34,7 @@ var _ = framework.IntegrationServiceSuiteDescribe("Status Reporting of Integrati
3334
var snapshot *appstudioApi.Snapshot
3435
var component *appstudioApi.Component
3536
var pipelineRun, testPipelinerun, failedPipelineRun *tektonv1.PipelineRun
36-
var integrationTestScenarioPass, integrationTestScenarioFail *integrationv1beta2.IntegrationTestScenario
37+
var integrationTestScenarioPass, integrationTestScenarioFail, integrationTestScenarioOptional *integrationv1beta2.IntegrationTestScenario
3738
var applicationName, componentName, componentBaseBranchName, pacBranchName, testNamespace string
3839
var mergeResult *github.PullRequestMergeResult
3940
var labels, annotations map[string]string
@@ -69,6 +70,8 @@ var _ = framework.IntegrationServiceSuiteDescribe("Status Reporting of Integrati
6970
Expect(err).ShouldNot(HaveOccurred())
7071
integrationTestScenarioFail, err = f.AsKubeAdmin.IntegrationController.CreateIntegrationTestScenario("", applicationName, testNamespace, gitURL, revision, pathInRepoFail, "", []string{})
7172
Expect(err).ShouldNot(HaveOccurred())
73+
integrationTestScenarioOptional, err = f.AsKubeAdmin.IntegrationController.CreateOptionalIntegrationTestScenario("", applicationName, testNamespace, gitURL, revision, pathInRepoFail, "", []string{})
74+
Expect(err).ShouldNot(HaveOccurred())
7275

7376
Eventually(func() error {
7477
pipelineRun, err = f.AsKubeAdmin.HasController.GetComponentPipelineRunWithType(componentName, applicationName, testNamespace, "build", "", "")
@@ -168,13 +171,19 @@ var _ = framework.IntegrationServiceSuiteDescribe("Status Reporting of Integrati
168171
Expect(err).ToNot(HaveOccurred())
169172
Expect(testPipelinerun.Labels[snapshotAnnotation]).To(ContainSubstring(snapshot.Name))
170173
Expect(testPipelinerun.Labels[scenarioAnnotation]).To(ContainSubstring(integrationTestScenarioFail.Name))
174+
175+
testPipelinerun, err = f.AsKubeDeveloper.IntegrationController.WaitForIntegrationPipelineToGetStarted(integrationTestScenarioOptional.Name, snapshot.Name, testNamespace)
176+
Expect(err).ToNot(HaveOccurred())
177+
Expect(testPipelinerun.Labels[snapshotAnnotation]).To(ContainSubstring(snapshot.Name))
178+
Expect(testPipelinerun.Labels[scenarioAnnotation]).To(ContainSubstring(integrationTestScenarioOptional.Name))
171179
})
172180
})
173181

174182
When("Integration PipelineRuns are created", func() {
175183
It("should eventually complete successfully", func() {
176184
Expect(f.AsKubeAdmin.IntegrationController.WaitForIntegrationPipelineToBeFinished(integrationTestScenarioPass, snapshot, testNamespace)).To(Succeed(), fmt.Sprintf("Error when waiting for an integration pipelinerun for snapshot %s/%s to finish", testNamespace, snapshot.GetName()))
177185
Expect(f.AsKubeAdmin.IntegrationController.WaitForIntegrationPipelineToBeFinished(integrationTestScenarioFail, snapshot, testNamespace)).To(Succeed(), fmt.Sprintf("Error when waiting for an integration pipelinerun for snapshot %s/%s to finish", testNamespace, snapshot.GetName()))
186+
Expect(f.AsKubeAdmin.IntegrationController.WaitForIntegrationPipelineToBeFinished(integrationTestScenarioOptional, snapshot, testNamespace)).To(Succeed(), fmt.Sprintf("Error when waiting for an integration pipelinerun for snapshot %s/%s to finish", testNamespace, snapshot.GetName()))
178187
})
179188
})
180189

@@ -201,6 +210,29 @@ var _ = framework.IntegrationServiceSuiteDescribe("Status Reporting of Integrati
201210
Expect(f.AsKubeAdmin.CommonController.Github.GetCheckRunConclusion(integrationTestScenarioFail.Name, componentRepoNameForStatusReporting, prHeadSha, prNumber)).To(Equal(constants.CheckrunConclusionFailure))
202211
})
203212

213+
It("eventually leads to the status reported at Checks tab for the optional Integration PipelineRun", func() {
214+
Expect(f.AsKubeAdmin.CommonController.Github.GetCheckRunConclusion(integrationTestScenarioOptional.Name, componentRepoNameForStatusReporting, prHeadSha, prNumber)).To(Equal(constants.CheckrunConclusionNeutral))
215+
})
216+
217+
It("checks if the optional Integration Test Scenario status is reported in the Snapshot", func() {
218+
Eventually(func() error {
219+
snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshot.Name, "", "", testNamespace)
220+
Expect(err).ShouldNot(HaveOccurred())
221+
222+
statusDetail, err := f.AsKubeDeveloper.IntegrationController.GetIntegrationTestStatusDetailFromSnapshot(snapshot, integrationTestScenarioOptional.Name)
223+
Expect(err).ToNot(HaveOccurred())
224+
225+
if statusDetail.Status != intgteststat.IntegrationTestStatusTestFail {
226+
return fmt.Errorf("test status doesn't have expected value %s", intgteststat.IntegrationTestStatusTestFail)
227+
}
228+
return nil
229+
}, shortTimeout, constants.PipelineRunPollingInterval).Should(Succeed())
230+
})
231+
232+
It("checks if the finalizer was removed from the optional Integration PipelineRun", func() {
233+
Expect(f.AsKubeDeveloper.IntegrationController.WaitForFinalizerToGetRemovedFromIntegrationPipeline(integrationTestScenarioOptional, snapshot, testNamespace)).To(Succeed())
234+
})
235+
204236
It("merging the PR, expected to succeed ", func() {
205237
Eventually(func() error {
206238
mergeResult, err = f.AsKubeAdmin.CommonController.Github.MergePullRequest(componentRepoNameForStatusReporting, prNumber)

0 commit comments

Comments
 (0)