@@ -86,54 +86,14 @@ func TestGithubPullRequestGitOpsComments(t *testing.T) {
8686 prNum : 4 ,
8787 },
8888 }
89- assert .NilError (t , err )
90- err = twait .UntilPipelineRunCreated (ctx , g .Cnx .Clients , waitOpts )
91- assert .NilError (t , err )
92-
93- g .Cnx .Clients .Log .Infof ("/cancel pr-gitops-comment on Pull Request" )
94- _ , _ , err = g .Provider .Client .Issues .CreateComment (ctx ,
95- g .Options .Organization ,
96- g .Options .Repo , g .PRNumber ,
97- & github.IssueComment {Body : github .Ptr ("/cancel pr-gitops-comment" )})
98- assert .NilError (t , err )
99-
100- waitOpts = twait.Opts {
101- RepoName : g .TargetNamespace ,
102- Namespace : g .TargetNamespace ,
103- MinNumberStatus : 3 ,
104- PollTimeout : twait .DefaultTimeout ,
105- TargetSHA : g .SHA ,
106- }
107- g .Cnx .Clients .Log .Info ("Waiting for Repository to be updated" )
108- _ , err = twait .UntilRepositoryUpdated (ctx , g .Cnx .Clients , waitOpts )
109- assert .NilError (t , err )
110-
111- g .Cnx .Clients .Log .Infof ("Check if we have the repository set as succeeded" )
112- repo , err := g .Cnx .Clients .PipelineAsCode .PipelinesascodeV1alpha1 ().Repositories (g .TargetNamespace ).Get (ctx , g .TargetNamespace , metav1.GetOptions {})
113- assert .NilError (t , err )
114- assert .Equal (t , repo .Status [len (repo .Status )- 1 ].Conditions [0 ].Status , corev1 .ConditionFalse )
115-
116- pruns , err = g .Cnx .Clients .Tekton .TektonV1 ().PipelineRuns (g .TargetNamespace ).List (ctx , metav1.ListOptions {
117- LabelSelector : fmt .Sprintf ("%s=%s" , keys .SHA , g .SHA ),
118- })
119- assert .NilError (t , err )
120- assert .Equal (t , len (pruns .Items ), 3 )
121-
122- // go over all pruns check that at least one is canceled and the other two are succeeded
123- canceledCount := 0
124- succeededCount := 0
125- unknownCount := 0
126- for _ , prun := range pruns .Items {
127- for _ , condition := range prun .Status .Conditions {
128- if condition .Type == "Succeeded" {
129- switch condition .Status {
130- case corev1 .ConditionFalse :
131- canceledCount ++
132- case corev1 .ConditionTrue :
133- succeededCount ++
134- case corev1 .ConditionUnknown :
135- unknownCount ++
136- }
89+ for _ , tt := range tests {
90+ t .Run (tt .name , func (t * testing.T ) {
91+ waitOpts := twait.Opts {
92+ RepoName : g .TargetNamespace ,
93+ Namespace : g .TargetNamespace ,
94+ MinNumberStatus : tt .prNum ,
95+ PollTimeout : twait .DefaultTimeout ,
96+ TargetSHA : g .SHA ,
13797 }
13898 if tt .comment == "/cancel pr-gitops-comment" {
13999 g .Cnx .Clients .Log .Info ("/test pr-gitops-comment on Pull Request before canceling" )
@@ -172,7 +132,4 @@ func TestGithubPullRequestGitOpsComments(t *testing.T) {
172132 assert .Equal (t , len (pruns .Items ), tt .prNum )
173133 })
174134 }
175- assert .Equal (t , canceledCount , 1 , "should have one canceled PipelineRun" )
176- assert .Equal (t , succeededCount , 2 , "should have two succeeded PipelineRuns" )
177- assert .Equal (t , unknownCount , 0 , "should have zero unknown PipelineRuns: %+v" , pruns .Items )
178135}
0 commit comments