mqtttest

package
v0.0.0-...-b33ea04 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2021 License: CC0-1.0 Imports: 6 Imported by: 0

Documentation

Overview

Package mqtttest provides utilities for MQTT testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPublishExchangeStub

func NewPublishExchangeStub(errFix error, exchangeFix ...error) func(message []byte, topic string) (exchange <-chan error, err error)

NewPublishExchangeStub returns a stub for mqtt.Client PublishAtLeastOnce or PublishExactlyOnce with a fixed return value.

The exchangeFix errors are applied to the exchange return, with an option for ExchangeBlock entries. An mqtt.ErrClosed in the exchangeFix keeps the exchange channel open (without an extra ExchangeBlock entry).

func NewPublishMock

func NewPublishMock(t testing.TB, want ...Transfer) func(quit <-chan struct{}, message []byte, topic string) error

NewPublishMock returns a new mock for mqtt.Client Publish, which compares the invocation with want in order of appearance.

func NewPublishStub

func NewPublishStub(fix error) func(quit <-chan struct{}, message []byte, topic string) error

NewPublishStub returns a new stub for mqtt.Client Publish with a fixed return value.

func NewReadSlicesMock

func NewReadSlicesMock(t testing.TB, want ...Transfer) func() (message, topic []byte, err error)

NewReadSlicesMock returns a new mock for mqtt.Client ReadSlices, which returns the Transfers in order of appearance.

func NewReadSlicesStub

func NewReadSlicesStub(fix Transfer) func() (message, topic []byte, err error)

NewReadSlicesStub returns a new stub for mqtt.Client ReadSlices with a fixed return value.

func NewSubscribeMock

func NewSubscribeMock(t testing.TB, want ...Filter) func(quit <-chan struct{}, topicFilters ...string) error

NewSubscribeMock returns a new mock for mqtt.Client Subscribe, which compares the invocation with want in order of appearece.

func NewSubscribeStub

func NewSubscribeStub(fix error) func(quit <-chan struct{}, topicFilters ...string) error

NewSubscribeStub returns a stub for mqtt.Client Subscribe with a fixed return value.

func NewUnsubscribeMock

func NewUnsubscribeMock(t testing.TB, want ...Filter) func(quit <-chan struct{}, topicFilters ...string) error

NewUnsubscribeMock returns a new mock for mqtt.Client Unsubscribe, which compares the invocation with want in order of appearece.

func NewUnsubscribeStub

func NewUnsubscribeStub(fix error) func(quit <-chan struct{}, topicFilters ...string) error

NewUnsubscribeStub returns a stub for mqtt.Client Unsubscribe with a fixed return value.

Types

type ExchangeBlock

type ExchangeBlock struct {
	Delay time.Duration // zero defaults to indefinite
}

ExchangeBlock prevents exchange <-chan error submission.

func (ExchangeBlock) Error

func (b ExchangeBlock) Error() string

Error implements the standard error interface.

type Filter

type Filter struct {
	Topics []string // order is ignored
	Err    error    // result
}

Filter defines a subscription exchange.

type Transfer

type Transfer struct {
	Message []byte // payload
	Topic   string // destination
	Err     error  // result
}

Transfer defines a message exchange.

Jump to

Keyboard shortcuts

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