From e55a6a7d0a10d7ac1b14bc63cecdc02d7ac9d3f2 Mon Sep 17 00:00:00 2001 From: Sushanta Das Date: Thu, 11 Jul 2024 16:43:15 +0530 Subject: [PATCH] remove simple build dependency --- tests/build/build.go | 168 +++++------------------ tests/build/build_templates.go | 75 ++++++++-- tests/build/build_templates_scenarios.go | 16 ++- tests/build/const.go | 26 ++-- tests/build/jvm-build.go | 24 +++- tests/build/multi-platform.go | 70 ++++++++-- 6 files changed, 205 insertions(+), 174 deletions(-) diff --git a/tests/build/build.go b/tests/build/build.go index 598566daae..e418024a6d 100644 --- a/tests/build/build.go +++ b/tests/build/build.go @@ -1040,16 +1040,13 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build", " var componentObj appservice.ComponentSpec var component *appservice.Component - var timeout, interval time.Duration + invalidAnnotation := "foo" BeforeAll(func() { f, err = framework.NewFramework(utils.GetGeneratedNamespace("build-e2e")) Expect(err).ShouldNot(HaveOccurred()) testNamespace = f.UserNamespace - timeout = 5 * time.Minute - interval = 5 * time.Second - applicationName = fmt.Sprintf("build-suite-test-application-%s", util.GenerateRandomString(4)) _, err = f.AsKubeAdmin.HasController.CreateApplication(applicationName, testNamespace) Expect(err).NotTo(HaveOccurred()) @@ -1066,8 +1063,11 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build", " }) - When("component is created", func() { - var lastBuildStartTime string + When("component is created with invalid build request annotations", func() { + + invalidBuildAnnotation := map[string]string{ + controllers.BuildRequestAnnotationName: invalidAnnotation, + } BeforeAll(func() { componentObj = appservice.ComponentSpec{ @@ -1084,138 +1084,21 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build", " }, } - component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, false, constants.DefaultDockerBuildPipelineBundle) + component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, false, utils.MergeMaps(invalidBuildAnnotation, constants.DefaultDockerBuildPipelineBundle)) Expect(component).ToNot(BeNil()) Expect(err).ShouldNot(HaveOccurred()) }) - It("triggers a pipeline run", func() { - Eventually(func() error { - pr, err := f.AsKubeAdmin.HasController.GetComponentPipelineRun(componentName, applicationName, testNamespace, "") - if err != nil { - GinkgoWriter.Printf("PipelineRun has not been created yet for the component %s/%s\n", testNamespace, componentName) - return err - } - if !pr.HasStarted() { - return fmt.Errorf("pipelinerun %s/%s hasn't started yet", pr.GetNamespace(), pr.GetName()) - } - return nil - }, time.Minute*5, constants.PipelineRunPollingInterval).Should(Succeed(), fmt.Sprintf("timed out when waiting for the PipelineRun to start for the component %s/%s", testNamespace, componentName)) - }) - - It("component build status annotation is set correctly", func() { - var buildStatus *controllers.BuildStatus - - Eventually(func() (bool, error) { - component, err := f.AsKubeAdmin.HasController.GetComponent(componentName, testNamespace) - if err != nil { - GinkgoWriter.Printf("cannot get the component: %v\n", err) - return false, err - } - - buildStatusAnnotationValue := component.Annotations[controllers.BuildStatusAnnotationName] - GinkgoWriter.Printf(buildStatusAnnotationValueLoggingFormat, buildStatusAnnotationValue) - statusBytes := []byte(buildStatusAnnotationValue) - - err = json.Unmarshal(statusBytes, &buildStatus) - if err != nil { - GinkgoWriter.Printf("cannot unmarshal build status: %v\n", err) - return false, err - } - - if buildStatus.Simple != nil { - GinkgoWriter.Printf("buildStartTime: %s\n", buildStatus.Simple.BuildStartTime) - lastBuildStartTime = buildStatus.Simple.BuildStartTime - } else { - GinkgoWriter.Println("build status does not have simple field") - } - - return buildStatus.Simple != nil && buildStatus.Simple.BuildStartTime != "", nil - }, timeout, interval).Should(BeTrue(), "build status has unexpected content") - - //Expect pipelinerun count to be 1 - Eventually(func() error { - pipelineRuns, err := f.AsKubeAdmin.HasController.GetAllPipelineRunsForApplication(applicationName, testNamespace) - if err != nil { - GinkgoWriter.Println("PiplelineRun has not been created yet") - return err - } - if len(pipelineRuns.Items) != 1 { - return fmt.Errorf("pipelinerun count in the namespace %s is not one, got pipelineruns %v", testNamespace, pipelineRuns.Items) - } - return nil - }, time.Minute*5, constants.PipelineRunPollingInterval).Should(Succeed(), "timeout while waiting for first pipelinerun to start") - }) - - Specify("simple build can be triggered manually", func() { - // Wait 1 second before sending the second build request, so that we get different buildStatus.Simple.BuildStartTime timestamp - time.Sleep(1 * time.Second) - Expect(f.AsKubeAdmin.HasController.SetComponentAnnotation(componentName, controllers.BuildRequestAnnotationName, controllers.BuildRequestTriggerSimpleBuildAnnotationValue, testNamespace)).To(Succeed()) - }) - - It("another pipelineRun is triggered", func() { - //Expect pipelinerun count to be 2 - Eventually(func() error { - pipelineRuns, err := f.AsKubeAdmin.HasController.GetAllPipelineRunsForApplication(applicationName, testNamespace) - if err != nil { - GinkgoWriter.Println("Second piplelineRun has not been created yet") - return err - } - if len(pipelineRuns.Items) != 2 { - return fmt.Errorf("pipelinerun count in the namespace %s is not two, got pipelineruns %v", testNamespace, pipelineRuns.Items) - } - return nil - }, time.Minute*5, constants.PipelineRunPollingInterval).Should(Succeed(), "timeout while waiting for second pipelinerun to start") - }) - - It("component build annotation is correct", func() { - var buildStatus *controllers.BuildStatus - - Eventually(func() (bool, error) { - component, err := f.AsKubeAdmin.HasController.GetComponent(componentName, testNamespace) - if err != nil { - GinkgoWriter.Printf("cannot get the component: %v\n", err) - return false, err - } - - buildStatusAnnotationValue := component.Annotations[controllers.BuildStatusAnnotationName] - GinkgoWriter.Printf(buildStatusAnnotationValueLoggingFormat, buildStatusAnnotationValue) - statusBytes := []byte(buildStatusAnnotationValue) - - err = json.Unmarshal(statusBytes, &buildStatus) - if err != nil { - GinkgoWriter.Printf("cannot unmarshal build status: %v\n", err) - return false, err - } - - if buildStatus.Simple != nil { - GinkgoWriter.Printf("buildStartTime: %s\n", buildStatus.Simple.BuildStartTime) - } else { - GinkgoWriter.Println("build status does not have simple field") - } - - return buildStatus.Simple != nil && buildStatus.Simple.BuildStartTime != lastBuildStartTime, nil - }, timeout, interval).Should(BeTrue(), "build status has unexpected content") - }) - It("handles invalid request annotation", func() { - invalidAnnotation := "foo" expectedInvalidAnnotationMessage := fmt.Sprintf("unexpected build request: %s", invalidAnnotation) - Expect(f.AsKubeAdmin.HasController.SetComponentAnnotation(componentName, controllers.BuildRequestAnnotationName, invalidAnnotation, testNamespace)).To(Succeed()) - - // Waiting for 2 minute to see if any more pipelinerun is triggered - Consistently(func() (bool, error) { - pipelineRuns, err := f.AsKubeAdmin.HasController.GetAllPipelineRunsForApplication(applicationName, testNamespace) - if err != nil { - return false, err - } - if len(pipelineRuns.Items) != 2 { - return false, fmt.Errorf("pipelinerun count in the namespace %s is not two, got pipelineruns %v", testNamespace, pipelineRuns.Items) - } - return true, nil - }, time.Minute*2, constants.PipelineRunPollingInterval).Should(BeTrue(), "timeout while checking if any more pipelinerun is triggered") + // Waiting for 1 minute to see if any pipelinerun is triggered + Consistently(func() bool { + _, err := f.AsKubeAdmin.HasController.GetComponentPipelineRun(componentName, applicationName, testNamespace, "") + Expect(err).To(HaveOccurred()) + return strings.Contains(err.Error(), "no pipelinerun found") + }, time.Minute*1, constants.PipelineRunPollingInterval).Should(BeTrue(), "timeout while checking if any pipelinerun is triggered") buildStatus := &controllers.BuildStatus{} Eventually(func() error { @@ -1286,7 +1169,7 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build", " Describe("A secret with dummy quay.io credentials is created in the testing namespace", Ordered, func() { - var applicationName, componentName, testNamespace string + var applicationName, componentName, testNamespace, pacBranchName, componentBaseBranchName string var timeout time.Duration var err error var pr *pipeline.PipelineRun @@ -1332,19 +1215,25 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build", " Expect(err).ToNot(HaveOccurred()) componentName = "build-suite-test-secret-overriding" + pacBranchName = constants.PaCPullRequestBranchPrefix + componentName + componentBaseBranchName = fmt.Sprintf("base-%s", util.GenerateRandomString(6)) + err = f.AsKubeAdmin.CommonController.Github.CreateRef(helloWorldComponentGitSourceCloneRepoName, "main", helloWorldComponentCloneRevision, componentBaseBranchName) + Expect(err).ShouldNot(HaveOccurred()) + componentObj := appservice.ComponentSpec{ ComponentName: componentName, Application: applicationName, Source: appservice.ComponentSource{ ComponentSourceUnion: appservice.ComponentSourceUnion{ GitSource: &appservice.GitSource{ - URL: helloWorldComponentGitSourceURL, + URL: helloWorldComponentGitSourceCloneURL, + Revision: componentBaseBranchName, DockerfileURL: constants.DockerFilePath, }, }, }, } - _, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, constants.DefaultDockerBuildPipelineBundle) + _, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, utils.MergeMaps(constants.ComponentPaCRequestAnnotation, constants.DefaultDockerBuildPipelineBundle)) Expect(err).NotTo(HaveOccurred()) }) @@ -1355,6 +1244,17 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build", " Expect(f.AsKubeAdmin.TektonController.DeleteAllPipelineRunsInASpecificNamespace(testNamespace)).To(Succeed()) Expect(f.SandboxController.DeleteUserSignup(f.UserName)).To(BeTrue()) } + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(helloWorldComponentGitSourceCloneRepoName, pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(helloWorldComponentGitSourceCloneRepoName, componentBaseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + // Delete created webhook from GitHub + cleanupWebhooks(f, helloWorldComponentGitSourceCloneRepoName) }) It("should override the shared secret", func() { @@ -1372,7 +1272,7 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build", " pr, err = f.AsKubeAdmin.HasController.GetComponentPipelineRun(componentName, applicationName, testNamespace, "") Expect(err).ShouldNot(HaveOccurred()) - Expect(pr.Spec.Workspaces).To(HaveLen(1)) + Expect(pr.Spec.Workspaces).To(HaveLen(2)) }) It("should not be possible to push to quay.io repo (PipelineRun should fail)", func() { diff --git a/tests/build/build_templates.go b/tests/build/build_templates.go index b98a1fa11a..8921704624 100644 --- a/tests/build/build_templates.go +++ b/tests/build/build_templates.go @@ -42,10 +42,20 @@ var ( const pipelineCompletionRetries = 2 +type TestBranches struct { + RepoName string + BranchName string + PacBranchName string + BaseBranchName string +} + +var pacAndBaseBranches []TestBranches + // CreateComponent creates a component from a test repository URL and returns the component's name -func CreateComponent(ctrl *has.HasController, gitUrl, revision, applicationName, componentName, namespace string) string { +func CreateComponent(f *framework.Framework, ctrl *has.HasController, gitUrl, revision, applicationName, componentName, namespace string) string { var err error var buildPipelineAnnotation map[string]string + var baseBranchName, pacBranchName string contextDir, dockerfilePath, pipelineBundleName, enableHermetic, prefetchInput, checkAdditionalTags := GetComponentScenarioDetailsFromGitUrl(gitUrl) Expect(pipelineBundleName).ShouldNot(BeEmpty()) if pipelineBundleName == "docker-build" { @@ -82,13 +92,38 @@ func CreateComponent(ctrl *has.HasController, gitUrl, revision, applicationName, } } + baseBranchName = fmt.Sprintf("base-%s", util.GenerateRandomString(6)) + pacBranchName = constants.PaCPullRequestBranchPrefix + componentName + + if revision == gitRepoContainsSymlinkBranchName { + revision = symlinkBranchRevision + err = f.AsKubeAdmin.CommonController.Github.CreateRef(utils.GetRepoName(gitUrl), gitRepoContainsSymlinkBranchName, revision, baseBranchName) + Expect(err).ShouldNot(HaveOccurred()) + pacAndBaseBranches = append(pacAndBaseBranches, TestBranches{ + RepoName: utils.GetRepoName(gitUrl), + BranchName: gitRepoContainsSymlinkBranchName, + PacBranchName: pacBranchName, + BaseBranchName: baseBranchName, + }) + } else { + revision = GetGitRevision(gitUrl) + err = f.AsKubeAdmin.CommonController.Github.CreateRef(utils.GetRepoName(gitUrl), "main", revision, baseBranchName) + Expect(err).ShouldNot(HaveOccurred()) + pacAndBaseBranches = append(pacAndBaseBranches, TestBranches{ + RepoName: utils.GetRepoName(gitUrl), + BranchName: "main", + PacBranchName: pacBranchName, + BaseBranchName: baseBranchName, + }) + } + componentObj := appservice.ComponentSpec{ ComponentName: componentName, Source: appservice.ComponentSource{ ComponentSourceUnion: appservice.ComponentSourceUnion{ GitSource: &appservice.GitSource{ URL: gitUrl, - Revision: revision, + Revision: baseBranchName, Context: contextDir, DockerfileURL: dockerfilePath, }, @@ -103,7 +138,7 @@ func CreateComponent(ctrl *has.HasController, gitUrl, revision, applicationName, "build.appstudio.openshift.io/pipeline": fmt.Sprintf(`{"name":"docker-build", "bundle": "%s"}`, customSourceBuildBundle), } } - c, err := ctrl.CreateComponent(componentObj, namespace, "", "", applicationName, false, buildPipelineAnnotation) + c, err := ctrl.CreateComponent(componentObj, namespace, "", "", applicationName, false, utils.MergeMaps(constants.ComponentPaCRequestAnnotation, buildPipelineAnnotation)) Expect(err).ShouldNot(HaveOccurred()) return c.Name } @@ -141,7 +176,7 @@ var _ = framework.BuildSuiteDescribe("Build templates E2E test", Label("build", defer GinkgoRecover() Describe("HACBS pipelines", Ordered, Label("pipeline"), func() { - var applicationName, componentName, symlinkComponentName, testNamespace string + var applicationName, componentName, symlinkComponentName, symlinkPRunName, testNamespace string var kubeadminClient *framework.ControllerHub var pipelineRunsWithE2eFinalizer []string @@ -182,7 +217,7 @@ var _ = framework.BuildSuiteDescribe("Build templates E2E test", Label("build", for _, gitUrl := range componentUrls { gitUrl := gitUrl componentName = fmt.Sprintf("%s-%s", "test-comp", util.GenerateRandomString(4)) - name := CreateComponent(kubeadminClient.HasController, gitUrl, "", applicationName, componentName, testNamespace) + name := CreateComponent(f, kubeadminClient.HasController, gitUrl, "", applicationName, componentName, testNamespace) Expect(name).ShouldNot(BeEmpty()) componentNames = append(componentNames, name) } @@ -190,7 +225,7 @@ var _ = framework.BuildSuiteDescribe("Build templates E2E test", Label("build", // Create component for the repo containing symlink symlinkComponentName = fmt.Sprintf("%s-%s", "test-symlink-comp", util.GenerateRandomString(4)) symlinkComponentName = CreateComponent( - kubeadminClient.HasController, pythonComponentGitSourceURL, gitRepoContainsSymlinkBranchName, + f, kubeadminClient.HasController, pythonComponentGitSourceURL, gitRepoContainsSymlinkBranchName, applicationName, symlinkComponentName, testNamespace) }) @@ -224,13 +259,24 @@ var _ = framework.BuildSuiteDescribe("Build templates E2E test", Label("build", Expect(f.SandboxController.DeleteUserSignup(f.UserName)).To(BeTrue()) } } + //Cleanup pac and base branches + for _, branches := range pacAndBaseBranches { + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(branches.RepoName, branches.PacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(branches.RepoName, branches.BaseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + } }) It(fmt.Sprintf("triggers PipelineRun for symlink component with source URL %s", pythonComponentGitSourceURL), Label(buildTemplatesTestLabel, sourceBuildTestLabel), func() { timeout := time.Minute * 5 - prName := WaitForPipelineRunStarts(kubeadminClient, applicationName, symlinkComponentName, testNamespace, timeout) - Expect(prName).ShouldNot(BeEmpty()) - pipelineRunsWithE2eFinalizer = append(pipelineRunsWithE2eFinalizer, prName) + symlinkPRunName = WaitForPipelineRunStarts(kubeadminClient, applicationName, symlinkComponentName, testNamespace, timeout) + Expect(symlinkPRunName).ShouldNot(BeEmpty()) + pipelineRunsWithE2eFinalizer = append(pipelineRunsWithE2eFinalizer, symlinkPRunName) }) for i, gitUrl := range componentUrls { @@ -637,10 +683,13 @@ var _ = framework.BuildSuiteDescribe("Build templates E2E test", Label("build", } It(fmt.Sprintf("pipelineRun should fail for symlink component with Git source URL %s", pythonComponentGitSourceURL), Label(buildTemplatesTestLabel, sourceBuildTestLabel), func() { - component, err := kubeadminClient.HasController.GetComponent(symlinkComponentName, testNamespace) - Expect(err).ShouldNot(HaveOccurred()) - Expect(kubeadminClient.HasController.WaitForComponentPipelineToBeFinished(component, "", - kubeadminClient.TektonController, &has.RetryOptions{Retries: pipelineCompletionRetries}, nil)).Should(MatchError(ContainSubstring("cloned repository contains symlink pointing outside of the cloned repository"))) + pipelineRunTimeout := int(time.Duration(10) * time.Minute) + Expect(f.AsKubeAdmin.TektonController.WatchPipelineRun(symlinkPRunName, testNamespace, pipelineRunTimeout)).To(Succeed()) + pr, err := f.AsKubeAdmin.TektonController.GetPipelineRun(symlinkPRunName, testNamespace) + Expect(err).ShouldNot(HaveOccurred(), "failed to get pipelinerun %s", symlinkPRunName) + tr, err := f.AsKubeAdmin.TektonController.GetTaskRunStatus(f.AsKubeAdmin.CommonController.KubeRest(), pr, "clone-repository") + Expect(err).NotTo(HaveOccurred(), "failed to get taskrun for clone-repository") + Expect(tekton.DidTaskRunSucceed(tr)).To(BeFalse()) }) }) }) diff --git a/tests/build/build_templates_scenarios.go b/tests/build/build_templates_scenarios.go index 44cd2f7062..8e11f2e539 100644 --- a/tests/build/build_templates_scenarios.go +++ b/tests/build/build_templates_scenarios.go @@ -2,10 +2,12 @@ package build import ( "github.com/konflux-ci/e2e-tests/pkg/constants" + "github.com/konflux-ci/e2e-tests/pkg/utils" ) type ComponentScenarioSpec struct { GitURL string + Revision string ContextDir string DockerFilePath string PipelineBundleName string @@ -17,6 +19,7 @@ type ComponentScenarioSpec struct { var componentScenarios = []ComponentScenarioSpec{ { GitURL: "https://github.com/redhat-appstudio-qe/devfile-sample-python-basic", + Revision: "47fc22092005aabebce233a9b6eab994a8152bbd", ContextDir: ".", DockerFilePath: constants.DockerFilePath, PipelineBundleName: "docker-build", @@ -82,9 +85,20 @@ var componentScenarios = []ComponentScenarioSpec{ }, } +func GetGitRevision(gitUrl string) string { + for _, componentScenario := range componentScenarios { + //check repo name for both the giturls is same + if utils.GetRepoName(componentScenario.GitURL) == utils.GetRepoName(gitUrl) { + return componentScenario.Revision + } + } + return "" +} + func GetComponentScenarioDetailsFromGitUrl(gitUrl string) (string, string, string, bool, string, bool) { for _, componentScenario := range componentScenarios { - if componentScenario.GitURL == gitUrl { + //check repo name for both the giturls is same + if utils.GetRepoName(componentScenario.GitURL) == utils.GetRepoName(gitUrl) { return componentScenario.ContextDir, componentScenario.DockerFilePath, componentScenario.PipelineBundleName, componentScenario.EnableHermetic, componentScenario.PrefetchInput, componentScenario.CheckAdditionalTags } } diff --git a/tests/build/const.go b/tests/build/const.go index acd19c9f26..0b700bbb8e 100644 --- a/tests/build/const.go +++ b/tests/build/const.go @@ -12,8 +12,8 @@ const ( COMPONENT_REPO_URLS_ENV string = "COMPONENT_REPO_URLS" containerImageSource = "quay.io/redhat-appstudio-qe/busybox-loop@sha256:f698f1f2cf641fe9176d2a277c9052d872f6b1c39e56248a1dd259b96281dda9" - pythonComponentGitSourceURL = "https://github.com/redhat-appstudio-qe/devfile-sample-python-basic" gitRepoContainsSymlinkBranchName = "symlink" + symlinkBranchRevision = "27ecfca9c9dad35e4f07ebbcd706f31cb7ce849f" dummyPipelineBundleRef = "quay.io/redhat-appstudio-qe/dummy-pipeline-bundle@sha256:9805fc3f309af8f838622e49d3e7705d8364eb5c8287043d5725f3ef12232f24" buildTemplatesTestLabel = "build-templates-e2e" buildTemplatesKcpTestLabel = "build-templates-kcp-e2e" @@ -23,6 +23,9 @@ const ( helloWorldComponentDefaultBranch = "default" helloWorldComponentRevision = "d2d03e69de912e3827c29b4c5b71ffe8bcb5dad8" + helloWorldComponentGitSourceCloneRepoName = "devfile-sample-hello-world-clone" + helloWorldComponentCloneRevision = "bb1d243a9c030e715ac2a7829973d226816446c3" + multiComponentGitSourceRepoName = "sample-multi-component" multiComponentDefaultBranch = "main" multiComponentGitRevision = "0d1835404efb8ab7bb1ab5b5b82cda1ebfda4b25" @@ -49,18 +52,21 @@ const ( //Logging related buildStatusAnnotationValueLoggingFormat = "build status annotation value: %s\n" - noAppOrgName = "redhat-appstudio-qe-no-app" + noAppOrgName = "redhat-appstudio-qe-no-app" + pythonComponentRepoName = "devfile-sample-python-basic" ) var ( - additionalTags = []string{"test-tag1", "test-tag2"} - componentUrls = strings.Split(utils.GetEnv(COMPONENT_REPO_URLS_ENV, pythonComponentGitSourceURL), ",") //multiple urls - componentNames []string - gihubOrg = utils.GetEnv(constants.GITHUB_E2E_ORGANIZATION_ENV, "redhat-appstudio-qe") - helloWorldComponentGitSourceURL = fmt.Sprintf(githubUrlFormat, gihubOrg, helloWorldComponentGitSourceRepoName) - annotationsTestGitSourceURL = fmt.Sprintf(githubUrlFormat, gihubOrg, annotationsTestGitSourceRepoName) - multiComponentGitSourceURL = fmt.Sprintf(githubUrlFormat, gihubOrg, multiComponentGitSourceRepoName) - multiComponentContextDirs = []string{"go-component", "python-component"} + additionalTags = []string{"test-tag1", "test-tag2"} + pythonComponentGitSourceURL = fmt.Sprintf(githubUrlFormat, gihubOrg, pythonComponentRepoName) + componentUrls = strings.Split(utils.GetEnv(COMPONENT_REPO_URLS_ENV, pythonComponentGitSourceURL), ",") //multiple urls + componentNames []string + gihubOrg = utils.GetEnv(constants.GITHUB_E2E_ORGANIZATION_ENV, "redhat-appstudio-qe") + helloWorldComponentGitSourceURL = fmt.Sprintf(githubUrlFormat, gihubOrg, helloWorldComponentGitSourceRepoName) + helloWorldComponentGitSourceCloneURL = fmt.Sprintf(githubUrlFormat, gihubOrg, helloWorldComponentGitSourceCloneRepoName) + annotationsTestGitSourceURL = fmt.Sprintf(githubUrlFormat, gihubOrg, annotationsTestGitSourceRepoName) + multiComponentGitSourceURL = fmt.Sprintf(githubUrlFormat, gihubOrg, multiComponentGitSourceRepoName) + multiComponentContextDirs = []string{"go-component", "python-component"} secretLookupComponentOneGitSourceURL = fmt.Sprintf(githubUrlFormat, noAppOrgName, secretLookupGitSourceRepoOneName) secretLookupComponentTwoGitSourceURL = fmt.Sprintf(githubUrlFormat, noAppOrgName, secretLookupGitSourceRepoTwoName) diff --git a/tests/build/jvm-build.go b/tests/build/jvm-build.go index c3f715a5c7..275d6e55d0 100644 --- a/tests/build/jvm-build.go +++ b/tests/build/jvm-build.go @@ -30,7 +30,7 @@ import ( ) var ( - testProjectGitUrl = utils.GetEnv("JVM_BUILD_SERVICE_TEST_REPO_URL", "https://github.com/redhat-appstudio-qe/hacbs-test-project") + testProjectGitUrl = utils.GetEnv("JVM_BUILD_SERVICE_TEST_REPO_URL", fmt.Sprintf("https://github.com/%s/hacbs-test-project", gihubOrg)) testProjectRevision = utils.GetEnv("JVM_BUILD_SERVICE_TEST_REPO_REVISION", "34da5a8f51fba6a8b7ec75a727d3c72ebb5e1274") ) @@ -41,7 +41,7 @@ var _ = framework.JVMBuildSuiteDescribe("JVM Build Service E2E tests", Label("jv defer GinkgoRecover() - var testNamespace, applicationName, componentName string + var testNamespace, applicationName, componentName, pacBranchName, baseBranchName string var component *appservice.Component var timeout, interval time.Duration var customJavaBuilderPipelineAnnotation map[string]string @@ -62,6 +62,16 @@ var _ = framework.JVMBuildSuiteDescribe("JVM Build Service E2E tests", Label("jv Expect(f.AsKubeAdmin.CommonController.StoreAllPods(testNamespace)).To(Succeed()) Expect(f.AsKubeAdmin.TektonController.StoreAllPipelineRuns(testNamespace)).To(Succeed()) } + + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(testProjectGitUrl), pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(testProjectGitUrl), baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } }) BeforeAll(func() { @@ -93,6 +103,12 @@ var _ = framework.JVMBuildSuiteDescribe("JVM Build Service E2E tests", Label("jv componentName = fmt.Sprintf("jvm-build-suite-component-%s", util.GenerateRandomString(6)) + pacBranchName = constants.PaCPullRequestBranchPrefix + componentName + baseBranchName = fmt.Sprintf("base-%s", util.GenerateRandomString(6)) + + err = f.AsKubeAdmin.CommonController.Github.CreateRef(utils.GetRepoName(testProjectGitUrl), "main", testProjectRevision, baseBranchName) + Expect(err).ShouldNot(HaveOccurred()) + // Create a component with Git Source URL being defined componentObj := appservice.ComponentSpec{ ComponentName: componentName, @@ -100,12 +116,12 @@ var _ = framework.JVMBuildSuiteDescribe("JVM Build Service E2E tests", Label("jv ComponentSourceUnion: appservice.ComponentSourceUnion{ GitSource: &appservice.GitSource{ URL: testProjectGitUrl, - Revision: testProjectRevision, + Revision: baseBranchName, }, }, }, } - component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, customJavaBuilderPipelineAnnotation) + component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, utils.MergeMaps(constants.ComponentPaCRequestAnnotation, customJavaBuilderPipelineAnnotation)) Expect(err).ShouldNot(HaveOccurred()) }) diff --git a/tests/build/multi-platform.go b/tests/build/multi-platform.go index 08b3f75fb4..83c151797a 100644 --- a/tests/build/multi-platform.go +++ b/tests/build/multi-platform.go @@ -53,7 +53,7 @@ const ( var ( IbmVpc = "us-east-default-vpc" - multiPlatformProjectGitUrl = utils.GetEnv("MULTI_PLATFORM_TEST_REPO_URL", "https://github.com/devfile-samples/devfile-sample-go-basic") + multiPlatformProjectGitUrl = utils.GetEnv("MULTI_PLATFORM_TEST_REPO_URL", fmt.Sprintf("https://github.com/%s/devfile-sample-go-basic", gihubOrg)) multiPlatformProjectRevision = utils.GetEnv("MULTI_PLATFORM_TEST_REPO_REVISION", "c713067b0e65fb3de50d1f7c457eb51c2ab0dbb0") timeout = 20 * time.Minute interval = 10 * time.Second @@ -68,7 +68,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E Describe("aws host-pool allocation", Label("aws-host-pool"), func() { - var testNamespace, applicationName, componentName, multiPlatformSecretName, host, userDir string + var testNamespace, applicationName, componentName, pacBranchName, baseBranchName, multiPlatformSecretName, host, userDir string var component *appservice.Component AfterAll(func() { @@ -84,6 +84,16 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E Expect(f.AsKubeAdmin.CommonController.StoreAllPods(testNamespace)).To(Succeed()) Expect(f.AsKubeAdmin.TektonController.StoreAllPipelineRuns(testNamespace)).To(Succeed()) } + + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } }) BeforeAll(func() { @@ -101,7 +111,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E err = createSecretForHostPool(f) Expect(err).ShouldNot(HaveOccurred()) - component, applicationName, componentName = createApplicationAndComponent(f, testNamespace, "ARM64") + component, applicationName, componentName, pacBranchName, baseBranchName = createApplicationAndComponent(f, testNamespace, "ARM64") }) When("the Component with multi-platform-build is created", func() { @@ -176,7 +186,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E }) }) Describe("aws dynamic allocation", Label("aws-dynamic"), func() { - var testNamespace, applicationName, componentName, multiPlatformSecretName, multiPlatformTaskName, dynamicInstanceTag, instanceId string + var testNamespace, applicationName, componentName, pacBranchName, baseBranchName, multiPlatformSecretName, multiPlatformTaskName, dynamicInstanceTag, instanceId string var component *appservice.Component AfterAll(func() { @@ -199,6 +209,16 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E Expect(f.AsKubeAdmin.CommonController.StoreAllPods(testNamespace)).To(Succeed()) Expect(f.AsKubeAdmin.TektonController.StoreAllPipelineRuns(testNamespace)).To(Succeed()) } + + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } }) BeforeAll(func() { @@ -221,7 +241,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E err = createSecretsForDynamicInstance(f) Expect(err).ShouldNot(HaveOccurred()) - component, applicationName, componentName = createApplicationAndComponent(f, testNamespace, "ARM64") + component, applicationName, componentName, pacBranchName, baseBranchName = createApplicationAndComponent(f, testNamespace, "ARM64") }) When("the Component with multi-platform-build is created", func() { @@ -258,7 +278,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E }) // TODO: Enable the test after https://issues.redhat.com/browse/KFLUXBUGS-1179 is fixed Describe("ibm system z dynamic allocation", Label("ibmz-dynamic"), Pending, func() { - var testNamespace, applicationName, componentName, multiPlatformSecretName, multiPlatformTaskName, dynamicInstanceTag, instanceId string + var testNamespace, applicationName, componentName, pacBranchName, baseBranchName, multiPlatformSecretName, multiPlatformTaskName, dynamicInstanceTag, instanceId string var component *appservice.Component AfterAll(func() { @@ -281,6 +301,16 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E Expect(f.AsKubeAdmin.CommonController.StoreAllPods(testNamespace)).To(Succeed()) Expect(f.AsKubeAdmin.TektonController.StoreAllPipelineRuns(testNamespace)).To(Succeed()) } + + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } }) BeforeAll(func() { @@ -300,7 +330,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E err = createSecretsForIbmDynamicInstance(f) Expect(err).ShouldNot(HaveOccurred()) - component, applicationName, componentName = createApplicationAndComponent(f, testNamespace, "S390X") + component, applicationName, componentName, pacBranchName, baseBranchName = createApplicationAndComponent(f, testNamespace, "S390X") }) When("the Component with multi-platform-build is created", func() { @@ -337,7 +367,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E }) // TODO: Enable the test after https://issues.redhat.com/browse/KFLUXBUGS-1179 is fixed Describe("ibm power pc dynamic allocation", Label("ibmp-dynamic"), Pending, func() { - var testNamespace, applicationName, componentName, multiPlatformSecretName, multiPlatformTaskName, dynamicInstanceTag, instanceId string + var testNamespace, applicationName, componentName, pacBranchName, baseBranchName, multiPlatformSecretName, multiPlatformTaskName, dynamicInstanceTag, instanceId string var component *appservice.Component AfterAll(func() { @@ -360,6 +390,16 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E Expect(f.AsKubeAdmin.CommonController.StoreAllPods(testNamespace)).To(Succeed()) Expect(f.AsKubeAdmin.TektonController.StoreAllPipelineRuns(testNamespace)).To(Succeed()) } + + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } }) BeforeAll(func() { @@ -380,7 +420,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E err = createSecretsForIbmDynamicInstance(f) Expect(err).ShouldNot(HaveOccurred()) - component, applicationName, componentName = createApplicationAndComponent(f, testNamespace, "PPC64LE") + component, applicationName, componentName, pacBranchName, baseBranchName = createApplicationAndComponent(f, testNamespace, "PPC64LE") }) When("the Component with multi-platform-build is created", func() { @@ -417,7 +457,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E }) }) -func createApplicationAndComponent(f *framework.Framework, testNamespace, platform string) (component *appservice.Component, applicationName, componentName string) { +func createApplicationAndComponent(f *framework.Framework, testNamespace, platform string) (component *appservice.Component, applicationName, componentName, pacBranchName, baseBranchName string) { applicationName = fmt.Sprintf("multi-platform-suite-application-%s", util.GenerateRandomString(4)) _, err := f.AsKubeAdmin.HasController.CreateApplication(applicationName, testNamespace) Expect(err).NotTo(HaveOccurred()) @@ -430,6 +470,12 @@ func createApplicationAndComponent(f *framework.Framework, testNamespace, platfo "build.appstudio.openshift.io/pipeline": fmt.Sprintf(`{"name":"buildah-remote-pipeline", "bundle": "%s"}`, customBuildahRemotePipeline), } + pacBranchName = constants.PaCPullRequestBranchPrefix + componentName + baseBranchName = fmt.Sprintf("base-%s", util.GenerateRandomString(6)) + + err = f.AsKubeAdmin.CommonController.Github.CreateRef(utils.GetRepoName(multiPlatformProjectGitUrl), "main", multiPlatformProjectRevision, baseBranchName) + Expect(err).ShouldNot(HaveOccurred()) + // Create a component with Git Source URL being defined componentObj := appservice.ComponentSpec{ ComponentName: componentName, @@ -437,13 +483,13 @@ func createApplicationAndComponent(f *framework.Framework, testNamespace, platfo ComponentSourceUnion: appservice.ComponentSourceUnion{ GitSource: &appservice.GitSource{ URL: multiPlatformProjectGitUrl, - Revision: multiPlatformProjectRevision, + Revision: baseBranchName, DockerfileURL: constants.DockerFilePath, }, }, }, } - component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, buildPipelineAnnotation) + component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, utils.MergeMaps(constants.ComponentPaCRequestAnnotation, buildPipelineAnnotation)) Expect(err).ShouldNot(HaveOccurred()) return }