go.bigb.es/auxilia

v0.4.0
Doc Versions Source

Documentation

Package legatustest provides test doubles for the legatus core: a scripted Conn and a Dialer that hands them out per host. Shared so engine, steps, and sync tests do not each reimplement a fake (GPC8). The doubles are safe for the concurrent use the Runner makes of them under fan-out.

Types

T type FakeConn

src
type FakeConn struct {
	ExecFn func(ctx context.Context, cmd legatus.Cmd) (legatus.ExecResult, error)
	// StreamFn, when set, backs ExecStream instead of the ExecFn+copy default — for
	// fakes that must write to the sinks incrementally or honor ctx mid-stream.
	StreamFn func(ctx context.Context, cmd legatus.Cmd, stdout, stderr io.Writer) (legatus.ExecResult, error)
	Files    map[string][]byte

	Execs []legatus.Cmd
	Gets  []string
	Puts  []PutCall
	// contains filtered or unexported fields
}

FakeConn is a scripted legatus.Conn. Set ExecFn to script command responses; uploads are captured in Files; every call is recorded.

ExecFn must honor the Conn.Exec contract: a command that "runs" returns a nil error even on a non-zero exit, with the status in ExecResult.ExitCode — matching the real SSH transport. Returning a non-nil error models a failure to run at all (no session, IO error), NOT a non-zero exit code.

f func NewFakeConn

src

NewFakeConn returns a ready FakeConn.

m func (*FakeConn) Close

src
func (c *FakeConn) Close() error

Close marks the connection closed.

m func (*FakeConn) Closed

src
func (c *FakeConn) Closed() bool

Closed reports whether Close was called.

m func (*FakeConn) Exec

src
func (c *FakeConn) Exec(ctx context.Context, cmd legatus.Cmd) (legatus.ExecResult, error)

Exec records the command and delegates to ExecFn (zero result if unset).

m func (*FakeConn) ExecStream

src
func (c *FakeConn) ExecStream(ctx context.Context, cmd legatus.Cmd, stdout, stderr io.Writer) (legatus.ExecResult, error)

ExecStream records the command and streams output. When StreamFn is set it backs the call directly; otherwise it runs ExecFn and copies the scripted ExecResult.Stdout/Stderr to each non-nil writer (a nil writer keeps its bytes in the result), mirroring the real transports' contract.

m func (*FakeConn) Get

src
func (c *FakeConn) Get(_ context.Context, remote string, w io.Writer) error

Get writes previously-Put content for remote, if any.

m func (*FakeConn) Put

src
func (c *FakeConn) Put(_ context.Context, content io.Reader, remote string, mode legatus.FileMode, opts ...legatus.PutOption) error

Put captures the uploaded content keyed by remote path, and records the call (mode + resolved options) in Puts.

T type FakeDialer

src
type FakeDialer struct {
	Conns   map[string]*FakeConn
	Default func(*legatus.Host) *FakeConn

	Dials []string
	// contains filtered or unexported fields
}

FakeDialer hands out FakeConns. Conns maps host name to a specific conn; otherwise Default (if set) builds one, else a fresh FakeConn is returned. Dial is safe for concurrent use (the Runner dials hosts in parallel).

m func (*FakeDialer) Dial

src
func (d *FakeDialer) Dial(_ context.Context, h *legatus.Host) (legatus.Conn, error)

Dial records the host and returns its conn.

T type PutCall

src
type PutCall struct {
	Remote string
	Mode   legatus.FileMode
	Opts   legatus.PutOptions
}

PutCall records one Put: the destination, mode, and resolved options — so a test can assert sudo/owner threading, which the Files map alone can't show.

Source Files