Skip to content

Commit

Permalink
Add more unit tests for using non-exist key of an object in task step
Browse files Browse the repository at this point in the history
Prior to this commit, the validation exists to check if individual keys
of an object param being used in task steps indeed exist, but the test
was missed.

In this PR, we add the unit test for that.
  • Loading branch information
chuangw6 authored and tekton-robot committed Sep 1, 2022
1 parent a056c71 commit 2704d7f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/apis/pipeline/v1/task_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,28 @@ func TestTaskSpecValidateError(t *testing.T) {
Message: `variable type invalid in "$(params.gitrepo[*])"`,
Paths: []string{"steps[0].args[0]"},
},
}, {
name: "non-existent individual key of an object param is used in task step",
fields: fields{
Params: []v1.ParamSpec{{
Name: "gitrepo",
Type: v1.ParamTypeObject,
Properties: map[string]v1.PropertySpec{
"url": {},
"commit": {},
},
}},
Steps: []v1.Step{{
Name: "do-the-clone",
Image: "some-git-image",
Args: []string{"$(params.gitrepo.non-exist-key)"},
WorkingDir: "/foo/bar/src/",
}},
},
expectedError: apis.FieldError{
Message: `non-existent variable in "$(params.gitrepo.non-exist-key)"`,
Paths: []string{"steps[0].args[0]"},
},
}, {
name: "Inexistent param variable in volumeMount with existing",
fields: fields{
Expand Down
22 changes: 22 additions & 0 deletions pkg/apis/pipeline/v1beta1/task_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,28 @@ func TestTaskSpecValidateError(t *testing.T) {
Message: `variable type invalid in "$(params.gitrepo[*])"`,
Paths: []string{"steps[0].args[0]"},
},
}, {
name: "non-existent individual key of an object param is used in task step",
fields: fields{
Params: []v1beta1.ParamSpec{{
Name: "gitrepo",
Type: v1beta1.ParamTypeObject,
Properties: map[string]v1beta1.PropertySpec{
"url": {},
"commit": {},
},
}},
Steps: []v1beta1.Step{{
Name: "do-the-clone",
Image: "some-git-image",
Args: []string{"$(params.gitrepo.non-exist-key)"},
WorkingDir: "/foo/bar/src/",
}},
},
expectedError: apis.FieldError{
Message: `non-existent variable in "$(params.gitrepo.non-exist-key)"`,
Paths: []string{"steps[0].args[0]"},
},
}, {
name: "Inexistent param variable in volumeMount with existing",
fields: fields{
Expand Down

0 comments on commit 2704d7f

Please sign in to comment.