Skip to content

Commit

Permalink
Check Bitbucket build status in E2E test
Browse files Browse the repository at this point in the history
Closes #187.
  • Loading branch information
michaelsauter committed Oct 5, 2021
1 parent c41cb49 commit 7c6da75
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
11 changes: 11 additions & 0 deletions pkg/tasktesting/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
2 changes: 2 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 0 additions & 12 deletions test/tasks/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

}
6 changes: 3 additions & 3 deletions test/tasks/ods-finish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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)
},
},
Expand All @@ -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)
},
},
Expand Down
4 changes: 2 additions & 2 deletions test/tasks/ods-start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)

},
},
Expand Down

0 comments on commit 7c6da75

Please sign in to comment.