Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation check for triggers #1072

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -260,11 +260,6 @@ func Test_EventListenerValidate(t *testing.T) {
},
Spec: v1alpha1.EventListenerSpec{
Triggers: []v1alpha1.EventListenerTrigger{{
Bindings: []*v1alpha1.EventListenerBinding{{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this removal intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes because
at a time user can specify either triggerRef or triggerTemplate, triggerBinding, interceptors

So removed bindings because there is triggerRef

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh so this was a bad test. Got it! Thanks!

Ref: "tb",
Kind: "TriggerBinding",
APIVersion: "v1alpha1",
}},
TriggerRef: "triggerref",
}},
Resources: v1alpha1.Resources{
Expand Down Expand Up @@ -699,6 +694,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{
savitaashture marked this conversation as resolved.
Show resolved Hide resolved
CustomResource: &v1alpha1.CustomResource{
RawExtension: getValidRawData(t),
},
},
},
},
}}

for _, test := range tests {
Expand Down