@@ -75,6 +75,62 @@ func TestRemote(t *testing.T) {
7575 pipelinewithTaskRefYamlB , err := yaml .Marshal (pipelinewithTaskRef )
7676 assert .NilError (t , err )
7777
78+ pipelineRelativeTaskRef := []tektonv1.PipelineTask {
79+ {
80+ Name : remoteTaskName + "-a" ,
81+ TaskRef : & tektonv1.TaskRef {
82+ Name : remoteTaskName + "-a" ,
83+ },
84+ },
85+ {
86+ Name : remoteTaskName + "-b" ,
87+ TaskRef : & tektonv1.TaskRef {
88+ Name : remoteTaskName + "-b" ,
89+ },
90+ },
91+ {
92+ Name : remoteTaskName + "-c" ,
93+ TaskRef : & tektonv1.TaskRef {
94+ Name : remoteTaskName + "-c" ,
95+ },
96+ },
97+ {
98+ Name : remoteTaskName + "-d" ,
99+ TaskRef : & tektonv1.TaskRef {
100+ Name : remoteTaskName + "-d" ,
101+ },
102+ },
103+ }
104+ pipelineWithRelativeTaskRef := ttkn .MakePipeline (remotePipelineName , pipelineRelativeTaskRef [:3 ], map [string ]string {
105+ apipac .Task : "./" + remoteTaskName + "-a" ,
106+ apipac .Task + "-1" : "../" + remoteTaskName + "-b" ,
107+ apipac .Task + "-2" : "../../../../" + remoteTaskName + "-c" ,
108+ })
109+
110+ pipelineWithRelativeTaskRefYamlB , err := yaml .Marshal (pipelineWithRelativeTaskRef )
111+ assert .NilError (t , err )
112+
113+ pipelineWithRelativeTaskRef1 := ttkn .MakePipeline (remotePipelineName , pipelineRelativeTaskRef [1 :], map [string ]string {
114+ apipac .Task : remoteTaskName + "-b" ,
115+ apipac .Task + "-1" : "utils/" + remoteTaskName + "-c" ,
116+ apipac .Task + "-2" : " " + remoteTaskName + "-d" ,
117+ })
118+
119+ pipelineWithRelativeTaskRefYamlB1 , err := yaml .Marshal (pipelineWithRelativeTaskRef1 )
120+ assert .NilError (t , err )
121+
122+ singleRelativeTaskBa , err := ttkn .MakeTaskB (remoteTaskName + "-a" , taskFromPipelineSpec )
123+ assert .NilError (t , err )
124+
125+ singleRelativeTaskBb , err := ttkn .MakeTaskB (remoteTaskName + "-b" , taskFromPipelineSpec )
126+ assert .NilError (t , err )
127+
128+ singleRelativeTaskBc , err := ttkn .MakeTaskB (remoteTaskName + "-c" , taskFromPipelineSpec )
129+ assert .NilError (t , err )
130+
131+ singleRelativeTaskBd , err := ttkn .MakeTaskB (remoteTaskName + "-d" , taskFromPipelineSpec )
132+ assert .NilError (t , err )
133+
78134 singleTask := ttkn .MakeTask (remoteTaskName , taskFromPipelineSpec )
79135 singleTaskB , err := yaml .Marshal (singleTask )
80136 assert .NilError (t , err )
@@ -92,7 +148,7 @@ func TestRemote(t *testing.T) {
92148 remoteURLS map [string ]map [string ]string
93149 expectedLogsSnippets []string
94150 expectedTaskSpec tektonv1.TaskSpec
95- expectedPipelineRun string
151+ expectedPipelineRun [] string
96152 noPipelineRun bool
97153 }{
98154 {
@@ -127,7 +183,66 @@ func TestRemote(t *testing.T) {
127183 fmt .Sprintf ("successfully fetched %s from remote https url" , remotePipelineURL ),
128184 fmt .Sprintf ("successfully fetched %s from remote https url" , remoteTaskURL ),
129185 },
130- expectedPipelineRun : "remote-pipeline-with-remote-task-from-pipeline.yaml" ,
186+ expectedPipelineRun : []string {"remote-pipeline-with-remote-task-from-pipeline.yaml" },
187+ },
188+ {
189+ name : "remote pipelines with relative tasks" ,
190+ pipelineruns : []* tektonv1.PipelineRun {
191+ ttkn .MakePR (randomPipelineRunName , map [string ]string {
192+ apipac .Pipeline : remotePipelineURL ,
193+ },
194+ tektonv1.PipelineRunSpec {
195+ PipelineRef : & tektonv1.PipelineRef {
196+ Name : remotePipelineName ,
197+ },
198+ },
199+ ),
200+ ttkn .MakePR (randomPipelineRunName , map [string ]string {
201+ apipac .Pipeline : remotePipelineURL + "-1" ,
202+ },
203+ tektonv1.PipelineRunSpec {
204+ PipelineRef : & tektonv1.PipelineRef {
205+ Name : remotePipelineName ,
206+ },
207+ },
208+ ),
209+ },
210+ remoteURLS : map [string ]map [string ]string {
211+ remotePipelineURL : {
212+ "body" : string (pipelineWithRelativeTaskRefYamlB ),
213+ "code" : "200" ,
214+ },
215+ remotePipelineURL + "-1" : {
216+ "body" : string (pipelineWithRelativeTaskRefYamlB1 ),
217+ "code" : "200" ,
218+ },
219+ remoteTaskURL + "-a" : {
220+ "body" : string (singleRelativeTaskBa ),
221+ "code" : "200" ,
222+ },
223+ remoteTaskURL + "-b" : {
224+ "body" : string (singleRelativeTaskBb ),
225+ "code" : "200" ,
226+ },
227+ remoteTaskURL + "-c" : {
228+ "body" : string (singleRelativeTaskBc ),
229+ "code" : "200" ,
230+ },
231+ "http://remote/utils/remote-task-c" : {
232+ "body" : string (singleRelativeTaskBc ),
233+ "code" : "200" ,
234+ },
235+ remoteTaskURL + "-d" : {
236+ "body" : string (singleRelativeTaskBd ),
237+ "code" : "200" ,
238+ },
239+ },
240+ expectedTaskSpec : taskFromPipelineSpec ,
241+ expectedLogsSnippets : []string {},
242+ expectedPipelineRun : []string {
243+ "remote-pipeline-with-relative-tasks.yaml" ,
244+ "remote-pipeline-with-relative-tasks-1.yaml" ,
245+ },
131246 },
132247 {
133248 name : "remote pipeline with remote task in pipeline overridden from pipelinerun" ,
@@ -162,7 +277,7 @@ func TestRemote(t *testing.T) {
162277 fmt .Sprintf ("successfully fetched %s from remote https url" , remotePipelineURL ),
163278 fmt .Sprintf ("successfully fetched %s from remote https url" , taskFromPipelineRunURL ),
164279 },
165- expectedPipelineRun : "remote-pipeline-with-remote-task-from-pipelinerun.yaml" ,
280+ expectedPipelineRun : [] string { "remote-pipeline-with-remote-task-from-pipelinerun.yaml" } ,
166281 },
167282 {
168283 name : "remote pipelinerun no annotations" ,
@@ -222,7 +337,7 @@ func TestRemote(t *testing.T) {
222337 fmt .Sprintf ("successfully fetched %s from remote https url" , remotePipelineURL ),
223338 fmt .Sprintf ("successfully fetched %s from remote https url" , remoteTaskURL ),
224339 },
225- expectedPipelineRun : "skip-fetching-multiple-tasks-of-the-same-name-from-pipelinerun-annotations-and-pipeline-annotation.yaml" ,
340+ expectedPipelineRun : [] string { "skip-fetching-multiple-tasks-of-the-same-name-from-pipelinerun-annotations-and-pipeline-annotation.yaml" } ,
226341 },
227342 {
228343 name : "skip fetching multiple tasks of the same name from pipelinerun annotations and tektondir" ,
@@ -258,7 +373,7 @@ func TestRemote(t *testing.T) {
258373 fmt .Sprintf ("skipping remote task %s as already fetched task %s for pipelinerun %s" , remoteTaskURL , remoteTaskName , randomPipelineRunName ),
259374 fmt .Sprintf ("overriding task %s coming from .tekton directory by an annotation task for pipelinerun %s" , remoteTaskName , randomPipelineRunName ),
260375 },
261- expectedPipelineRun : "skip-fetching-multiple-tasks-of-the-same-name-from-pipelinerun-annotations-and-tektondir.yaml" ,
376+ expectedPipelineRun : [] string { "skip-fetching-multiple-tasks-of-the-same-name-from-pipelinerun-annotations-and-tektondir.yaml" } ,
262377 },
263378 {
264379 name : "skip fetching multiple pipelines of the same name from pipelinerun annotations and tektondir" ,
@@ -293,7 +408,7 @@ func TestRemote(t *testing.T) {
293408 fmt .Sprintf ("successfully fetched %s from remote https url" , remoteTaskURL ),
294409 fmt .Sprintf ("skipping remote task %s as already fetched task %s for pipelinerun %s" , remoteTaskURL , remoteTaskName , randomPipelineRunName ),
295410 },
296- expectedPipelineRun : "skip-fetching-multiple-pipelines-of-the-same-name-from-pipelinerun-annotations-and-tektondir.yaml" ,
411+ expectedPipelineRun : [] string { "skip-fetching-multiple-pipelines-of-the-same-name-from-pipelinerun-annotations-and-tektondir.yaml" } ,
297412 },
298413 }
299414 for _ , tt := range tests {
@@ -334,12 +449,18 @@ func TestRemote(t *testing.T) {
334449 assert .Assert (t , len (ret ) == 0 , "not expecting any pipelinerun" )
335450 return
336451 }
337- expectedData , err := os .ReadFile ("testdata/" + tt .expectedPipelineRun )
338- assert .NilError (t , err )
339- pipelineRun := & tektonv1.PipelineRun {}
340- err = yaml .Unmarshal (expectedData , pipelineRun )
341- assert .NilError (t , err )
342- assert .DeepEqual (t , pipelineRun , ret [0 ])
452+ for i , pr := range ret {
453+ if len (tt .expectedPipelineRun ) < len (ret ) {
454+ assert .NilError (t , fmt .Errorf ("insufficient amount of expectedPipelineRuns was provided, got %d but want %d; or set noPipelineRun to true" ,
455+ len (tt .expectedPipelineRun ), len (ret )))
456+ }
457+ expectedData , err := os .ReadFile ("testdata/" + tt .expectedPipelineRun [i ])
458+ assert .NilError (t , err )
459+ pipelineRun := & tektonv1.PipelineRun {}
460+ err = yaml .Unmarshal (expectedData , pipelineRun )
461+ assert .NilError (t , err )
462+ assert .DeepEqual (t , pipelineRun , pr )
463+ }
343464 })
344465 }
345466}
0 commit comments