|
1 | | -//go:build e2e |
2 | | - |
3 | 1 | package test |
4 | 2 |
|
5 | 3 | import ( |
6 | 4 | "context" |
7 | 5 | "fmt" |
| 6 | + "strings" |
8 | 7 | "testing" |
9 | 8 | "time" |
10 | 9 |
|
11 | 10 | "github.com/ktrysmt/go-bitbucket" |
| 11 | + "github.com/mitchellh/mapstructure" |
12 | 12 | "github.com/openshift-pipelines/pipelines-as-code/pkg/params/triggertype" |
| 13 | + "github.com/openshift-pipelines/pipelines-as-code/pkg/provider/bitbucketcloud/types" |
13 | 14 | tbb "github.com/openshift-pipelines/pipelines-as-code/test/pkg/bitbucketcloud" |
14 | 15 | "github.com/openshift-pipelines/pipelines-as-code/test/pkg/options" |
15 | 16 | "github.com/openshift-pipelines/pipelines-as-code/test/pkg/payload" |
@@ -107,6 +108,65 @@ func TestBitbucketCloudPullRequestCancelInProgressMerged(t *testing.T) { |
107 | 108 | assert.Equal(t, prs.Items[0].GetStatusCondition().GetCondition(apis.ConditionSucceeded).GetReason(), "Cancelled", "should have been cancelled") |
108 | 109 | } |
109 | 110 |
|
| 111 | +func TestBitbucketCloudPRBuildStatusReported(t *testing.T) { |
| 112 | + targetNS := names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-ns") |
| 113 | + ctx := context.Background() |
| 114 | + |
| 115 | + runcnx, opts, bprovider, err := tbb.Setup(ctx) |
| 116 | + if err != nil { |
| 117 | + t.Skip(err.Error()) |
| 118 | + return |
| 119 | + } |
| 120 | + bcrepo := tbb.CreateCRD(ctx, t, bprovider, runcnx, opts, targetNS) |
| 121 | + targetRefName := names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-test") |
| 122 | + title := "TestPullRequest - " + targetRefName |
| 123 | + |
| 124 | + entries, err := payload.GetEntries( |
| 125 | + map[string]string{".tekton/pipelinerun.yaml": "testdata/pipelinerun.yaml"}, |
| 126 | + targetNS, options.MainBranch, triggertype.PullRequest.String(), map[string]string{}) |
| 127 | + assert.NilError(t, err) |
| 128 | + |
| 129 | + pr, repobranch := tbb.MakePR(t, bprovider, runcnx, bcrepo, opts, title, targetRefName, entries) |
| 130 | + defer tbb.TearDown(ctx, t, runcnx, bprovider, opts, pr.ID, targetRefName, targetNS, false) |
| 131 | + |
| 132 | + hash, ok := repobranch.Target["hash"].(string) |
| 133 | + assert.Assert(t, ok) |
| 134 | + |
| 135 | + sopt := twait.SuccessOpt{ |
| 136 | + TargetNS: targetNS, |
| 137 | + OnEvent: triggertype.PullRequest.String(), |
| 138 | + NumberofPRMatch: 1, |
| 139 | + SHA: hash, |
| 140 | + Title: title, |
| 141 | + MinNumberStatus: 1, |
| 142 | + } |
| 143 | + twait.Succeeded(ctx, t, runcnx, opts, sopt) |
| 144 | + |
| 145 | + resp, err := bprovider.Client().Repositories.Commits.GetCommitStatuses(&bitbucket.CommitsOptions{ |
| 146 | + Owner: opts.Organization, |
| 147 | + RepoSlug: opts.Repo, |
| 148 | + Revision: hash, |
| 149 | + }) |
| 150 | + assert.NilError(t, err) |
| 151 | + |
| 152 | + statusesMap, ok := resp.(map[string]any) |
| 153 | + assert.Equal(t, ok, true, "cannot convert Bitbucket commit statuses response to map[string]any") |
| 154 | + |
| 155 | + statues := []*types.Status{} |
| 156 | + |
| 157 | + err = mapstructure.Decode(statusesMap["values"], &statues) |
| 158 | + assert.NilError(t, err, fmt.Sprintf("cannot decode Bitbucket commit statuses from response payload: %v", err)) |
| 159 | + |
| 160 | + foundStatus := false |
| 161 | + for _, status := range statues { |
| 162 | + if strings.Contains(status.Key, "pipelinerun-") { |
| 163 | + foundStatus = true |
| 164 | + break |
| 165 | + } |
| 166 | + } |
| 167 | + assert.Equal(t, foundStatus, true, "should have found the status for the pipeline run") |
| 168 | +} |
| 169 | + |
110 | 170 | // Local Variables: |
111 | 171 | // compile-command: "go test -tags=e2e -v -run TestBitbucketCloudPullRequest$ ." |
112 | 172 | // End: |
0 commit comments