testserver

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: EPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CloseOnPublishReceived     = `CloseOnPublishReceived` // Disconnects when the `PUBLISH` message has been received (before any response)
	CloseOnPubAckReceived      = `CloseOnPubAckReceived`  // Disconnects when the `PUBACK` message has been received (before any response)
	CloseOnPubRecReceived      = `CloseOnPubRecReceived`  // Disconnects when the `PUBREC` message has been received (before any response)
	CloseOnPubRelReceived      = `CloseOnPubRelReceived`  // Disconnects when the `PUBREL` message has been received (before any response)
	CloseOnPubCompReceived     = `CloseOnPubCompReceived` // Disconnects when the `PUBREL` message has been received (before any response)
	AppendAfterActionProcessed = `Done`                   // Appended to message body after action carried out (does not apply to Publish)

)

Message bodies that trigger an action (note that after action completed `Done` will be appended)

Variables

View Source
var ErrorMIDsExhausted = errors.New("all message ids in use")

ErrorMIDsExhausted is returned from Request() when there are no free message ids to be used.

Functions

This section is empty.

Types

type Instance

type Instance struct {
	// contains filtered or unexported fields
}

Instance an instance of the test server Note that many variables are not mutex protected (because they are private and only accessed from one goroutine)

func New

func New(logger Logger) *Instance

New creates a new instance of the simulator

func (*Instance) Connect

func (i *Instance) Connect(ctx context.Context) (net.Conn, chan struct{}, error)

Connect establishes a connection to the test server Note that this can fail! Returns a net.Conn (to pass to paho), a channel that will be closed when connection has shutdown and an error (if any).

func (*Instance) Connected

func (i *Instance) Connected() bool

Connected returns true if the test server has an active connection with the client

func (*Instance) SetConnectCallback

func (i *Instance) SetConnectCallback(callback func(cp *packets.Connect, cap *packets.Connack))

SetConnectCallback sets callback that will be called before the response to a CONNECT packet is sent. The CONNACK packet mak be altered if required. Note: this is not thread safe - call before sending any messages

func (*Instance) SetPacketReceivedCallback

func (i *Instance) SetPacketReceivedCallback(callback func(publish *packets.ControlPacket) error)

SetPacketReceivedCallback sets callback that will be called whenever a packet is received If the callback returns an error the connection will be dropped Note: this is not thread safe - call before sending any messages

type Logger

type Logger interface {
	Println(v ...interface{})
	Printf(format string, v ...interface{})
}

Logger mirrors paho.Logger

type MIDs

type MIDs struct {
	sync.Mutex
	// contains filtered or unexported fields
}

MIDs is a simple service to provide message IDs (mostly copied from paho)

func (*MIDs) Allocate

func (m *MIDs) Allocate(i uint16)

Allocate sets a specific MID (for testing only; MID must be free!)

func (*MIDs) Clear

func (m *MIDs) Clear()

Clear resets all MIDs to unused Note: Does not reset lastMid because retaining a sequence can make debugging easier

func (*MIDs) Free

func (m *MIDs) Free(i uint16)

Free releases a MID for reuse

func (*MIDs) Request

func (m *MIDs) Request() (uint16, error)

Request is the library provided MIDService's implementation of the required interface function()

type StateInfo

type StateInfo struct {
	Sent *packets.ControlPacket // The most recent packet we sent with the relevant ID (will be resent on reconnection)
	// For publish related packets (included to simplify later operations)
	QOS     byte   // The QOS in the `PUBLISH`
	Topic   string // The topic from the original `PUBLISH` (if applicable)
	Payload []byte // The payload from `PUBLISH` (or nil for other messages)
}

StateInfo holds state information relating to a message ID

func NewStateInfo

func NewStateInfo(sent *packets.ControlPacket, qos byte, topic string, payload []byte) *StateInfo

NewStateInfo creates a StateInfo

Jump to

Keyboard shortcuts

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