@@ -9,17 +9,12 @@ import (
99 "os"
1010 "testing"
1111
12- "github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/keys"
1312 "github.com/openshift-pipelines/pipelines-as-code/pkg/params/triggertype"
1413 tbbdc "github.com/openshift-pipelines/pipelines-as-code/test/pkg/bitbucketdatacenter"
15- "github.com/openshift-pipelines/pipelines-as-code/test/pkg/options"
16- "github.com/openshift-pipelines/pipelines-as-code/test/pkg/payload"
1714 "github.com/openshift-pipelines/pipelines-as-code/test/pkg/wait"
1815
19- "github.com/jenkins-x/go-scm/scm"
2016 "github.com/tektoncd/pipeline/pkg/names"
2117 "gotest.tools/v3/assert"
22- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2318)
2419
2520func TestBitbucketDataCenterPullRequest (t * testing.T ) {
@@ -40,11 +35,9 @@ func TestBitbucketDataCenterPullRequest(t *testing.T) {
4035 files [fmt .Sprintf (".tekton/pipelinerun-%d.yaml" , i )] = "testdata/pipelinerun.yaml"
4136 }
4237
43- files , err = payload .GetEntries (files , targetNS , options .MainBranch , triggertype .PullRequest .String (), map [string ]string {})
44- assert .NilError (t , err )
45-
4638 pr := tbbdc .CreatePR (ctx , t , client , runcnx , opts , repo , files , bitbucketWSOwner , targetNS )
47- defer tbbdc .TearDown (ctx , t , runcnx , client , pr , bitbucketWSOwner , targetNS )
39+ runcnx .Clients .Log .Infof ("Pull Request with title '%s' is created" , pr .Title )
40+ defer tbbdc .TearDown (ctx , t , runcnx , client , pr .Number , bitbucketWSOwner , targetNS )
4841
4942 successOpts := wait.SuccessOpt {
5043 TargetNS : targetNS ,
@@ -71,11 +64,9 @@ func TestBitbucketDataCenterCELPathChangeInPullRequest(t *testing.T) {
7164 ".tekton/pipelinerun.yaml" : "testdata/pipelinerun-cel-path-changed.yaml" ,
7265 }
7366
74- files , err = payload .GetEntries (files , targetNS , options .MainBranch , triggertype .PullRequest .String (), map [string ]string {})
75- assert .NilError (t , err )
76-
7767 pr := tbbdc .CreatePR (ctx , t , client , runcnx , opts , repo , files , bitbucketWSOwner , targetNS )
78- defer tbbdc .TearDown (ctx , t , runcnx , client , pr , bitbucketWSOwner , targetNS )
68+ runcnx .Clients .Log .Infof ("Pull Request with title '%s' is created" , pr .Title )
69+ defer tbbdc .TearDown (ctx , t , runcnx , client , pr .Number , bitbucketWSOwner , targetNS )
7970
8071 successOpts := wait.SuccessOpt {
8172 TargetNS : targetNS ,
@@ -85,64 +76,3 @@ func TestBitbucketDataCenterCELPathChangeInPullRequest(t *testing.T) {
8576 }
8677 wait .Succeeded (ctx , t , runcnx , opts , successOpts )
8778}
88-
89- func TestBitbucketDataCenterOnPathChangeAnnotationOnPRMerge (t * testing.T ) {
90- targetNS := names .SimpleNameGenerator .RestrictLengthWithRandomSuffix ("pac-e2e-ns" )
91- // this would be a temporary base branch for the pull request we're going to raise
92- // we need this because we're going to merge the pull request so that after test
93- // we can delete the temporary base branch and our main branch should not be affected
94- // by this merge because we run the E2E frequently.
95- tempBaseBranch := names .SimpleNameGenerator .RestrictLengthWithRandomSuffix ("pac-e2e-ns" )
96-
97- ctx := context .Background ()
98- bitbucketWSOwner := os .Getenv ("TEST_BITBUCKET_SERVER_E2E_REPOSITORY" )
99-
100- ctx , runcnx , opts , client , err := tbbdc .Setup (ctx )
101- assert .NilError (t , err )
102-
103- repo := tbbdc .CreateCRD (ctx , t , client , runcnx , bitbucketWSOwner , targetNS )
104- runcnx .Clients .Log .Infof ("Repository %s has been created" , repo .Name )
105- defer tbbdc .TearDownNs (ctx , t , runcnx , targetNS )
106-
107- branch , resp , err := client .Git .CreateRef (ctx , bitbucketWSOwner , tempBaseBranch , repo .Branch )
108- assert .NilError (t , err , "error creating branch: http status code: %d : %v" , resp .Status , err )
109- runcnx .Clients .Log .Infof ("Base branch %s has been created" , branch .Name )
110-
111- opts .BaseBranch = branch .Name
112-
113- if os .Getenv ("TEST_NOCLEANUP" ) != "true" {
114- defer func () {
115- _ , err := client .Git .DeleteRef (ctx , bitbucketWSOwner , tempBaseBranch )
116- assert .NilError (t , err , "error deleting branch: http status code: %d : %v" , resp .Status , err )
117- }()
118- }
119-
120- files := map [string ]string {
121- ".tekton/pr.yaml" : "testdata/pipelinerun-on-path-change.yaml" ,
122- "doc/foo/bar/README.md" : "README.md" ,
123- }
124-
125- files , err = payload .GetEntries (files , targetNS , tempBaseBranch , triggertype .Push .String (), map [string ]string {})
126- assert .NilError (t , err )
127-
128- pr := tbbdc .CreatePR (ctx , t , client , runcnx , opts , repo , files , bitbucketWSOwner , targetNS )
129- defer tbbdc .TearDown (ctx , t , runcnx , client , nil , bitbucketWSOwner , targetNS )
130-
131- // merge the pull request so that we can get push event.
132- _ , err = client .PullRequests .Merge (ctx , bitbucketWSOwner , pr .Number , & scm.PullRequestMergeOptions {})
133- assert .NilError (t , err )
134-
135- successOpts := wait.SuccessOpt {
136- TargetNS : targetNS ,
137- OnEvent : triggertype .Push .String (),
138- NumberofPRMatch : 1 ,
139- MinNumberStatus : 1 ,
140- }
141- wait .Succeeded (ctx , t , runcnx , opts , successOpts )
142-
143- pipelineRuns , err := runcnx .Clients .Tekton .TektonV1 ().PipelineRuns (targetNS ).List (ctx , metav1.ListOptions {})
144- assert .NilError (t , err )
145- assert .Equal (t , len (pipelineRuns .Items ), 1 )
146- // check that pipeline run contains on-path-change annotation.
147- assert .Equal (t , pipelineRuns .Items [0 ].GetAnnotations ()[keys .OnPathChange ], "[doc/***.md]" )
148- }
0 commit comments