diff --git a/pkg/tasktesting/bitbucket.go b/pkg/tasktesting/bitbucket.go index 23c8d6e5..2f4605a4 100644 --- a/pkg/tasktesting/bitbucket.go +++ b/pkg/tasktesting/bitbucket.go @@ -33,3 +33,14 @@ func BitbucketClientOrFatal(t *testing.T, c *kclient.Clientset, namespace string }) return bitbucketClient } + +func CheckBitbucketBuildStatus(t *testing.T, c *bitbucket.Client, gitCommit, wantBuildStatus string) { + buildStatus, err := c.BuildStatusGet(gitCommit) + if err != nil { + t.Fatal(err) + } + if buildStatus.State != wantBuildStatus { + t.Fatalf("Got: %s, want: %s", buildStatus.State, wantBuildStatus) + } + +} diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 9d76381d..0f771d79 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -148,6 +148,8 @@ func TestWebhookInterceptor(t *testing.T) { t.Log(logs) t.Fatal() } + + tasktesting.CheckBitbucketBuildStatus(t, bitbucketClient, odsContext.GitCommitSHA, bitbucket.BuildStatusSuccessful) } func waitForServiceToBeReady(t *testing.T, clientset *k8s.Clientset, ns, name string, timeout time.Duration) error { diff --git a/test/tasks/common_test.go b/test/tasks/common_test.go index b145a85c..fe9722e2 100644 --- a/test/tasks/common_test.go +++ b/test/tasks/common_test.go @@ -10,7 +10,6 @@ import ( "time" "github.com/opendevstack/pipeline/internal/kubernetes" - "github.com/opendevstack/pipeline/pkg/bitbucket" "github.com/opendevstack/pipeline/pkg/config" "github.com/opendevstack/pipeline/pkg/pipelinectxt" "github.com/opendevstack/pipeline/pkg/sonar" @@ -177,14 +176,3 @@ func createODSYML(wsDir string, o *config.ODS) error { filename := filepath.Join(wsDir, "ods.yaml") return ioutil.WriteFile(filename, y, 0644) } - -func checkBuildStatus(t *testing.T, c *bitbucket.Client, gitCommit, wantBuildStatus string) { - buildStatus, err := c.BuildStatusGet(gitCommit) - if err != nil { - t.Fatal(err) - } - if buildStatus.State != wantBuildStatus { - t.Fatalf("Got: %s, want: %s", buildStatus.State, wantBuildStatus) - } - -} diff --git a/test/tasks/ods-finish_test.go b/test/tasks/ods-finish_test.go index 15763ac7..6ff25a87 100644 --- a/test/tasks/ods-finish_test.go +++ b/test/tasks/ods-finish_test.go @@ -32,7 +32,7 @@ func TestTaskODSFinish(t *testing.T) { WantRunSuccess: true, PostRunFunc: func(t *testing.T, ctxt *tasktesting.TaskRunContext) { bitbucketClient := tasktesting.BitbucketClientOrFatal(t, ctxt.Clients.KubernetesClientSet, ctxt.Namespace) - checkBuildStatus(t, bitbucketClient, ctxt.ODS.GitCommitSHA, bitbucket.BuildStatusFailed) + tasktesting.CheckBitbucketBuildStatus(t, bitbucketClient, ctxt.ODS.GitCommitSHA, bitbucket.BuildStatusFailed) }, }, "set bitbucket build status to successful and upload artifacts to temporary Nexus repository": { @@ -50,7 +50,7 @@ func TestTaskODSFinish(t *testing.T) { WantRunSuccess: true, PostRunFunc: func(t *testing.T, ctxt *tasktesting.TaskRunContext) { bitbucketClient := tasktesting.BitbucketClientOrFatal(t, ctxt.Clients.KubernetesClientSet, ctxt.Namespace) - checkBuildStatus(t, bitbucketClient, ctxt.ODS.GitCommitSHA, bitbucket.BuildStatusSuccessful) + tasktesting.CheckBitbucketBuildStatus(t, bitbucketClient, ctxt.ODS.GitCommitSHA, bitbucket.BuildStatusSuccessful) checkArtifactsAreInNexus(t, ctxt, nexus.TemporaryRepositoryDefault) }, }, @@ -73,7 +73,7 @@ func TestTaskODSFinish(t *testing.T) { WantRunSuccess: true, PostRunFunc: func(t *testing.T, ctxt *tasktesting.TaskRunContext) { bitbucketClient := tasktesting.BitbucketClientOrFatal(t, ctxt.Clients.KubernetesClientSet, ctxt.Namespace) - checkBuildStatus(t, bitbucketClient, ctxt.ODS.GitCommitSHA, bitbucket.BuildStatusSuccessful) + tasktesting.CheckBitbucketBuildStatus(t, bitbucketClient, ctxt.ODS.GitCommitSHA, bitbucket.BuildStatusSuccessful) checkArtifactsAreInNexus(t, ctxt, nexus.PermanentRepositoryDefault) }, }, diff --git a/test/tasks/ods-start_test.go b/test/tasks/ods-start_test.go index 590be5f7..9a91fb44 100644 --- a/test/tasks/ods-start_test.go +++ b/test/tasks/ods-start_test.go @@ -57,7 +57,7 @@ func TestTaskODSStart(t *testing.T) { checkODSContext(t, wsDir, ctxt.ODS) bitbucketClient := tasktesting.BitbucketClientOrFatal(t, ctxt.Clients.KubernetesClientSet, ctxt.Namespace) - checkBuildStatus(t, bitbucketClient, ctxt.ODS.GitCommitSHA, bitbucket.BuildStatusInProgress) + tasktesting.CheckBitbucketBuildStatus(t, bitbucketClient, ctxt.ODS.GitCommitSHA, bitbucket.BuildStatusInProgress) downloadedArtifact := filepath.Join(wsDir, pipelinectxt.PipelineRunsPath, "foo-zh9gt0.json") if _, err := os.Stat(downloadedArtifact); os.IsNotExist(err) { @@ -142,7 +142,7 @@ func TestTaskODSStart(t *testing.T) { checkFileContent(t, destinationArtifactsBaseDir, xUnitFileSource, xUnitContent) bitbucketClient := tasktesting.BitbucketClientOrFatal(t, ctxt.Clients.KubernetesClientSet, ctxt.Namespace) - checkBuildStatus(t, bitbucketClient, ctxt.ODS.GitCommitSHA, bitbucket.BuildStatusInProgress) + tasktesting.CheckBitbucketBuildStatus(t, bitbucketClient, ctxt.ODS.GitCommitSHA, bitbucket.BuildStatusInProgress) }, },