Documentation ¶
Overview ¶
Package test contains test data and generic tests for testing bindings.
Package test provides re-usable functions for binding tests.
Index ¶
- Variables
- func AllVersions(events []event.Event) []event.Event
- func AssertEventContextEquals(t *testing.T, want event.EventContext, have event.EventContext)
- func AssertEventEquals(t *testing.T, want event.Event, have event.Event)
- func AssertTransformerInvokedOneTime(t *testing.T, m *MockTransformerFactory)
- 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 ExToStr(t *testing.T, e event.Event) event.Event
- func FullEvent() event.Event
- func MinEvent() event.Event
- func MustCreateMockBinaryMessage(e event.Event) binding.Message
- func MustCreateMockStructuredMessage(e event.Event) binding.Message
- func MustJSON(e event.Event) []byte
- func MustToEvent(t *testing.T, ctx context.Context, m binding.Message) event.Event
- func NameOf(x interface{}) string
- func NoExtensions(events []event.Event) []event.Event
- func RunTransformerTests(t *testing.T, ctx context.Context, tests []TransformerTestArgs)
- type MockBinaryMessage
- func (bm *MockBinaryMessage) End(ctx context.Context) error
- func (bm *MockBinaryMessage) Finish(error) error
- func (bm *MockBinaryMessage) ReadBinary(ctx context.Context, b binding.BinaryWriter) error
- func (bm *MockBinaryMessage) ReadEncoding() binding.Encoding
- func (bm *MockBinaryMessage) ReadStructured(context.Context, binding.StructuredWriter) error
- func (bm *MockBinaryMessage) SetAttribute(attribute spec.Attribute, value interface{}) error
- func (bm *MockBinaryMessage) SetData(data io.Reader) (err error)
- func (bm *MockBinaryMessage) SetExtension(name string, value interface{}) error
- func (bm *MockBinaryMessage) Start(ctx context.Context) error
- type MockStructuredMessage
- func (s *MockStructuredMessage) Finish(error) error
- func (s *MockStructuredMessage) ReadBinary(context.Context, binding.BinaryWriter) error
- func (bm *MockStructuredMessage) ReadEncoding() binding.Encoding
- func (s *MockStructuredMessage) ReadStructured(ctx context.Context, b binding.StructuredWriter) error
- func (s *MockStructuredMessage) SetStructuredEvent(ctx context.Context, format format.Format, event io.Reader) (err error)
- type MockTransformerFactory
- func (m *MockTransformerFactory) BinaryTransformer(encoder binding.BinaryWriter) binding.BinaryWriter
- func (m *MockTransformerFactory) End(ctx context.Context) error
- func (m *MockTransformerFactory) EventTransformer() binding.EventTransformer
- func (m *MockTransformerFactory) SetAttribute(attribute spec.Attribute, value interface{}) error
- func (m *MockTransformerFactory) SetData(data io.Reader) error
- func (m *MockTransformerFactory) SetExtension(name string, value interface{}) error
- func (m *MockTransformerFactory) SetStructuredEvent(ctx context.Context, format format.Format, event io.Reader) error
- func (m *MockTransformerFactory) Start(ctx context.Context) error
- func (m *MockTransformerFactory) StructuredTransformer(encoder binding.StructuredWriter) binding.StructuredWriter
- type TransformerTestArgs
Constants ¶
This section is empty.
Variables ¶
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"}} )
var UnknownMessage binding.Message = unknownMessage{}
Functions ¶
func AllVersions ¶
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)
Assert two event.Event context are equals
func AssertEventEquals ¶
Assert two event.Event are equals
func AssertTransformerInvokedOneTime ¶
func AssertTransformerInvokedOneTime(t *testing.T, m *MockTransformerFactory)
func EachMessage ¶
Run 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 ExToStr ¶
Returns a copy of the event.Event where all extensions are converted to strings. Fails the test if conversion fails
func MustCreateMockBinaryMessage ¶
Create a new MockBinaryMessage starting from an event.Event. Panics in case of error
func MustCreateMockStructuredMessage ¶
Create a new MockStructuredMessage starting from an event.Event. Panics in case of error
func MustToEvent ¶
Must convert the 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 ¶
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 { 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) Finish ¶
func (bm *MockBinaryMessage) Finish(error) error
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 (bm *MockBinaryMessage) ReadStructured(context.Context, binding.StructuredWriter) error
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
type MockStructuredMessage ¶
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 (s *MockStructuredMessage) ReadBinary(context.Context, binding.BinaryWriter) error
func (*MockStructuredMessage) ReadEncoding ¶
func (bm *MockStructuredMessage) ReadEncoding() binding.Encoding
func (*MockStructuredMessage) ReadStructured ¶
func (s *MockStructuredMessage) ReadStructured(ctx context.Context, b binding.StructuredWriter) error
func (*MockStructuredMessage) SetStructuredEvent ¶
type MockTransformerFactory ¶
type MockTransformerFactory struct { FailStructured bool FailBinary bool StructuredDelegate binding.StructuredWriter InvokedStructuredFactory int InvokedStructuredTransformer int BinaryDelegate binding.BinaryWriter InvokedBinaryFactory int InvokedBinaryTransformer int InvokedEventFactory int InvokedEventTransformer int }
func NewMockTransformerFactory ¶
func NewMockTransformerFactory(failStructured bool, failBinary bool) *MockTransformerFactory
func (*MockTransformerFactory) BinaryTransformer ¶
func (m *MockTransformerFactory) BinaryTransformer(encoder binding.BinaryWriter) binding.BinaryWriter
func (*MockTransformerFactory) End ¶
func (m *MockTransformerFactory) End(ctx context.Context) error
func (*MockTransformerFactory) EventTransformer ¶
func (m *MockTransformerFactory) EventTransformer() binding.EventTransformer
func (*MockTransformerFactory) SetAttribute ¶
func (m *MockTransformerFactory) SetAttribute(attribute spec.Attribute, value interface{}) error
func (*MockTransformerFactory) SetData ¶
func (m *MockTransformerFactory) SetData(data io.Reader) error
func (*MockTransformerFactory) SetExtension ¶
func (m *MockTransformerFactory) SetExtension(name string, value interface{}) error
func (*MockTransformerFactory) SetStructuredEvent ¶
func (*MockTransformerFactory) Start ¶
func (m *MockTransformerFactory) Start(ctx context.Context) error
func (*MockTransformerFactory) StructuredTransformer ¶
func (m *MockTransformerFactory) StructuredTransformer(encoder binding.StructuredWriter) binding.StructuredWriter