Documentation
¶
Overview ¶
Package mock provides a pty-backed fake Flipper CLI so serial.go and the command wrappers can be exercised without real hardware.
The mock opens a /dev/ptmx master, hands the caller the /dev/pts/<n> slave path, and runs a goroutine that reads writes from the slave (i.e. bytes the CLI-under-test "sends" to the Flipper), dispatches them to a scripted command table, and writes canned responses back. A handshake banner is emitted as soon as the slave is first read from.
Linux-only: uses Linux-specific TIOCSPTLCK / TIOCGPTN ioctls. Tests on other platforms must skip or use a different harness.
Index ¶
Constants ¶
const DefaultBanner = "\r\nWelcome to the Mock Flipper CLI!\r\nFirmware: XFW-MOCK\r\n\r\n>: "
DefaultBanner is emitted once when the slave is first opened, as the welcome banner a real Flipper prints on DTR rising. Must end with a prompt so the handshake observer sees ">: ".
const DefaultDeviceInfo = `` /* 301-byte string literal not displayed */
DefaultDeviceInfo is the canned device_info output returned when no override is provided. It mirrors the shape of a real Xtreme-fork Flipper so Capabilities parses the expected fork / UID / name.
const MomentumDeviceInfo = `` /* 304-byte string literal not displayed */
MomentumDeviceInfo is a canned device_info for tests that need Momentum firmware capabilities (SubGHzRxRawHasFilePath=false, NFCFlaggedArgs=true).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
Handler renders a response body for a given command line. The returned string is what the mock will echo back BEFORE the closing prompt (the prompt is appended automatically). Commands not in the table produce a bare prompt (same as an unknown Flipper CLI command).
type Mock ¶
type Mock struct {
// contains filtered or unexported fields
}
Mock is a running pty-backed fake Flipper. Returned by Spawn. Call Close (or register as t.Cleanup) to tear down.
func Spawn ¶
Spawn creates a new mock Flipper. The returned path may be passed to flipper.Connect. The t.Cleanup hook closes it automatically.
func (*Mock) BytesReceived ¶ added in v0.2.0
BytesReceived returns a snapshot of every raw byte received from the CLI-under-test since Spawn. Unlike Lines, this includes control bytes such as \x03 (Ctrl+C) that are consumed without becoming complete command lines.
func (*Mock) Close ¶
Close tears down the pty pair and waits for the responder goroutine to exit. Safe to call multiple times.
func (*Mock) Lines ¶
Lines returns a copy of every non-empty command line the mock has dispatched since Spawn, in order. Useful for asserting what the flipper-under-test actually sent on the wire.
func (*Mock) Path ¶
Path returns the /dev/pts/<n> slave path the caller should pass to flipper.Connect.
func (*Mock) URL ¶
URL returns the mock:// transport URL for this mock. Prefer this over Path when calling flipper.ConnectURL, so the test exercises the dedicated mockTransport dialer in internal/flipper/transport rather than the serial dialer's go.bug.st/serial fallback path. Both work against a pty slave today, but routing through the mock scheme keeps test intent obvious and mirrors how a future BLE-backed mock would be wired.
type Option ¶
type Option func(*Mock)
Option tunes the mock at construction time.
func WithBanner ¶
WithBanner overrides the one-shot welcome banner.
func WithHandler ¶
WithHandler registers a response handler for a command token (the first whitespace-separated word). Overwrites any previous handler.
func WithSuppressPrompt ¶ added in v0.2.0
WithSuppressPrompt suppresses the automatic "\r\n>: " prompt that dispatch appends after handling the named command. Use this to simulate commands that stream indefinitely without emitting a closing prompt (like `subghz rx` or `log`). The handler's returned body is still written; only the trailing prompt is withheld until a Ctrl+C arrives.