test

package
v2.0.0-RC1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package test contains test data and generic tests for testing bindings.

Package test provides re-usable functions for binding tests.

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"}}
)
View Source
var UnknownMessage binding.Message = unknownMessage{}

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 AssertEventContextEquals

func AssertEventContextEquals(t *testing.T, want event.EventContext, have event.EventContext)

AssertEventContextEquals asserts that two event.Event contexts are equals

func AssertEventEquals

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

AssertEventEquals asserts that two event.Event are equals

func AssertTransformerInvokedOneTime

func AssertTransformerInvokedOneTime(t *testing.T, m *MockTransformer)

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 ExToStr

func ExToStr(t *testing.T, e event.Event) event.Event

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

func FullEvent

func FullEvent() event.Event

FullEvent has all context attributes set and JSON string data.

func MinEvent

func MinEvent() event.Event

MinEvent has only required attributes set.

func MustCreateMockBinaryMessage

func MustCreateMockBinaryMessage(e event.Event) binding.Message

MustCreateMockBinaryMessage creates a new MockBinaryMessage starting from an event.Event. Panics in case of error

func MustCreateMockStructuredMessage

func MustCreateMockStructuredMessage(e event.Event) binding.Message

MustCreateMockStructuredMessage creates a new MockStructuredMessage starting from an event.Event. Panics in case of error.

func MustJSON

func MustJSON(e event.Event) []byte

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

func MustToEvent

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

MustToEvent converts a Message to event.Event

func NameOf

func NameOf(x interface{}) string

NameOf generates a string test name from x, esp. for ce.Event and ce.Message.

func NoExtensions

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

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

func RunTransformerTests

func RunTransformerTests(t *testing.T, ctx context.Context, tests []TransformerTestArgs)

Types

type MockBinaryMessage

type MockBinaryMessage struct {
	Version    spec.Version
	Metadata   map[spec.Attribute]interface{}
	Extensions map[string]interface{}
	Body       []byte
}

MockBinaryMessage implements a binary-mode message as a simple struct. MockBinaryMessage implements both the binding.Message interface and the binding.BinaryWriter

func (*MockBinaryMessage) End

func (bm *MockBinaryMessage) End(ctx context.Context) error

func (*MockBinaryMessage) Finish

func (bm *MockBinaryMessage) Finish(error) error

func (*MockBinaryMessage) GetAttribute

func (bm *MockBinaryMessage) GetAttribute(k spec.Kind) (spec.Attribute, interface{})

func (*MockBinaryMessage) GetExtension

func (bm *MockBinaryMessage) GetExtension(name string) interface{}

func (*MockBinaryMessage) ReadBinary

func (bm *MockBinaryMessage) ReadBinary(ctx context.Context, b binding.BinaryWriter) error

func (*MockBinaryMessage) ReadEncoding

func (bm *MockBinaryMessage) ReadEncoding() binding.Encoding

func (*MockBinaryMessage) ReadStructured

func (*MockBinaryMessage) SetAttribute

func (bm *MockBinaryMessage) SetAttribute(attribute spec.Attribute, value interface{}) error

func (*MockBinaryMessage) SetData

func (bm *MockBinaryMessage) SetData(data io.Reader) (err error)

func (*MockBinaryMessage) SetExtension

func (bm *MockBinaryMessage) SetExtension(name string, value interface{}) error

func (*MockBinaryMessage) Start

func (bm *MockBinaryMessage) Start(ctx context.Context) error

type MockStructuredMessage

type MockStructuredMessage struct {
	Format format.Format
	Bytes  []byte
}

MockStructuredMessage implements a structured-mode message as a simple struct. MockStructuredMessage implements both the binding.Message interface and the binding.StructuredWriter

func (*MockStructuredMessage) Finish

func (s *MockStructuredMessage) Finish(error) error

func (*MockStructuredMessage) ReadBinary

func (*MockStructuredMessage) ReadEncoding

func (s *MockStructuredMessage) ReadEncoding() binding.Encoding

func (*MockStructuredMessage) ReadStructured

func (*MockStructuredMessage) SetStructuredEvent

func (s *MockStructuredMessage) SetStructuredEvent(ctx context.Context, format format.Format, event io.Reader) (err error)

type MockTransformer

type MockTransformer struct {
	Invoked int
}

type TransformerTestArgs

type TransformerTestArgs struct {
	Name         string
	InputEvent   event.Event
	InputMessage binding.Message
	WantEvent    event.Event
	AssertFunc   func(t *testing.T, event event.Event)
	Transformers []binding.Transformer
}

Jump to

Keyboard shortcuts

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