go.bigb.es/auxilia
Documentation
Index
- type FakeConn
- func NewFakeConn() *FakeConn
- func (*FakeConn) Close() error
- func (*FakeConn) Closed() bool
- func (*FakeConn) Exec(ctx context.Context, cmd legatus.Cmd) (legatus.ExecResult, error)
- func (*FakeConn) ExecStream(ctx context.Context, cmd legatus.Cmd, stdout, stderr io.Writer) (legatus.ExecResult, error)
- func (*FakeConn) Get(_ context.Context, remote string, w io.Writer) error
- func (*FakeConn) Put(_ context.Context, content io.Reader, remote string, mode legatus.FileMode, opts ...legatus.PutOption) error
- type FakeDialer
- type PutCall
Types
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.
func (c *FakeConn) Closed() bool
Closed reports whether Close was called.
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).
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.
func (c *FakeConn) Get(_ context.Context, remote string, w io.Writer) error
Get writes previously-Put content for remote, if any.
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.
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).
func (d *FakeDialer) Dial(_ context.Context, h *legatus.Host) (legatus.Conn, error)
Dial records the host and returns its conn.
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.
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.