Documentation ¶
Overview ¶
Package mqtttest provides utilities for MQTT testing.
Index ¶
- func NewPublishExchangeStub(errFix error, exchangeFix ...error) func(message []byte, topic string) (exchange <-chan error, err error)
- func NewPublishMock(t testing.TB, want ...Transfer) func(quit <-chan struct{}, message []byte, topic string) error
- func NewPublishStub(fix error) func(quit <-chan struct{}, message []byte, topic string) error
- func NewReadSlicesMock(t testing.TB, want ...Transfer) func() (message, topic []byte, err error)
- func NewReadSlicesStub(fix Transfer) func() (message, topic []byte, err error)
- func NewSubscribeMock(t testing.TB, want ...Filter) func(quit <-chan struct{}, topicFilters ...string) error
- func NewSubscribeStub(fix error) func(quit <-chan struct{}, topicFilters ...string) error
- func NewUnsubscribeMock(t testing.TB, want ...Filter) func(quit <-chan struct{}, topicFilters ...string) error
- func NewUnsubscribeStub(fix error) func(quit <-chan struct{}, topicFilters ...string) error
- type ExchangeBlock
- type Filter
- type Transfer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewPublishExchangeStub ¶ added in v1.0.0
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).
Example ¶
package main import ( "errors" "fmt" "time" "github.com/pascaldekloe/mqtt/mqtttest" ) func main() { PublishExchange := mqtttest.NewPublishExchangeStub(nil, mqtttest.ExchangeBlock{Delay: time.Millisecond}, errors.New("test storage failure"), ) exchange, err := PublishExchange([]byte("Hi!"), "announce") if err != nil { fmt.Println("publish error:", err) return } for err := range exchange { fmt.Println("exchange error:", err) } }
Output: exchange error: test storage failure
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 ¶
NewPublishStub returns a new stub for mqtt.Client Publish with a fixed return value.
func NewReadSlicesMock ¶
NewReadSlicesMock returns a new mock for mqtt.Client ReadSlices, which returns the Transfers in order of appearance.
func NewReadSlicesStub ¶ added in v1.0.0
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 ¶
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 ¶
NewUnsubscribeStub returns a stub for mqtt.Client Unsubscribe with a fixed return value.
Types ¶
type ExchangeBlock ¶
ExchangeBlock prevents exchange <-chan error submission.
func (ExchangeBlock) Error ¶
func (b ExchangeBlock) Error() string
Error implements the standard error interface.