test

package
v1.2.1-RC.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: Apache-2.0 Imports: 20 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"}}
)

Functions

func AllVersions

func AllVersions(events []ce.Event) []ce.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 cloudevents.EventContext, have cloudevents.EventContext)

func AssertEventEquals

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

func BenchmarkSendReceive

func BenchmarkSendReceive(b *testing.B, s binding.Sender, r binding.Receiver)

Simple send/receive benchmark. Requires a sender and receiver that are connected to each other.

func Canonical

func Canonical(t *testing.T, c ce.EventContext)

Canonical converts all attributes to canonical string form for comparisons.

func CopyEventContext

func CopyEventContext(e ce.Event) ce.Event

func EachEvent

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

Run 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))

Run f as a test for each message in messages

func Events

func Events() []ce.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 ce.Event) ce.Event

func FullEvent

func FullEvent() ce.Event

FullEvent has all context attributes set and JSON string data.

func MinEvent

func MinEvent() ce.Event

MinEvent has only required attributes set.

func MustJSON

func MustJSON(e ce.Event) []byte

func MustToEvent

func MustToEvent(ctx context.Context, m binding.Message) (e ce.Event, encoding binding.Encoding)

func NameOf

func NameOf(x interface{}) string

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

func NewMockBinaryMessage

func NewMockBinaryMessage(e cloudevents.Event) binding.Message

func NewMockStructuredMessage

func NewMockStructuredMessage(e cloudevents.Event) binding.Message

func NoExtensions

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

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

func RunTranscoderTests

func RunTranscoderTests(t *testing.T, ctx context.Context, tests []TranscoderTestArgs)

func SendReceive

func SendReceive(t *testing.T, ctx context.Context, in binding.Message, s binding.Sender, r binding.Receiver, outAssert func(binding.Message))

SendReceive does, s.Send(in) and returns r.Receive(). Halt test on error.

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.

func (*MockBinaryMessage) Binary

func (*MockBinaryMessage) Encoding

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

func (*MockBinaryMessage) End

func (bm *MockBinaryMessage) End() error

func (*MockBinaryMessage) Finish

func (bm *MockBinaryMessage) Finish(error) error

func (*MockBinaryMessage) GetParent

func (bm *MockBinaryMessage) GetParent() binding.Message

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

func (*MockBinaryMessage) Structured

type MockStructuredMessage

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

MockStructuredMessage implements a structured-mode message as a simple struct.

func (*MockStructuredMessage) Binary

func (*MockStructuredMessage) Encoding

func (bm *MockStructuredMessage) Encoding() binding.Encoding

func (*MockStructuredMessage) Finish

func (s *MockStructuredMessage) Finish(error) error

func (*MockStructuredMessage) SetStructuredEvent

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

func (*MockStructuredMessage) Structured

type TranscoderTestArgs

type TranscoderTestArgs struct {
	Name         string
	InputMessage binding.Message
	WantEvent    cloudevents.Event
	Transformers []binding.TransformerFactory
}

Jump to

Keyboard shortcuts

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