|
| 1 | +//go:build e2e |
| 2 | +// +build e2e |
| 3 | + |
| 4 | +package test |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + "fmt" |
| 9 | + "os" |
| 10 | + "regexp" |
| 11 | + "testing" |
| 12 | + |
| 13 | + "github.com/openshift-pipelines/pipelines-as-code/pkg/params/triggertype" |
| 14 | + tbbs "github.com/openshift-pipelines/pipelines-as-code/test/pkg/bitbucketserver" |
| 15 | + "github.com/openshift-pipelines/pipelines-as-code/test/pkg/payload" |
| 16 | + "github.com/openshift-pipelines/pipelines-as-code/test/pkg/scm" |
| 17 | + "github.com/openshift-pipelines/pipelines-as-code/test/pkg/wait" |
| 18 | + |
| 19 | + "github.com/tektoncd/pipeline/pkg/names" |
| 20 | + "gotest.tools/v3/assert" |
| 21 | +) |
| 22 | + |
| 23 | +func TestBitbucketServerDynamicVariables(t *testing.T) { |
| 24 | + targetNS := names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-ns") |
| 25 | + ctx := context.Background() |
| 26 | + bitbucketWSOwner := os.Getenv("TEST_BITBUCKET_SERVER_E2E_REPOSITORY") |
| 27 | + |
| 28 | + ctx, runcnx, opts, client, err := tbbs.Setup(ctx) |
| 29 | + assert.NilError(t, err) |
| 30 | + |
| 31 | + repo := tbbs.CreateCRD(ctx, t, client, runcnx, bitbucketWSOwner, targetNS) |
| 32 | + runcnx.Clients.Log.Infof("Repository %s has been created", repo.Name) |
| 33 | + defer tbbs.TearDownNs(ctx, t, runcnx, targetNS) |
| 34 | + |
| 35 | + branch, _, err := client.Git.CreateRef(ctx, bitbucketWSOwner, targetNS, "refs/heads/main") |
| 36 | + assert.NilError(t, err) |
| 37 | + runcnx.Clients.Log.Infof("Branch %s has been created", branch.Name) |
| 38 | + |
| 39 | + files := map[string]string{ |
| 40 | + ".tekton/pipelinerun.yaml": "testdata/pipelinerun-dynamic-vars.yaml", |
| 41 | + } |
| 42 | + |
| 43 | + files, err = payload.GetEntries(files, targetNS, targetNS, triggertype.Push.String(), map[string]string{}) |
| 44 | + assert.NilError(t, err) |
| 45 | + gitCloneURL, err := scm.MakeGitCloneURL(repo.Clone, opts.UserName, opts.Password) |
| 46 | + assert.NilError(t, err) |
| 47 | + |
| 48 | + commitMsg := fmt.Sprintf("commit %s", targetNS) |
| 49 | + scmOpts := &scm.Opts{ |
| 50 | + GitURL: gitCloneURL, |
| 51 | + Log: runcnx.Clients.Log, |
| 52 | + WebURL: repo.Clone, |
| 53 | + TargetRefName: targetNS, |
| 54 | + BaseRefName: repo.Branch, |
| 55 | + CommitTitle: commitMsg, |
| 56 | + } |
| 57 | + scm.PushFilesToRefGit(t, scmOpts, files) |
| 58 | + runcnx.Clients.Log.Infof("Files has been pushed to branch %s", targetNS) |
| 59 | + |
| 60 | + successOpts := wait.SuccessOpt{ |
| 61 | + TargetNS: targetNS, |
| 62 | + OnEvent: triggertype.Push.String(), |
| 63 | + NumberofPRMatch: 1, |
| 64 | + MinNumberStatus: 1, |
| 65 | + } |
| 66 | + wait.Succeeded(ctx, t, runcnx, opts, successOpts) |
| 67 | + |
| 68 | + reg := *regexp.MustCompile(fmt.Sprintf("event: repo:refs_changed, refId: refs/heads/%s, message: %s", targetNS, commitMsg)) |
| 69 | + err = wait.RegexpMatchingInPodLog(ctx, runcnx, targetNS, "pipelinesascode.tekton.dev/original-prname=pipelinerun-dynamic-vars", "step-task", reg, "", 2) |
| 70 | + assert.NilError(t, err) |
| 71 | +} |
0 commit comments