Skip to content

Commit

Permalink
Add tests for all supported attribute fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Moss committed Apr 20, 2021
1 parent 29b72a5 commit bcdec63
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions pkg/eventfilter/attributes/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,41 @@ func attributesWithSubject(t, s, sub string) map[string]string {
"subject": sub,
}
}

func TestAllSupportedAttributeFieldsV1(t *testing.T) {
e := cloudevents.NewEvent(cloudevents.VersionV1)
e.SetType(eventType)
e.SetSource(eventSource)
e.SetID("1234")
e.SetDataSchema("wow")
e.SetSubject("cool")
e.SetDataContentType("cheers;mate")

attributes := map[string]string{
"specversion": e.SpecVersion(),
"type": e.Type(),
"source": e.Source(),
"subject": e.Subject(),
"id": e.ID(),
"time": e.Time().String(),
"dataschema": e.DataSchema(),
"schemaurl": e.DataSchema(),
"datacontenttype": e.DataContentType(),
"datamediatype": e.DataMediaType(),
}
if result := NewAttributesFilter(attributes).Filter(context.TODO(), e); result != eventfilter.PassFilter {
t.Errorf("Expected pass, got %v", result)
}
}

func TestV03Event(t *testing.T) {
e := cloudevents.NewEvent(cloudevents.VersionV03)
e.SetDataContentEncoding("perfect")

attributes := map[string]string{
"datacontentencoding": e.DeprecatedDataContentEncoding(),
}
if result := NewAttributesFilter(attributes).Filter(context.TODO(), e); result != eventfilter.PassFilter {
t.Errorf("Expected pass, got %v", result)
}
}

0 comments on commit bcdec63

Please sign in to comment.