Skip to content

Commit

Permalink
test: check for circular dependency in stepaction validation
Browse files Browse the repository at this point in the history
Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
  • Loading branch information
waveywaves authored and tekton-robot committed Jan 30, 2025
1 parent 8df0a96 commit c6d38c9
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions pkg/apis/pipeline/v1alpha1/stepaction_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,69 @@ func TestStepActionValidateError(t *testing.T) {
Message: `non-existent variable in "$(params.gitrepo.foo)"`,
Paths: []string{"spec.volumeMounts[0]"},
},
}, {
name: "circular dependency in param default values",
fields: fields{
Image: "myimage",
Params: []v1.ParamSpec{{
Name: "param1",
Type: v1.ParamTypeString,
Default: v1.NewStructuredValues("$(params.param2)"),
}, {
Name: "param2",
Type: v1.ParamTypeString,
Default: v1.NewStructuredValues("$(params.param1)"),
}},
},
expectedError: *((&apis.FieldError{
Message: `param "param1" default value has a circular dependency`,
Paths: []string{"spec.params"},
}).Also(&apis.FieldError{
Message: `param "param2" default value has a circular dependency`,
Paths: []string{"spec.params"},
})),
}, {
name: "complex circular dependency in param default values",
fields: fields{
Image: "myimage",
Params: []v1.ParamSpec{{
Name: "param1",
Type: v1.ParamTypeString,
Default: v1.NewStructuredValues("$(params.param2)"),
}, {
Name: "param2",
Type: v1.ParamTypeString,
Default: v1.NewStructuredValues("$(params.param3)"),
}, {
Name: "param3",
Type: v1.ParamTypeString,
Default: v1.NewStructuredValues("$(params.param1)"),
}},
},
expectedError: *((&apis.FieldError{
Message: `param "param1" default value has a circular dependency`,
Paths: []string{"spec.params"},
}).Also(&apis.FieldError{
Message: `param "param2" default value has a circular dependency`,
Paths: []string{"spec.params"},
}).Also(&apis.FieldError{
Message: `param "param3" default value has a circular dependency`,
Paths: []string{"spec.params"},
})),
}, {
name: "self-referential param default value",
fields: fields{
Image: "myimage",
Params: []v1.ParamSpec{{
Name: "param1",
Type: v1.ParamTypeString,
Default: v1.NewStructuredValues("$(params.param1)"),
}},
},
expectedError: apis.FieldError{
Message: `param "param1" default value has a circular dependency`,
Paths: []string{"spec.params"},
},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -594,6 +657,7 @@ func TestStepActionValidateError(t *testing.T) {
if err == nil {
t.Fatalf("Expected an error, got nothing for %v", sa)
}
t.Logf("Actual error: %v", err)
if d := cmp.Diff(tt.expectedError.Error(), err.Error(), cmpopts.IgnoreUnexported(apis.FieldError{})); d != "" {
t.Errorf("StepActionSpec.Validate() errors diff %s", diff.PrintWantGot(d))
}
Expand Down Expand Up @@ -1013,6 +1077,7 @@ func TestStepActionSpecValidateError(t *testing.T) {
if err == nil {
t.Fatalf("Expected an error, got nothing for %v", sa)
}
t.Logf("Actual error: %v", err)
if d := cmp.Diff(tt.expectedError.Error(), err.Error(), cmpopts.IgnoreUnexported(apis.FieldError{})); d != "" {
t.Errorf("StepActionSpec.Validate() errors diff %s", diff.PrintWantGot(d))
}
Expand Down

0 comments on commit c6d38c9

Please sign in to comment.