Documentation ¶
Overview ¶
Package test has utilities (asserts, mocks, ...) to use cloudevents in your tests
Package test contains test data and generic tests for testing bindings.
Index ¶
- Variables
- func AllVersions(events []event.Event) []event.Event
- func AssertEvent(t testing.TB, have event.Event, matchers ...EventMatcher)
- func AssertEventContextEquals(t testing.TB, want event.EventContext, have event.EventContext)
- func AssertEventEquals(t testing.TB, want event.Event, have event.Event)
- func ConvertEventExtensionsToString(t testing.TB, e event.Event) event.Event
- func EachEvent(t *testing.T, events []event.Event, f func(*testing.T, event.Event))
- func EachMessage(t *testing.T, messages []binding.Message, f func(*testing.T, binding.Message))
- func Events() []event.Event
- func FullEvent() event.Event
- func FullMessage() binding.Message
- func MinEvent() event.Event
- func MinMessage() binding.Message
- func MustJSON(t testing.TB, e event.Event) []byte
- func MustToEvent(t testing.TB, ctx context.Context, m binding.Message) event.Event
- func TestNameOf(x interface{}) string
- func WithoutExtensions(events []event.Event) []event.Event
- type EventMatcher
- func AllOf(matchers ...EventMatcher) EventMatcher
- func AnyOf(matchers ...EventMatcher) EventMatcher
- func ContainsAttributes(attrs ...spec.Kind) EventMatcher
- func ContainsExactlyExtensions(exts ...string) EventMatcher
- func ContainsExtensions(exts ...string) EventMatcher
- func DataContains(expectedContainedString string) EventMatcher
- func HasAttributeKind(kind spec.Kind, value interface{}) EventMatcher
- func HasData(want []byte) EventMatcher
- func HasDataContentType(dataContentType string) EventMatcher
- func HasDataSchema(schema string) EventMatcher
- func HasExactlyAttributesEqualTo(want event.EventContext) EventMatcher
- func HasExactlyExtensions(ext map[string]interface{}) EventMatcher
- func HasExtension(key string, value interface{}) EventMatcher
- func HasExtensions(ext map[string]interface{}) EventMatcher
- func HasId(id string) EventMatcher
- func HasNoData() EventMatcher
- func HasSource(source string) EventMatcher
- func HasSpecVersion(specVersion string) EventMatcher
- func HasSubject(subject string) EventMatcher
- func HasTime(t time.Time) EventMatcher
- func HasType(ty string) EventMatcher
- func IsContextEqualTo(want event.EventContext) EventMatcher
- func IsDataEqualTo(want event.Event) EventMatcher
- func IsEqualTo(want event.Event) EventMatcher
- func IsInvalid() EventMatcher
- func IsValid() EventMatcher
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func AllVersions ¶
AllVersions returns all versions of each event in events. ID gets a -number suffix so IDs are unique.
func AssertEvent ¶
func AssertEvent(t testing.TB, have event.Event, matchers ...EventMatcher)
AssertEvent is a "matcher like" assertion method to test the properties of an event
func AssertEventContextEquals ¶
func AssertEventContextEquals(t testing.TB, want event.EventContext, have event.EventContext)
AssertEventContextEquals asserts that two event.Event contexts are equals
func AssertEventEquals ¶
AssertEventEquals asserts that two event.Event are equals
func ConvertEventExtensionsToString ¶
ConvertEventExtensionsToString returns a copy of the event.Event where all extensions are converted to strings. Fails the test if conversion fails
func EachMessage ¶
EachMessage runs f as a test for each message in messages
func Events ¶
Events is a set of test events that should be handled correctly by all event-processing code.
func FullMessage ¶
FullMessage returns the same event of FullEvent but wrapped as Message.
func MinMessage ¶
MinMessage returns the same event of MinEvent but wrapped as Message.
func MustToEvent ¶
MustToEvent converts a Message to event.Event
func TestNameOf ¶
func TestNameOf(x interface{}) string
TestNameOf generates a string test name from x, esp. for ce.Event and ce.Message.
Types ¶
type EventMatcher ¶
func AnyOf ¶
func AnyOf(matchers ...EventMatcher) EventMatcher
AnyOf returns a matcher which match if at least one of the provided matchers matches
func ContainsAttributes ¶
func ContainsAttributes(attrs ...spec.Kind) EventMatcher
ContainsAttributes checks if the event contains at least the provided context attributes
func ContainsExactlyExtensions ¶
func ContainsExactlyExtensions(exts ...string) EventMatcher
ContainsExactlyExtensions checks if the event contains only the provided extension names and no more
func ContainsExtensions ¶
func ContainsExtensions(exts ...string) EventMatcher
ContainsExtensions checks if the event contains at least the provided extension names
func DataContains ¶
func DataContains(expectedContainedString string) EventMatcher
DataContains matches that the data field of the event, converted to a string, contains the provided string
func HasAttributeKind ¶
func HasAttributeKind(kind spec.Kind, value interface{}) EventMatcher
func HasData ¶
func HasData(want []byte) EventMatcher
HasData checks if the event contains the provided data
func HasDataContentType ¶
func HasDataContentType(dataContentType string) EventMatcher
func HasDataSchema ¶
func HasDataSchema(schema string) EventMatcher
func HasExactlyAttributesEqualTo ¶
func HasExactlyAttributesEqualTo(want event.EventContext) EventMatcher
HasExactlyAttributesEqualTo checks if the event has exactly the provided spec attributes (excluding extension attributes)
func HasExactlyExtensions ¶
func HasExactlyExtensions(ext map[string]interface{}) EventMatcher
HasExactlyExtensions checks if the event contains exactly the provided extensions
func HasExtension ¶
func HasExtension(key string, value interface{}) EventMatcher
HasExtension checks if the event contains the provided extension
func HasExtensions ¶
func HasExtensions(ext map[string]interface{}) EventMatcher
HasExtensions checks if the event contains at least the provided extensions
func HasId ¶
func HasId(id string) EventMatcher
func HasSource ¶
func HasSource(source string) EventMatcher
func HasSpecVersion ¶
func HasSpecVersion(specVersion string) EventMatcher
func HasSubject ¶
func HasSubject(subject string) EventMatcher
func HasTime ¶
func HasTime(t time.Time) EventMatcher
func HasType ¶
func HasType(ty string) EventMatcher
func IsContextEqualTo ¶
func IsContextEqualTo(want event.EventContext) EventMatcher
IsContextEqualTo performs a semantic equality check of the event context, including extension attributes (like AssertEventContextEquals)
func IsDataEqualTo ¶
func IsDataEqualTo(want event.Event) EventMatcher
IsDataEqualTo checks if the data field matches with want
func IsEqualTo ¶
func IsEqualTo(want event.Event) EventMatcher
IsEqualTo performs a semantic equality check of the event (like AssertEventEquals)