Skip to content

Commit

Permalink
Validate run for both ref and spec as nil.
Browse files Browse the repository at this point in the history
Previously we had the check for an empty RunSpec but a RunSpec
could be missing both Ref and Spec and yet contain some other
field. This validation check was missing.
  • Loading branch information
ScrapCodes authored and tekton-robot committed May 26, 2021
1 parent f911d73 commit 2d05c9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1alpha1/run_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func (rs *RunSpec) Validate(ctx context.Context) *apis.FieldError {
if rs.Ref != nil && rs.Spec != nil {
return apis.ErrMultipleOneOf("spec.ref", "spec.spec")
}
if rs.Ref == nil && rs.Spec == nil {
return apis.ErrMissingOneOf("spec.ref", "spec.spec")
}
if rs.Ref != nil {
if rs.Ref.APIVersion == "" {
return apis.ErrMissingField("spec.ref.apiVersion")
Expand Down
16 changes: 13 additions & 3 deletions pkg/apis/pipeline/v1alpha1/run_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,26 @@ func TestRun_Invalid(t *testing.T) {
want: apis.ErrMissingField("spec"),
}, {
name: "Empty spec",
run: &v1alpha1.Run{
ObjectMeta: metav1.ObjectMeta{
Name: "temp",
},
Spec: v1alpha1.RunSpec{},
},
want: apis.ErrMissingField("spec"),
}, {
name: "Both spec and ref missing",
run: &v1alpha1.Run{
ObjectMeta: metav1.ObjectMeta{
Name: "temp",
},
Spec: v1alpha1.RunSpec{
Ref: nil,
Spec: nil,
Ref: nil,
Spec: nil,
ServiceAccountName: "test-sa",
},
},
want: apis.ErrMissingField("spec"),
want: apis.ErrMissingOneOf("spec.ref", "spec.spec"),
}, {
name: "Both Ref and Spec",
run: &v1alpha1.Run{
Expand Down

0 comments on commit 2d05c9b

Please sign in to comment.