@@ -3143,7 +3143,6 @@ func TestResolvePipelineRunTask_WithMatrix(t *testing.T) {
31433143 Value : v1beta1.ArrayOrString {Type : v1beta1 .ParamTypeArray , ArrayVal : []string {"chrome" , "safari" , "firefox" }},
31443144 }},
31453145 }}
3146-
31473146 rtr := & resources.ResolvedTaskResources {
31483147 TaskName : "task" ,
31493148 TaskSpec : & v1beta1.TaskSpec {Steps : []v1beta1.Step {{
@@ -3201,6 +3200,106 @@ func TestResolvePipelineRunTask_WithMatrix(t *testing.T) {
32013200 }
32023201}
32033202
3203+ func TestResolvePipelineRunTask_WithMatrixedCustomTask (t * testing.T ) {
3204+ pipelineRunName := "pipelinerun"
3205+ pipelineTaskName := "pipelinetask"
3206+
3207+ pr := v1beta1.PipelineRun {
3208+ ObjectMeta : metav1.ObjectMeta {
3209+ Name : pipelineRunName ,
3210+ },
3211+ }
3212+
3213+ var runs []* v1alpha1.Run
3214+ var runNames []string
3215+ runsMap := map [string ]* v1alpha1.Run {}
3216+ for i := 0 ; i < 9 ; i ++ {
3217+ runName := fmt .Sprintf ("%s-%s-%d" , pipelineRunName , pipelineTaskName , i )
3218+ run := & v1alpha1.Run {
3219+ ObjectMeta : metav1.ObjectMeta {
3220+ Name : runName ,
3221+ },
3222+ }
3223+ runs = append (runs , run )
3224+ runNames = append (runNames , runName )
3225+ runsMap [runName ] = run
3226+ }
3227+
3228+ pts := []v1beta1.PipelineTask {{
3229+ Name : "pipelinetask" ,
3230+ TaskRef : & v1beta1.TaskRef {
3231+ APIVersion : "example.dev/v0" ,
3232+ Kind : "Example" ,
3233+ Name : "my-task" ,
3234+ },
3235+ Matrix : []v1beta1.Param {{
3236+ Name : "platform" ,
3237+ Value : v1beta1.ArrayOrString {Type : v1beta1 .ParamTypeArray , ArrayVal : []string {"linux" , "mac" , "windows" }},
3238+ }},
3239+ }, {
3240+ Name : "pipelinetask" ,
3241+ TaskRef : & v1beta1.TaskRef {
3242+ APIVersion : "example.dev/v0" ,
3243+ Kind : "Example" ,
3244+ Name : "my-task" ,
3245+ },
3246+ Matrix : []v1beta1.Param {{
3247+ Name : "platform" ,
3248+ Value : v1beta1.ArrayOrString {Type : v1beta1 .ParamTypeArray , ArrayVal : []string {"linux" , "mac" , "windows" }},
3249+ }, {
3250+ Name : "browsers" ,
3251+ Value : v1beta1.ArrayOrString {Type : v1beta1 .ParamTypeArray , ArrayVal : []string {"chrome" , "safari" , "firefox" }},
3252+ }},
3253+ }}
3254+
3255+ getTask := func (ctx context.Context , name string ) (v1beta1.TaskObject , error ) { return task , nil }
3256+ getTaskRun := func (name string ) (* v1beta1.TaskRun , error ) { return & trs [0 ], nil }
3257+ getRun := func (name string ) (* v1alpha1.Run , error ) { return runsMap [name ], nil }
3258+
3259+ for _ , tc := range []struct {
3260+ name string
3261+ pt v1beta1.PipelineTask
3262+ want * ResolvedPipelineTask
3263+ }{{
3264+ name : "custom task with matrix - single parameter" ,
3265+ pt : pts [0 ],
3266+ want : & ResolvedPipelineTask {
3267+ CustomTask : true ,
3268+ RunNames : runNames [:3 ],
3269+ Runs : runs [:3 ],
3270+ PipelineTask : & pts [0 ],
3271+ },
3272+ }, {
3273+ name : "custom task with matrix - multiple parameters" ,
3274+ pt : pts [1 ],
3275+ want : & ResolvedPipelineTask {
3276+ CustomTask : true ,
3277+ RunNames : runNames ,
3278+ Runs : runs ,
3279+ PipelineTask : & pts [1 ],
3280+ },
3281+ }} {
3282+ t .Run (tc .name , func (t * testing.T ) {
3283+ ctx := context .Background ()
3284+ cfg := config .NewStore (logtesting .TestLogger (t ))
3285+ cfg .OnConfigChanged (& corev1.ConfigMap {
3286+ ObjectMeta : metav1.ObjectMeta {Name : config .GetFeatureFlagsConfigName ()},
3287+ Data : map [string ]string {
3288+ "enable-api-fields" : "alpha" ,
3289+ },
3290+ })
3291+ ctx = cfg .ToContext (ctx )
3292+ rpt , err := ResolvePipelineTask (ctx , pr , getTask , getTaskRun , getRun , tc .pt , nil )
3293+ if err != nil {
3294+ t .Fatalf ("Did not expect error when resolving PipelineRun: %v" , err )
3295+ }
3296+ if d := cmp .Diff (tc .want , rpt ); d != "" {
3297+ t .Errorf ("Did not get expected ResolvedPipelineTask with Matrix and Custom Task: %s" , diff .PrintWantGot (d ))
3298+ }
3299+ })
3300+ }
3301+ }
3302+
32043303func TestIsSuccessful (t * testing.T ) {
32053304 for _ , tc := range []struct {
32063305 name string
0 commit comments