|
| 1 | +package integration |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "time" |
| 7 | + |
| 8 | + "github.com/konflux-ci/e2e-tests/pkg/clients/has" |
| 9 | + "github.com/konflux-ci/e2e-tests/pkg/constants" |
| 10 | + "github.com/konflux-ci/e2e-tests/pkg/framework" |
| 11 | + "github.com/konflux-ci/e2e-tests/pkg/utils" |
| 12 | + |
| 13 | + appstudioApi "github.com/konflux-ci/application-api/api/v1alpha1" |
| 14 | + integrationv1beta2 "github.com/konflux-ci/integration-service/api/v1beta2" |
| 15 | + . "github.com/onsi/ginkgo/v2" |
| 16 | + . "github.com/onsi/gomega" |
| 17 | + pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" |
| 18 | +) |
| 19 | + |
| 20 | +var _ = framework.IntegrationServiceSuiteDescribe("Status Reporting of Integration tests", Label("integration-service", "github-status-reporting"), func() { |
| 21 | + defer GinkgoRecover() |
| 22 | + |
| 23 | + var f *framework.Framework |
| 24 | + var err error |
| 25 | + |
| 26 | + var prNumber int |
| 27 | + var timeout, interval time.Duration |
| 28 | + var prHeadSha string |
| 29 | + var snapshot *appstudioApi.Snapshot |
| 30 | + var component *appstudioApi.Component |
| 31 | + var pipelineRun, testPipelinerun *pipeline.PipelineRun |
| 32 | + var integrationTestScenarioPass, integrationTestScenarioFail *integrationv1beta2.IntegrationTestScenario |
| 33 | + var applicationName, componentName, componentBaseBranchName, pacBranchName, testNamespace string |
| 34 | + |
| 35 | + AfterEach(framework.ReportFailure(&f)) |
| 36 | + |
| 37 | + Describe("with status reporting of Integration tests in CheckRuns", Ordered, func() { |
| 38 | + BeforeAll(func() { |
| 39 | + if os.Getenv(constants.SKIP_PAC_TESTS_ENV) == "true" { |
| 40 | + Skip("Skipping this test due to configuration issue with Spray proxy") |
| 41 | + } |
| 42 | + |
| 43 | + f, err = framework.NewFramework(utils.GetGeneratedNamespace("stat-rep")) |
| 44 | + Expect(err).NotTo(HaveOccurred()) |
| 45 | + testNamespace = f.UserNamespace |
| 46 | + |
| 47 | + if utils.IsPrivateHostname(f.OpenshiftConsoleHost) { |
| 48 | + Skip("Using private cluster (not reachable from Github), skipping...") |
| 49 | + } |
| 50 | + |
| 51 | + applicationName = createApp(*f, testNamespace) |
| 52 | + component, componentName, pacBranchName, componentBaseBranchName = createComponent(*f, testNamespace, applicationName, componentRepoNameForStatusReporting, componentGitSourceURLForStatusReporting) |
| 53 | + |
| 54 | + integrationTestScenarioPass, err = f.AsKubeAdmin.IntegrationController.CreateIntegrationTestScenario("", applicationName, testNamespace, gitURL, revision, pathInRepoPass, []string{}) |
| 55 | + Expect(err).ShouldNot(HaveOccurred()) |
| 56 | + integrationTestScenarioFail, err = f.AsKubeAdmin.IntegrationController.CreateIntegrationTestScenario("", applicationName, testNamespace, gitURL, revision, pathInRepoFail, []string{}) |
| 57 | + Expect(err).ShouldNot(HaveOccurred()) |
| 58 | + }) |
| 59 | + |
| 60 | + AfterAll(func() { |
| 61 | + if !CurrentSpecReport().Failed() { |
| 62 | + cleanup(*f, testNamespace, applicationName, componentName, snapshot) |
| 63 | + } |
| 64 | + |
| 65 | + // Delete new branches created by PaC and a testing branch used as a component's base branch |
| 66 | + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(componentRepoNameForStatusReporting, pacBranchName) |
| 67 | + if err != nil { |
| 68 | + Expect(err.Error()).To(ContainSubstring(referenceDoesntExist)) |
| 69 | + } |
| 70 | + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(componentRepoNameForStatusReporting, componentBaseBranchName) |
| 71 | + if err != nil { |
| 72 | + Expect(err.Error()).To(ContainSubstring(referenceDoesntExist)) |
| 73 | + } |
| 74 | + }) |
| 75 | + |
| 76 | + When("a new Component with specified custom branch is created", Label("custom-branch"), func() { |
| 77 | + It("triggers a Build PipelineRun", func() { |
| 78 | + timeout = time.Second * 600 |
| 79 | + interval = time.Second * 1 |
| 80 | + Eventually(func() error { |
| 81 | + pipelineRun, err = f.AsKubeAdmin.HasController.GetComponentPipelineRun(componentName, applicationName, testNamespace, "") |
| 82 | + if err != nil { |
| 83 | + GinkgoWriter.Printf("Build PipelineRun has not been created yet for the component %s/%s\n", testNamespace, componentName) |
| 84 | + return err |
| 85 | + } |
| 86 | + if !pipelineRun.HasStarted() { |
| 87 | + return fmt.Errorf("build pipelinerun %s/%s hasn't started yet", pipelineRun.GetNamespace(), pipelineRun.GetName()) |
| 88 | + } |
| 89 | + return nil |
| 90 | + }, timeout, constants.PipelineRunPollingInterval).Should(Succeed(), fmt.Sprintf("timed out when waiting for the build PipelineRun to start for the component %s/%s", testNamespace, componentName)) |
| 91 | + }) |
| 92 | + |
| 93 | + It("does not contain an annotation with a Snapshot Name", func() { |
| 94 | + Expect(pipelineRun.Annotations[snapshotAnnotation]).To(Equal("")) |
| 95 | + }) |
| 96 | + |
| 97 | + It("should lead to build PipelineRun finishing successfully", func() { |
| 98 | + Expect(f.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(component, |
| 99 | + "", f.AsKubeAdmin.TektonController, &has.RetryOptions{Retries: 2, Always: true}, pipelineRun)).To(Succeed()) |
| 100 | + }) |
| 101 | + |
| 102 | + It("should have a related PaC init PR created", func() { |
| 103 | + timeout = time.Second * 300 |
| 104 | + interval = time.Second * 1 |
| 105 | + |
| 106 | + Eventually(func() bool { |
| 107 | + prs, err := f.AsKubeAdmin.CommonController.Github.ListPullRequests(componentRepoNameForStatusReporting) |
| 108 | + Expect(err).ShouldNot(HaveOccurred()) |
| 109 | + |
| 110 | + for _, pr := range prs { |
| 111 | + if pr.Head.GetRef() == pacBranchName { |
| 112 | + prNumber = pr.GetNumber() |
| 113 | + prHeadSha = pr.Head.GetSHA() |
| 114 | + return true |
| 115 | + } |
| 116 | + } |
| 117 | + return false |
| 118 | + }, timeout, interval).Should(BeTrue(), fmt.Sprintf("timed out when waiting for init PaC PR (branch name '%s') to be created in %s repository", pacBranchName, componentRepoNameForStatusReporting)) |
| 119 | + |
| 120 | + // in case the first pipelineRun attempt has failed and was retried, we need to update the value of pipelineRun variable |
| 121 | + pipelineRun, err = f.AsKubeAdmin.HasController.GetComponentPipelineRun(componentName, applicationName, testNamespace, prHeadSha) |
| 122 | + Expect(err).ShouldNot(HaveOccurred()) |
| 123 | + }) |
| 124 | + |
| 125 | + It("eventually leads to the build PipelineRun's status reported at Checks tab", func() { |
| 126 | + expectedCheckRunName := fmt.Sprintf("%s-%s", componentName, "on-pull-request") |
| 127 | + Expect(f.AsKubeAdmin.CommonController.Github.GetCheckRunConclusion(expectedCheckRunName, componentRepoNameForStatusReporting, prHeadSha, prNumber)).To(Equal(constants.CheckrunConclusionSuccess)) |
| 128 | + }) |
| 129 | + }) |
| 130 | + |
| 131 | + When("the PaC build pipelineRun run succeeded", func() { |
| 132 | + It("checks if the BuildPipelineRun have the annotation of chains signed", func() { |
| 133 | + Expect(f.AsKubeDeveloper.IntegrationController.WaitForBuildPipelineRunToGetAnnotated(testNamespace, applicationName, componentName, chainsSignedAnnotation)).To(Succeed()) |
| 134 | + }) |
| 135 | + |
| 136 | + It("checks if the Snapshot is created", func() { |
| 137 | + snapshot, err = f.AsKubeDeveloper.IntegrationController.WaitForSnapshotToGetCreated("", "", componentName, testNamespace) |
| 138 | + Expect(err).ToNot(HaveOccurred()) |
| 139 | + }) |
| 140 | + |
| 141 | + It("checks if the Build PipelineRun got annotated with Snapshot name", func() { |
| 142 | + Expect(f.AsKubeDeveloper.IntegrationController.WaitForBuildPipelineRunToGetAnnotated(testNamespace, applicationName, componentName, snapshotAnnotation)).To(Succeed()) |
| 143 | + }) |
| 144 | + }) |
| 145 | + |
| 146 | + When("the Snapshot was created", func() { |
| 147 | + It("should find both the related Integration PipelineRuns", func() { |
| 148 | + testPipelinerun, err = f.AsKubeDeveloper.IntegrationController.WaitForIntegrationPipelineToGetStarted(integrationTestScenarioPass.Name, snapshot.Name, testNamespace) |
| 149 | + Expect(err).ToNot(HaveOccurred()) |
| 150 | + Expect(testPipelinerun.Labels[snapshotAnnotation]).To(ContainSubstring(snapshot.Name)) |
| 151 | + Expect(testPipelinerun.Labels[scenarioAnnotation]).To(ContainSubstring(integrationTestScenarioPass.Name)) |
| 152 | + |
| 153 | + testPipelinerun, err = f.AsKubeDeveloper.IntegrationController.WaitForIntegrationPipelineToGetStarted(integrationTestScenarioFail.Name, snapshot.Name, testNamespace) |
| 154 | + Expect(err).ToNot(HaveOccurred()) |
| 155 | + Expect(testPipelinerun.Labels[snapshotAnnotation]).To(ContainSubstring(snapshot.Name)) |
| 156 | + Expect(testPipelinerun.Labels[scenarioAnnotation]).To(ContainSubstring(integrationTestScenarioFail.Name)) |
| 157 | + }) |
| 158 | + }) |
| 159 | + |
| 160 | + When("Integration PipelineRuns are created", func() { |
| 161 | + It("should eventually complete successfully", func() { |
| 162 | + 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())) |
| 163 | + 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())) |
| 164 | + }) |
| 165 | + }) |
| 166 | + |
| 167 | + When("Integration PipelineRuns completes successfully", func() { |
| 168 | + It("should lead to Snapshot CR being marked as failed", FlakeAttempts(3), func() { |
| 169 | + // Snapshot marked as Failed because one of its Integration test failed (as expected) |
| 170 | + Eventually(func() bool { |
| 171 | + snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot("", pipelineRun.Name, "", testNamespace) |
| 172 | + return err == nil && !f.AsKubeAdmin.CommonController.HaveTestsSucceeded(snapshot) |
| 173 | + }, time.Minute*3, time.Second*5).Should(BeTrue(), fmt.Sprintf("Timed out waiting for Snapshot to be marked as failed %s/%s", snapshot.GetNamespace(), snapshot.GetName())) |
| 174 | + }) |
| 175 | + |
| 176 | + It("eventually leads to the status reported at Checks tab for the successful Integration PipelineRun", func() { |
| 177 | + Expect(f.AsKubeAdmin.CommonController.Github.GetCheckRunConclusion(integrationTestScenarioPass.Name, componentRepoNameForStatusReporting, prHeadSha, prNumber)).To(Equal(constants.CheckrunConclusionSuccess)) |
| 178 | + }) |
| 179 | + |
| 180 | + It("eventually leads to the status reported at Checks tab for the failed Integration PipelineRun", func() { |
| 181 | + Expect(f.AsKubeAdmin.CommonController.Github.GetCheckRunConclusion(integrationTestScenarioFail.Name, componentRepoNameForStatusReporting, prHeadSha, prNumber)).To(Equal(constants.CheckrunConclusionFailure)) |
| 182 | + }) |
| 183 | + }) |
| 184 | + }) |
| 185 | +}) |
0 commit comments