Skip to content

Commit 5e15f05

Browse files
committed
test: add test for matrix params with string value containing variable reference
fix #8324
1 parent fbd647e commit 5e15f05

File tree

4 files changed

+203
-7
lines changed

4 files changed

+203
-7
lines changed

pkg/apis/pipeline/v1/matrix_types_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,8 @@ func TestPipelineTask_CountCombinations(t *testing.T) {
782782
}{{
783783
name: "combinations count is zero",
784784
matrix: &v1.Matrix{
785-
Params: v1.Params{{}}},
785+
Params: v1.Params{},
786+
},
786787
want: 0,
787788
}, {
788789
name: "combinations count is one from one parameter",
@@ -915,11 +916,20 @@ func TestPipelineTask_CountCombinations(t *testing.T) {
915916
}},
916917
}},
917918
want: 7,
919+
}, {
920+
name: "matrix params with string value containing variable reference",
921+
matrix: &v1.Matrix{
922+
Params: v1.Params{{
923+
Name: "GOARCH", Value: v1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}},
924+
}, {
925+
Name: "version", Value: v1.ParamValue{StringVal: "$(tasks.platforms.results.str[*])"}},
926+
}},
927+
want: 3,
918928
}}
919929
for _, tt := range tests {
920930
t.Run(tt.name, func(t *testing.T) {
921931
if d := cmp.Diff(tt.want, tt.matrix.CountCombinations()); d != "" {
922-
t.Errorf("Matrix.CountCombinations() errors diff %s", diff.PrintWantGot(d))
932+
t.Errorf("%s Matrix.CountCombinations() errors diff %s", tt.name, diff.PrintWantGot(d))
923933
}
924934
})
925935
}

pkg/reconciler/pipelinerun/pipelinerun_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8939,8 +8939,14 @@ spec:
89398939
script: |
89408940
echo "$(params.platform)"
89418941
- name: b-task
8942-
taskRef:
8943-
name: mytask
8942+
taskSpec:
8943+
params:
8944+
- name: platform
8945+
steps:
8946+
- name: echo
8947+
image: alpine
8948+
script: |
8949+
echo "$(params.platform)"
89448950
matrix:
89458951
params:
89468952
- name: platform

pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,10 +3800,10 @@ func TestResolvePipelineRunTask_WithMatrix(t *testing.T) {
38003800
name: "task with matrix - whole array results",
38013801
pt: pts[2],
38023802
want: &ResolvedPipelineTask{
3803-
TaskRunNames: nil,
3803+
TaskRunNames: []string{"pipelinerun-pipelinetask-with-whole-array-results"},
38043804
TaskRuns: nil,
38053805
PipelineTask: &pts[2],
3806-
ResolvedTask: nil,
3806+
ResolvedTask: rtr,
38073807
},
38083808
pst: pipelineRunState,
38093809
}} {

test/matrix_test.go

Lines changed: 181 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
3030
"github.com/tektoncd/pipeline/test/diff"
3131
"github.com/tektoncd/pipeline/test/parse"
32+
corev1 "k8s.io/api/core/v1"
3233
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3334
"knative.dev/pkg/apis"
3435
duckv1 "knative.dev/pkg/apis/duck/v1"
@@ -68,11 +69,14 @@ spec:
6869
default: ""
6970
- name: package
7071
default: ""
72+
results:
73+
- name: str
74+
type: string
7175
steps:
7276
- name: echo
7377
image: mirror.gcr.io/alpine
7478
script: |
75-
echo "$(params.GOARCH) and $(params.version)"
79+
echo -n "$(params.GOARCH) and $(params.version)" | tee $(results.str.path)
7680
`, namespace))
7781

7882
task1withresults := parse.MustParseV1Task(t, fmt.Sprintf(`
@@ -107,6 +111,22 @@ spec:
107111
echo -n "[\"go1.17\",\"go1.18.1\"]" | tee $(results.versions.path)
108112
`, namespace))
109113

114+
task3printer := parse.MustParseV1Task(t, fmt.Sprintf(`
115+
metadata:
116+
name: printer
117+
namespace: %s
118+
spec:
119+
params:
120+
- name: platform
121+
value: "default-platform"
122+
steps:
123+
- name: produce-a-list-of-versions
124+
image: mirror.gcr.io/bash
125+
script: |
126+
#!/usr/bin/env bash
127+
echo "platform: $(params.platform)"
128+
`, namespace))
129+
110130
if _, err := c.V1TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil {
111131
t.Fatalf("Failed to create Task `%s`: %s", task.Name, err)
112132
}
@@ -116,6 +136,9 @@ spec:
116136
if _, err := c.V1TaskClient.Create(ctx, task2withresults, metav1.CreateOptions{}); err != nil {
117137
t.Fatalf("Failed to create Task `%s`: %s", task2withresults.Name, err)
118138
}
139+
if _, err := c.V1TaskClient.Create(ctx, task3printer, metav1.CreateOptions{}); err != nil {
140+
t.Fatalf("Failed to create Task `%s`: %s", task3printer.Name, err)
141+
}
119142

120143
pipeline := parse.MustParseV1Pipeline(t, fmt.Sprintf(`
121144
metadata:
@@ -157,6 +180,13 @@ spec:
157180
params:
158181
- name: GOARCH
159182
value: I-do-not-exist
183+
- name: printer-matrix
184+
taskRef:
185+
name: printer
186+
matrix:
187+
params:
188+
- name: platform
189+
value: $(tasks.matrix-include.results.str[*])
160190
`, helpers.ObjectNameForTest(t), namespace))
161191

162192
pipelineRun := parse.MustParseV1PipelineRun(t, fmt.Sprintf(`
@@ -208,6 +238,11 @@ spec:
208238
}}},
209239
TaskRunStatusFields: v1.TaskRunStatusFields{
210240
Artifacts: &v1.Artifacts{},
241+
Results: []v1.TaskRunResult{{
242+
Name: "str",
243+
Type: v1.ResultsTypeString,
244+
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64 and go1.17"},
245+
}},
211246
},
212247
},
213248
}, {
@@ -240,6 +275,11 @@ spec:
240275
}}},
241276
TaskRunStatusFields: v1.TaskRunStatusFields{
242277
Artifacts: &v1.Artifacts{},
278+
Results: []v1.TaskRunResult{{
279+
Name: "str",
280+
Type: v1.ResultsTypeString,
281+
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le and go1.17"},
282+
}},
243283
},
244284
},
245285
}, {
@@ -269,6 +309,11 @@ spec:
269309
}}},
270310
TaskRunStatusFields: v1.TaskRunStatusFields{
271311
Artifacts: &v1.Artifacts{},
312+
Results: []v1.TaskRunResult{{
313+
Name: "str",
314+
Type: v1.ResultsTypeString,
315+
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64 and go1.18.1"},
316+
}},
272317
},
273318
},
274319
}, {
@@ -298,6 +343,11 @@ spec:
298343
}}},
299344
TaskRunStatusFields: v1.TaskRunStatusFields{
300345
Artifacts: &v1.Artifacts{},
346+
Results: []v1.TaskRunResult{{
347+
Name: "str",
348+
Type: v1.ResultsTypeString,
349+
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le and go1.18.1"},
350+
}},
301351
},
302352
},
303353
}, {
@@ -319,6 +369,136 @@ spec:
319369
Reason: "Succeeded",
320370
Message: "All Steps have completed executing",
321371
}}},
372+
TaskRunStatusFields: v1.TaskRunStatusFields{
373+
Artifacts: &v1.Artifacts{},
374+
Results: []v1.TaskRunResult{{
375+
Name: "str",
376+
Type: v1.ResultsTypeString,
377+
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "I-do-not-exist and "},
378+
}},
379+
},
380+
},
381+
}, {
382+
ObjectMeta: metav1.ObjectMeta{
383+
Name: "pr-printer-matrix-0",
384+
},
385+
Spec: v1.TaskRunSpec{
386+
Params: v1.Params{{
387+
Name: "platform",
388+
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64 and go1.17"},
389+
}},
390+
ServiceAccountName: "default",
391+
TaskRef: &v1.TaskRef{Name: "printer", Kind: v1.NamespacedTaskKind},
392+
},
393+
Status: v1.TaskRunStatus{
394+
Status: duckv1.Status{
395+
Conditions: duckv1.Conditions{{
396+
Type: apis.ConditionSucceeded,
397+
Status: corev1.ConditionTrue,
398+
Reason: "Succeeded",
399+
Message: "All Steps have completed executing",
400+
}},
401+
},
402+
TaskRunStatusFields: v1.TaskRunStatusFields{
403+
Artifacts: &v1.Artifacts{},
404+
},
405+
},
406+
}, {
407+
ObjectMeta: metav1.ObjectMeta{
408+
Name: "pr-printer-matrix-1",
409+
},
410+
Spec: v1.TaskRunSpec{
411+
Params: v1.Params{{
412+
Name: "platform",
413+
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le and go1.17"},
414+
}},
415+
ServiceAccountName: "default",
416+
TaskRef: &v1.TaskRef{Name: "printer", Kind: v1.NamespacedTaskKind},
417+
},
418+
Status: v1.TaskRunStatus{
419+
Status: duckv1.Status{
420+
Conditions: duckv1.Conditions{{
421+
Type: apis.ConditionSucceeded,
422+
Status: corev1.ConditionTrue,
423+
Reason: "Succeeded",
424+
Message: "All Steps have completed executing",
425+
}},
426+
},
427+
TaskRunStatusFields: v1.TaskRunStatusFields{
428+
Artifacts: &v1.Artifacts{},
429+
},
430+
},
431+
}, {
432+
ObjectMeta: metav1.ObjectMeta{
433+
Name: "pr-printer-matrix-2",
434+
},
435+
Spec: v1.TaskRunSpec{
436+
Params: v1.Params{{
437+
Name: "platform",
438+
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64 and go1.18.1"},
439+
}},
440+
ServiceAccountName: "default",
441+
TaskRef: &v1.TaskRef{Name: "printer", Kind: v1.NamespacedTaskKind},
442+
},
443+
Status: v1.TaskRunStatus{
444+
Status: duckv1.Status{
445+
Conditions: duckv1.Conditions{{
446+
Type: apis.ConditionSucceeded,
447+
Status: corev1.ConditionTrue,
448+
Reason: "Succeeded",
449+
Message: "All Steps have completed executing",
450+
}},
451+
},
452+
TaskRunStatusFields: v1.TaskRunStatusFields{
453+
Artifacts: &v1.Artifacts{},
454+
},
455+
},
456+
}, {
457+
ObjectMeta: metav1.ObjectMeta{
458+
Name: "pr-printer-matrix-3",
459+
},
460+
Spec: v1.TaskRunSpec{
461+
Params: v1.Params{{
462+
Name: "platform",
463+
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le and go1.18.1"},
464+
}},
465+
ServiceAccountName: "default",
466+
TaskRef: &v1.TaskRef{Name: "printer", Kind: v1.NamespacedTaskKind},
467+
},
468+
Status: v1.TaskRunStatus{
469+
Status: duckv1.Status{
470+
Conditions: duckv1.Conditions{{
471+
Type: apis.ConditionSucceeded,
472+
Status: corev1.ConditionTrue,
473+
Reason: "Succeeded",
474+
Message: "All Steps have completed executing",
475+
}},
476+
},
477+
TaskRunStatusFields: v1.TaskRunStatusFields{
478+
Artifacts: &v1.Artifacts{},
479+
},
480+
},
481+
}, {
482+
ObjectMeta: metav1.ObjectMeta{
483+
Name: "pr-printer-matrix-4",
484+
},
485+
Spec: v1.TaskRunSpec{
486+
Params: v1.Params{{
487+
Name: "platform",
488+
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "I-do-not-exist and "},
489+
}},
490+
ServiceAccountName: "default",
491+
TaskRef: &v1.TaskRef{Name: "printer", Kind: v1.NamespacedTaskKind},
492+
},
493+
Status: v1.TaskRunStatus{
494+
Status: duckv1.Status{
495+
Conditions: duckv1.Conditions{{
496+
Type: apis.ConditionSucceeded,
497+
Status: corev1.ConditionTrue,
498+
Reason: "Succeeded",
499+
Message: "All Steps have completed executing",
500+
}},
501+
},
322502
TaskRunStatusFields: v1.TaskRunStatusFields{
323503
Artifacts: &v1.Artifacts{},
324504
},

0 commit comments

Comments
 (0)