Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func (t ResolvedPipelineRunTask) IsCustomTask() bool {
return t.CustomTask
}

// IsMatrixed return true if the PipelineTask has a Matrix.
func (t ResolvedPipelineRunTask) IsMatrixed() bool {
return len(t.PipelineTask.Matrix) > 0
}

// IsSuccessful returns true only if the run has completed successfully
func (t ResolvedPipelineRunTask) IsSuccessful() bool {
if t.IsCustomTask() {
Expand Down
79 changes: 79 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2705,3 +2705,82 @@ func TestGetRunName(t *testing.T) {
})
}
}

func TestIsMatrixed(t *testing.T) {
pr := v1beta1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: "pipelinerun",
},
}
getTask := func(ctx context.Context, name string) (v1beta1.TaskObject, error) { return task, nil }
getTaskRun := func(name string) (*v1beta1.TaskRun, error) { return &trs[0], nil }
getRun := func(name string) (*v1alpha1.Run, error) { return &runs[0], nil }

for _, tc := range []struct {
name string
pt v1beta1.PipelineTask
want bool
}{{
name: "custom task with matrix",
pt: v1beta1.PipelineTask{
TaskRef: &v1beta1.TaskRef{
APIVersion: "example.dev/v0",
Kind: "Sample",
},
Matrix: []v1beta1.Param{{
Name: "platform",
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}},
}},
},
want: true,
}, {
name: "custom task without matrix",
pt: v1beta1.PipelineTask{
TaskRef: &v1beta1.TaskRef{
APIVersion: "example.dev/v0",
Kind: "Sample",
},
},
want: false,
}, {
name: "task with matrix",
pt: v1beta1.PipelineTask{
TaskRef: &v1beta1.TaskRef{
Name: "my-task",
},
Matrix: []v1beta1.Param{{
Name: "platform",
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}},
}},
},
want: true,
}, {
name: "task without matrix",
pt: v1beta1.PipelineTask{
TaskRef: &v1beta1.TaskRef{
Name: "my-task",
},
},
want: false,
}} {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
cfg := config.NewStore(logtesting.TestLogger(t))
cfg.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName()},
Data: map[string]string{
"enable-api-fields": "alpha",
},
})
ctx = cfg.ToContext(ctx)
rprt, err := ResolvePipelineRunTask(ctx, pr, getTask, getTaskRun, getRun, tc.pt, nil)
if err != nil {
t.Fatalf("Did not expect error when resolving PipelineRun: %v", err)
}
got := rprt.IsMatrixed()
if d := cmp.Diff(tc.want, got); d != "" {
t.Errorf("IsMatrixed: %s", diff.PrintWantGot(d))
}
})
}
}