fakevendor

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

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

func Build(ctx context.Context, s *Script, name string) (string, func(), error)

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

func Main(args []string) int

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.

func Load

func Load(r io.Reader) (*Script, error)

Load decodes a script from r. Unknown fields are an error.

func LoadFile

func LoadFile(path string) (*Script, error)

LoadFile loads a script from a file.

func (*Script) Validate

func (s *Script) Validate() error

Validate checks the step structure and compiles every regexp.

type Step

type Step struct {
	Expect      *Expect `yaml:"expect,omitempty"`
	Emit        *Emit   `yaml:"emit,omitempty"`
	SleepMillis int     `yaml:"sleepMillis,omitempty"`
	ExitCode    *int    `yaml:"exitCode,omitempty"`
}

Step is one action of a script. Exactly one field is set (Validate enforces this).

Directories

Path Synopsis
Command fakevendor replays a fake-vendor script from a file.
Command fakevendor replays a fake-vendor script from a file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL