test

package
v2.15.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2024 License: Apache-2.0 Imports: 16 Imported by: 36

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

Constants

This section is empty.

Variables

View Source
var (
	Source    = types.URIRef{URL: url.URL{Scheme: "http", Host: "example.com", Path: "/source"}}
	Timestamp = types.Timestamp{Time: time.Date(2020, 03, 21, 12, 34, 56, 780000000, time.UTC)}
	Schema    = types.URI{URL: url.URL{Scheme: "http", Host: "example.com", Path: "/schema"}}
)

Functions

func AllVersions

func AllVersions(events []event.Event) []event.Event

AllVersions returns all versions of each event in events. ID gets a -number suffix so IDs are unique.

func AssertEvent added in v2.1.0

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

func AssertEventEquals(t testing.TB, want event.Event, have event.Event)

AssertEventEquals asserts that two event.Event are equals

func ConvertEventExtensionsToString

func ConvertEventExtensionsToString(t testing.TB, e event.Event) event.Event

ConvertEventExtensionsToString returns a copy of the event.Event where all extensions are converted to strings. Fails the test if conversion fails

func EachEvent

func EachEvent(t *testing.T, events []event.Event, f func(*testing.T, event.Event))

EachEvent runs f as a test for each event in events

func EachMessage

func EachMessage(t *testing.T, messages []binding.Message, f func(*testing.T, binding.Message))

EachMessage runs f as a test for each message in messages

func Events

func Events() []event.Event

Events is a set of test events that should be handled correctly by all event-processing code.

func FullEvent

func FullEvent() event.Event

FullEvent has all context attributes set and JSON string data.

func FullMessage added in v2.2.0

func FullMessage() binding.Message

FullMessage returns the same event of FullEvent but wrapped as Message.

func MinEvent

func MinEvent() event.Event

MinEvent has only required attributes set.

func MinMessage added in v2.2.0

func MinMessage() binding.Message

MinMessage returns the same event of MinEvent but wrapped as Message.

func MustJSON

func MustJSON(t testing.TB, e event.Event) []byte

MustJSON marshals the event.Event to JSON structured representation or panics

func MustToEvent

func MustToEvent(t testing.TB, ctx context.Context, m binding.Message) event.Event

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.

func WithoutExtensions

func WithoutExtensions(events []event.Event) []event.Event

WithoutExtensions returns a copy of events with no Extensions. Use for testing where extensions are not supported.

Types

type EventMatcher added in v2.1.0

type EventMatcher func(have event.Event) error

func AllOf added in v2.1.0

func AllOf(matchers ...EventMatcher) EventMatcher

AllOf combines matchers together

func AnyOf added in v2.1.0

func AnyOf(matchers ...EventMatcher) EventMatcher

AnyOf returns a matcher which match if at least one of the provided matchers matches

func ContainsAttributes added in v2.1.0

func ContainsAttributes(attrs ...spec.Kind) EventMatcher

ContainsAttributes checks if the event contains at least the provided context attributes

func ContainsExactlyExtensions added in v2.1.0

func ContainsExactlyExtensions(exts ...string) EventMatcher

ContainsExactlyExtensions checks if the event contains only the provided extension names and no more

func ContainsExtensions added in v2.1.0

func ContainsExtensions(exts ...string) EventMatcher

ContainsExtensions checks if the event contains at least the provided extension names

func DataContains added in v2.1.0

func DataContains(expectedContainedString string) EventMatcher

DataContains matches that the data field of the event, converted to a string, contains the provided string

func HasAttributeKind added in v2.1.0

func HasAttributeKind(kind spec.Kind, value interface{}) EventMatcher

func HasData added in v2.1.0

func HasData(want []byte) EventMatcher

HasData checks if the event contains the provided data

func HasDataContentType added in v2.1.0

func HasDataContentType(dataContentType string) EventMatcher

func HasDataSchema added in v2.1.0

func HasDataSchema(schema string) EventMatcher

func HasExactlyAttributesEqualTo added in v2.1.0

func HasExactlyAttributesEqualTo(want event.EventContext) EventMatcher

HasExactlyAttributesEqualTo checks if the event has exactly the provided spec attributes (excluding extension attributes)

func HasExactlyExtensions added in v2.1.0

func HasExactlyExtensions(ext map[string]interface{}) EventMatcher

HasExactlyExtensions checks if the event contains exactly the provided extensions

func HasExtension added in v2.1.0

func HasExtension(key string, value interface{}) EventMatcher

HasExtension checks if the event contains the provided extension

func HasExtensionKeys added in v2.15.0

func HasExtensionKeys(keys []string) EventMatcher

HasExtensionKeys checks if the event contains the provided keys from its extensions

func HasExtensions added in v2.1.0

func HasExtensions(ext map[string]interface{}) EventMatcher

HasExtensions checks if the event contains at least the provided extensions

func HasId added in v2.1.0

func HasId(id string) EventMatcher

func HasNoData added in v2.1.0

func HasNoData() EventMatcher

HasNoData checks if the event doesn't contain data

func HasSource added in v2.1.0

func HasSource(source string) EventMatcher

func HasSpecVersion added in v2.1.0

func HasSpecVersion(specVersion string) EventMatcher

func HasSubject added in v2.1.0

func HasSubject(subject string) EventMatcher

func HasTime added in v2.1.0

func HasTime(t time.Time) EventMatcher

func HasType added in v2.1.0

func HasType(ty string) EventMatcher

func IsContextEqualTo added in v2.1.0

func IsContextEqualTo(want event.EventContext) EventMatcher

IsContextEqualTo performs a semantic equality check of the event context, including extension attributes (like AssertEventContextEquals)

func IsDataEqualTo added in v2.1.0

func IsDataEqualTo(want event.Event) EventMatcher

IsDataEqualTo checks if the data field matches with want

func IsEqualTo added in v2.1.0

func IsEqualTo(want event.Event) EventMatcher

IsEqualTo performs a semantic equality check of the event (like AssertEventEquals)

func IsInvalid added in v2.1.0

func IsInvalid() EventMatcher

IsInvalid checks if the event is invalid

func IsValid added in v2.1.0

func IsValid() EventMatcher

IsValid checks if the event is valid

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL