Documentation
¶
Overview ¶
Package fakevendor builds a fake vendor CLI from a YAML script (SPEC §5.9). The fake replays an ordered list of steps: it expects a stdin line that matches a JSON subset or a regexp, or asserts argv; it emits a stdout or stderr line; it sleeps; it exits with a code. A script may also carry canned replies for `--version` and `auth status`.
Build compiles a self-contained executable that replays a script, so a provider plugin can spawn it in place of the real vendor CLI. Script files that a plugin ships live under testdata/fakevendor/*.yaml and are generated from recorded fixtures, never invented.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
Build compiles a temporary self-contained executable named name that replays s, using `go build`. It returns the absolute path and a cleanup func.
func Main ¶
Main is the entry point of the standalone `fakevendor` CLI: it loads the script at args[1] and replays it with args[2:] as argv. It is used for manual debugging of a script; Build compiles self-contained binaries for scenarios.
func Run ¶
func Run(ctx context.Context, s *Script, argv []string, stdin io.Reader, stdout, stderr io.Writer) int
Run executes the script against argv/stdin/stdout/stderr and returns the exit code. It answers --version and auth status before the steps. A mismatch or a missing stdin line writes a diagnostic to stderr and returns 2.
Types ¶
type Emit ¶
type Emit struct {
// Stream is "stdout" (default) or "stderr".
Stream string `yaml:"stream,omitempty"`
// Line is the literal line to write. Exactly one of Line and Env is set.
Line string `yaml:"line,omitempty"`
// Env makes the step emit "<Env>=<os.Getenv(Env)>", reporting the value of
// an environment variable (empty for an absent var). Exactly one of Line
// and Env is set.
Env string `yaml:"env,omitempty"`
}
Emit writes one line to stdout or stderr.
type Expect ¶
type Expect struct {
// JSON requires the decoded stdin line to contain this subset.
JSON map[string]any `yaml:"json,omitempty"`
// Regex requires the stdin line to match this regexp.
Regex string `yaml:"regex,omitempty"`
// Argv requires argv to equal this exactly (no line is read).
Argv []string `yaml:"argv,omitempty"`
}
Expect matches a stdin line, or asserts argv.
type Script ¶
type Script struct {
Name string `yaml:"name"`
// Version is the raw line emitted to stdout when argv contains --version.
Version string `yaml:"version,omitempty"`
// AuthStatus is the raw line emitted to stdout when argv is ["auth","status"].
AuthStatus string `yaml:"authStatus,omitempty"`
Steps []Step `yaml:"steps"`
}
Script is a fake vendor CLI program.