test

package
Version: v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDummyMessage

func NewDummyMessage(topic string, payload []byte) mqtt.Message

Types

type Publishment

type Publishment struct {
	Topic    string
	Qos      byte
	Retained bool
	Payload  interface{}
}

type Subscription

type Subscription struct {
	SubscriptionBase

	Matcher  *regexp.Regexp
	Callback mqtt.MessageHandler
}

type SubscriptionBase

type SubscriptionBase struct {
	Topic string
	Qos   byte
}

type TestClient

type TestClient struct {
	Publishments  []Publishment
	Subscriptions []Subscription
	// contains filtered or unexported fields
}

func NewTestClient

func NewTestClient() TestClient

func (*TestClient) AddRoute

func (t *TestClient) AddRoute(_ string, _ mqtt.MessageHandler)

AddRoute allows you to add a handler for messages on a specific topic without making a subscription. For example having a different handler for parts of a wildcard subscription

func (*TestClient) AssertNumPublishments

func (t *TestClient) AssertNumPublishments(testing *testing.T, num int)

func (*TestClient) AssertNumSubscriptions

func (t *TestClient) AssertNumSubscriptions(testing *testing.T, num int)

******

  • Assertions

func (*TestClient) AssertPublishments

func (t *TestClient) AssertPublishments(testing *testing.T, offset int, topic string, qos byte, retained bool, payload interface{})

func (*TestClient) AssertSubscription

func (t *TestClient) AssertSubscription(testing *testing.T, offset int, topic string, qos byte)

func (*TestClient) Connect

func (t *TestClient) Connect() mqtt.Token

Connect will create a connection to the message broker, by default it will attempt to connect at v3.1.1 and auto retry at v3.1 if that fails

func (*TestClient) Disconnect

func (t *TestClient) Disconnect(_ uint)

Disconnect will end the connection with the server, but not before waiting the specified number of milliseconds to wait for existing work to be completed.

func (*TestClient) GetPublishedPayload

func (t *TestClient) GetPublishedPayload(offset int) interface{}

func (*TestClient) IsConnected

func (t *TestClient) IsConnected() bool

IsConnected returns a bool signifying whether the client is connected or not.

func (*TestClient) IsConnectionOpen

func (t *TestClient) IsConnectionOpen() bool

IsConnectionOpen return a bool signifying wether the client has an active connection to mqtt broker, i.e not in disconnected or reconnect mode

func (*TestClient) OptionsReader

func (t *TestClient) OptionsReader() mqtt.ClientOptionsReader

OptionsReader returns a ClientOptionsReader which is a copy of the clientoptions in use by the client.

func (*TestClient) Publish

func (t *TestClient) Publish(topic string, qos byte, retained bool, payload interface{}) mqtt.Token

Publish will publish a message with the specified QoS and content to the specified topic. Returns a token to track delivery of the message to the broker

func (*TestClient) Send

func (t *TestClient) Send(testing *testing.T, topic string, payload interface{})

******

  • Interaction

func (*TestClient) Subscribe

func (t *TestClient) Subscribe(topic string, qos byte, callback mqtt.MessageHandler) mqtt.Token

func (*TestClient) SubscribeMultiple

func (t *TestClient) SubscribeMultiple(_ map[string]byte, _ mqtt.MessageHandler) mqtt.Token

SubscribeMultiple starts a new subscription for multiple topics. Provide a MessageHandler to be executed when a message is published on one of the topics provided, or nil for the default handler

func (*TestClient) Unsubscribe

func (t *TestClient) Unsubscribe(_ ...string) mqtt.Token

Unsubscribe will end the subscription from each of the topics provided. Messages published to those topics from other clients will no longer be received.

Jump to

Keyboard shortcuts

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