dummymqttd

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package dummymqttd can be used to simulate MODE's MQTT server for testing.

Index

Constants

View Source
const (
	KVSyncActionReload = "reload"
	KVSyncActionSet    = "set"
	KVSyncActionDelete = "delete"
)

These are possible values for the KeyValueSync.Action field.

View Source
const (
	DefaultMqttHost = "localhost"
	DefaultMqttPort = 1998
)

Variables

View Source
var (
	DefaultUsers = []string{"good", "1234"}

	DefaultItems = []*KeyValue{
		{Key: "key1", Value: "value1", ModificationTime: time.Now()},
		{Key: "key2", Value: "value2", ModificationTime: time.Now()},
	}

	// DummyServerDelayDuration is the amount of time the server will wait before
	// responding. This can be used to simulate a slow network
	DummyServerDelayDuration = 3 * time.Second

	// ServerContext is initialized by either StartDummyMQTTD or StartDummyMQTTDWithConfig
	ServerContext *DummyContext
)

Functions

func StartDummyMQTTD

func StartDummyMQTTD(ctx context.Context, wg *sync.WaitGroup,
	cmdCh chan DummyCmd) bool

StartDummyMQTTD is dummy MQTT server. It will run an MQTT server as a goroutine. An optional command channel can be passed in to manipulate the server manipulating test conditions and shutting down. Unlike the v2 dummyMQTTD, this starts goroutines but isn't meant to be run as a goroutine. It will panic if it is unable to start listening.

To end the server, either close the command channel or call cancel() on the context.

func StartDummyMQTTDWithConfig

func StartDummyMQTTDWithConfig(ctx context.Context, wg *sync.WaitGroup,
	cmdCh chan DummyCmd, conf DummyConfig) bool

Types

type DummyClient

type DummyClient struct {
	Subscriptions []string
	// contains filtered or unexported fields
}

type DummyCmd

type DummyCmd int
const (
	// PublishCmd tells the server to publish on whatever topics a client is subscribed to
	PublishCmd DummyCmd = iota
	// PublishKvSync tells the server to publish some kv commands
	PublishKvSync
	PublishKvSet
	PublishKvDelete
	// PublishCommandCmd tells the server to publish a command
	PublishCommandCmd
	// ShutdownCmd shuts the server down
	ShutdownCmd
	// DisconnectCmd disconnects all connections
	DisconnectCmd
	// SlowdownServerCmd inserts a 3-second delay after receiving the next command
	SlowdownServerCmd
	// ResetServerCmd resets the server to normal
	ResetServerCmd
)

type DummyConfig

type DummyConfig struct {
	MqttHost string
	MqttPort int
	Users    []string
	SubData  []byte
}

type DummyContext

type DummyContext struct {
	Clients []*DummyClient
	// contains filtered or unexported fields
}

type KeyValue

type KeyValue struct {
	Key              string      `json:"key"`
	Value            interface{} `json:"value"`
	ModificationTime time.Time   `json:"modificationTime"`
}

KeyValue represents a key-value pair stored in the Device Data Proxy.

type KeyValueSync

type KeyValueSync struct {
	Action   string      `json:"action"`
	Revision int         `json:"rev"`
	Key      string      `json:"key"`
	Value    interface{} `json:"value"`
	NumItems int         `json:"numItems"`
	Items    []*KeyValue `json:"items"`
}

KeyValueSync is a message received from MODE regarding a device's key-value store (DDP).

  • If Action has a value of KVSyncActionReload, the Items field will be populated with all the existing key-value pairs.
  • If Action has a value of KVSyncActionSet, the Key and Value fields will be populated with a recently saved key-value pair.
  • If Action has a value of KVSyncActionDelete, the Key field will be populated with a recently deleted key.

In all cases, the Revision field indicates the current revision number of the key-value store.

Jump to

Keyboard shortcuts

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