gizmo: github.com/NYTimes/gizmo/pubsub/pubsubtest Index | Files

package pubsubtest

import "github.com/NYTimes/gizmo/pubsub/pubsubtest"

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

Index

Package Files

doc.go pub.go sub.go

type TestPublishMsg Uses

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 Uses

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 Uses

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

Publish publishes the message, delegating to PublishRaw.

func (*TestPublisher) PublishMulti Uses

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

PublishMulti publishes the messages, delegating to Publish.

func (*TestPublisher) PublishMultiRaw Uses

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 Uses

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

PublishRaw publishes the raw message byte slice.

type TestSubsMessage Uses

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

TestSubsMessage represents a test subscriber message.

func (*TestSubsMessage) Done Uses

func (m *TestSubsMessage) Done() error

Done sets the Doned field to true.

func (*TestSubsMessage) ExtendDoneDeadline Uses

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

ExtendDoneDeadline changes the underlying DoneTimeout

func (*TestSubsMessage) Message Uses

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

Message returns the subscriber message.

type TestSubscriber Uses

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 Uses

func (t *TestSubscriber) Err() error

Err returns the GivenErrError value.

func (*TestSubscriber) Start Uses

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

Start will populate and return the test channel for the subscriber

func (*TestSubscriber) Stop Uses

func (t *TestSubscriber) Stop() error

Stop returns the GivenStopError value.

Package pubsubtest imports 7 packages (graph). Updated 2019-03-05. Refresh now. Tools for package owners.