pubsubtest

package
Version: v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package pubsubtest provides a publisher and a subscriber intended for use in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TestPublishMsg

type TestPublishMsg struct {
	// Key represents the message key.
	Key string
	// Body represents the message body.
	Body []byte
}

TestPublishMsg is a test publish message.

type TestPublisher

type TestPublisher struct {
	// Published will contain a list of all messages that have been published.
	Published []TestPublishMsg

	// GivenError will be returned by the TestPublisher on publish.
	// Good for testing error scenarios.
	GivenError error

	// FoundError will contain any errors encountered while marshalling
	// the protobuf struct.
	FoundError error
	// contains filtered or unexported fields
}

TestPublisher is a simple implementation of pubsub.Publisher meant to help mock out any implementations.

func (*TestPublisher) Publish

func (t *TestPublisher) Publish(ctx context.Context, key string, msg proto.Message) error

Publish publishes the message, delegating to PublishRaw.

func (*TestPublisher) PublishMulti

func (t *TestPublisher) PublishMulti(ctx context.Context, keys []string, messages []proto.Message) error

PublishMulti publishes the messages, delegating to Publish.

func (*TestPublisher) PublishMultiRaw

func (t *TestPublisher) PublishMultiRaw(ctx context.Context, keys []string, messages [][]byte) error

PublishMultiRaw will publish multiple raw byte array messages with a context.

func (*TestPublisher) PublishRaw

func (t *TestPublisher) PublishRaw(_ context.Context, key string, msg []byte) error

PublishRaw publishes the raw message byte slice.

type TestSubsMessage

type TestSubsMessage struct {
	Msg         []byte
	DoneTimeout time.Duration
	Doned       bool
}

TestSubsMessage represents a test subscriber message.

func (*TestSubsMessage) Done

func (m *TestSubsMessage) Done() error

Done sets the Doned field to true.

func (*TestSubsMessage) ExtendDoneDeadline

func (m *TestSubsMessage) ExtendDoneDeadline(d time.Duration) error

ExtendDoneDeadline changes the underlying DoneTimeout

func (*TestSubsMessage) Message

func (m *TestSubsMessage) Message() []byte

Message returns the subscriber message.

type TestSubscriber

type TestSubscriber struct {
	// ProtoMessages will be marshalled into []byte and used to mock out
	// a feed if it is populated.
	ProtoMessages []proto.Message

	// JSONMessages will be marshalled into []byte and used to mock out
	// a feed if it is populated.
	JSONMessages []interface{}

	// GivenErrError will be returned by the TestSubscriber on Err().
	// Good for testing error scenarios.
	GivenErrError error

	// GivenStopError will be returned by the TestSubscriber on Stop().
	// Good for testing error scenarios.
	GivenStopError error

	// FoundError will contain any errors encountered while marshalling
	// the JSON and protobuf struct.
	FoundError error
}

TestSubscriber is a simple implementation of pubsub.Subscriber meant to help mock out any implementations.

func (*TestSubscriber) Err

func (t *TestSubscriber) Err() error

Err returns the GivenErrError value.

func (*TestSubscriber) Start

func (t *TestSubscriber) Start() <-chan pubsub.SubscriberMessage

Start will populate and return the test channel for the subscriber

func (*TestSubscriber) Stop

func (t *TestSubscriber) Stop() error

Stop returns the GivenStopError value.

Source Files

Jump to

Keyboard shortcuts

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