Skip to content

Commit

Permalink
Add validation check for triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
savitaashture authored and tekton-robot committed May 4, 2021
1 parent a23ac4f commit 4f77406
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/triggers/v1alpha1/event_listener_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ func (t *EventListenerTrigger) validate(ctx context.Context) (errs *apis.FieldEr
errs = errs.Also(apis.ErrMissingOneOf("template", "triggerRef"))
}

if t.TriggerRef != "" && (t.Template != nil || t.Bindings != nil || t.Interceptors != nil) {
errs = errs.Also(apis.ErrMultipleOneOf("triggerRef", "template or bindings or interceptors"))
}

// Validate optional Bindings
errs = errs.Also(triggerSpecBindingArray(t.Bindings).validate(ctx))
if t.Template != nil {
Expand Down
26 changes: 21 additions & 5 deletions pkg/apis/triggers/v1alpha1/event_listener_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,6 @@ func Test_EventListenerValidate(t *testing.T) {
},
Spec: v1alpha1.EventListenerSpec{
Triggers: []v1alpha1.EventListenerTrigger{{
Bindings: []*v1alpha1.EventListenerBinding{{
Ref: "tb",
Kind: "TriggerBinding",
APIVersion: "v1alpha1",
}},
TriggerRef: "triggerref",
}},
Resources: v1alpha1.Resources{
Expand Down Expand Up @@ -737,6 +732,27 @@ func TestEventListenerValidate_error(t *testing.T) {
},
},
},
}, {
name: "Specify TriggerTemplate along with TriggerRef",
el: &v1alpha1.EventListener{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
},
Spec: v1alpha1.EventListenerSpec{
Triggers: []v1alpha1.EventListenerTrigger{{
Template: &v1alpha1.EventListenerTemplate{
Ref: ptr.String("tt"),
},
TriggerRef: "triggerref",
}},
Resources: v1alpha1.Resources{
CustomResource: &v1alpha1.CustomResource{
RawExtension: getValidRawData(t),
},
},
},
},
}}

for _, test := range tests {
Expand Down

0 comments on commit 4f77406

Please sign in to comment.