test

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

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

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

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

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

type EventMatcher func(have event.Event) error

func AllOf

func AllOf(matchers ...EventMatcher) EventMatcher

AllOf combines matchers together

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 HasNoData

func HasNoData() EventMatcher

HasNoData checks if the event doesn't contain data

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)

func IsInvalid

func IsInvalid() EventMatcher

IsInvalid checks if the event is invalid

func IsValid

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