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