Skip to content
Open
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
10 changes: 8 additions & 2 deletions pkg/apis/eventing/v1beta1/eventtype_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ func (ets *EventTypeSpec) Validate(ctx context.Context) *apis.FieldError {
fe := apis.ErrMissingField("type")
errs = errs.Also(fe)
}
// TODO validate Source is a valid URI.
// TODO validate Schema is a valid URI.
// Validate Source is a non-empty URI when provided
if ets.Source != nil && ets.Source.IsEmpty() {
errs = errs.Also(apis.ErrInvalidValue("", "source", "source URI cannot be empty"))
Copy link
Member

Choose a reason for hiding this comment

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

ets.Source could be nil, while this error would not be set. As IsEmpty() seems also to be nil safe, you could also use ets.Source.IsEmpty() directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey thanks @creydr ! I tried removing the nil check but the existing tests started failing. IsEmpty() returns true for nil, so it was treating "not provided" the same as "provided but empty". I think we only want to error on the second case since the fields are optional. Let me know if I'm missing something though!

}
// Validate Schema is a non-empty URI when provided
if ets.Schema != nil && ets.Schema.IsEmpty() {
errs = errs.Also(apis.ErrInvalidValue("", "schema", "schema URI cannot be empty"))
Copy link
Member

Choose a reason for hiding this comment

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

same as with etc.Source & nil

}
// There is no validation of the SchemaData, it is application specific data.
return errs
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/apis/eventing/v1beta1/eventtype_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ func TestEventTypeSpecValidation(t *testing.T) {
Source: testSource,
Broker: "test-broker",
},
}, {
name: "invalid empty source",
ets: &EventTypeSpec{
Type: "test-type",
Source: &apis.URL{},
Broker: "test-broker",
},
want: apis.ErrInvalidValue("", "source", "source URI cannot be empty"),
}, {
name: "invalid empty schema",
ets: &EventTypeSpec{
Type: "test-type",
Source: testSource,
Schema: &apis.URL{},
Broker: "test-broker",
},
want: apis.ErrInvalidValue("", "schema", "schema URI cannot be empty"),
},
}

Expand Down