Documentation
¶
Overview ¶
Package mqtttestbroker is a minimal in-process MQTT 3.1.1 broker for tests. It implements just enough of the protocol for real clients to connect (plain TCP or TLS), subscribe, publish, receive publishes, ping and disconnect — including last-will delivery on ungraceful drops. It is a test double: no auth, no retain store, no QoS 2, no persistence — do not use it in production.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RawConnect ¶
RawConnect dials a plaintext broker and hand-writes a minimal MQTT 3.1.1 CONNECT packet, returning the open connection after reading the CONNACK. It exists so tests can drop a client ungracefully — closing the returned connection without a DISCONNECT packet is what triggers the broker's last-will path, something a well-behaved client library never does on demand.
Types ¶
type Broker ¶
type Broker struct {
// Published records every publish the broker saw, in order —
// handy for assertions on what the client side sent. Guarded by
// mu — read it through PublishedMessages().
Published []PublishedMessage
// contains filtered or unexported fields
}
Broker is a running test broker.
func StartTLS ¶
StartTLS runs a TLS broker on a random loopback port using a self-signed server certificate valid for 127.0.0.1/localhost. The CA PEM is available via CAPEM so tests can configure client-side verification through the same file-path knobs real flows use.
func (*Broker) CAPEM ¶
CAPEM returns the PEM bytes of the CA that signed the server certificate (TLS brokers only — nil otherwise).
func (*Broker) Close ¶
func (b *Broker) Close()
Close stops the listener and drops every client connection.
func (*Broker) PublishedMessages ¶
func (b *Broker) PublishedMessages() []PublishedMessage
PublishedMessages returns a copy of the recorded publishes — the broker's serve goroutines append while tests read.