From d478674aba8b3513286893ea6416b7ce21e3823b Mon Sep 17 00:00:00 2001 From: Matthias Wessendorf Date: Thu, 19 Sep 2024 13:46:05 +0200 Subject: [PATCH] :lipstick: Enhance tests for v1b3 event type, new attrs Signed-off-by: Matthias Wessendorf --- .../v1beta3/eventtype_validation_test.go | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/pkg/apis/eventing/v1beta3/eventtype_validation_test.go b/pkg/apis/eventing/v1beta3/eventtype_validation_test.go index 1c799403a5a..87f0114064c 100644 --- a/pkg/apis/eventing/v1beta3/eventtype_validation_test.go +++ b/pkg/apis/eventing/v1beta3/eventtype_validation_test.go @@ -50,12 +50,36 @@ func TestEventTypeSpecValidation(t *testing.T) { ets *EventTypeSpec want *apis.FieldError }{{ - name: "invalid eventtype type", + name: "invalid eventtype type, missing type", ets: &EventTypeSpec{}, want: func() *apis.FieldError { fe := apis.ErrMissingField("attributes.id", "attributes.source", "attributes.specversion", "attributes.type") return fe }(), + }, { + name: "partially invalid eventtype type", + ets: &EventTypeSpec{ + Attributes: []EventAttributeDefinition{ + { + Name: "source", + Value: testSource.String(), + Required: true, + }, + { + Name: "specversion", + Value: "v1", + Required: true, + }, + { + Name: "id", + Required: true, + }, + }, + }, + want: func() *apis.FieldError { + fe := apis.ErrMissingField("attributes.type") + return fe + }(), }, { name: "valid eventtype", ets: &EventTypeSpec{ @@ -86,6 +110,46 @@ func TestEventTypeSpecValidation(t *testing.T) { }, }, }, + }, { + name: "valid eventtype with extensions and optional attributes", + ets: &EventTypeSpec{ + Reference: &duckv1.KReference{ + APIVersion: "eventing.knative.dev/v1", + Kind: "Broker", + Name: "test-broker", + }, + Attributes: []EventAttributeDefinition{ + { + Name: "type", + Value: "event-type", + Required: true, + }, + { + Name: "source", + Value: testSource.String(), + Required: true, + }, + { + Name: "specversion", + Value: "v1", + Required: true, + }, + { + Name: "subject", + Value: "foo.png", + Required: false, + }, + { + Name: "customattribute", + Value: "value", + Required: false, + }, + { + Name: "id", + Required: true, + }, + }, + }, }, }