fakebin

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fakebin turns the test binary into fake executables such as terragrunt or mise. A sidecar spec next to each link says what the fake prints and how it exits, and every call is recorded.

Index

Constants

View Source
const ExitInterrupted = 130

ExitInterrupted is the exit code of a blocking fake that was interrupted.

Variables

This section is empty.

Functions

func Install

func Install(t testing.TB, name string, spec Spec) string

Install links the test binary into a new temp directory as name and returns the link's path.

func Main

func Main(m *testing.M)

Main runs the fake when this process was started through an [Install]ed link, and the tests otherwise. Call it from TestMain.

func Serve

func Serve()

Serve runs the fake and exits when this process was started through an [Install]ed link, and returns otherwise. A TestMain that hands over to testscript.Main calls it first, because testscript.Main replaces os.Args[0], where the fake finds its spec.

Types

type Call

type Call struct {
	Args []string          `json:"args"`
	Dir  string            `json:"dir"`
	Env  map[string]string `json:"env,omitempty"`
}

Call is one recorded invocation.

func Calls

func Calls(t testing.TB, path string) []Call

Calls returns the invocations recorded for the fake at path, oldest first.

type File

type File struct {
	Flag string `json:"flag"`
	Src  string `json:"src"`
}

File copies Src, a file or a directory relative to the fake's directory, to the path that follows Flag in the call's args, as in "--report-file <path>" or "--report-file=<path>".

type Rule

type Rule struct {
	Args            []string `json:"args,omitempty"`
	Dir             string   `json:"dir,omitempty"` // suffix of the working directory, slash-separated; empty matches any
	Stdout          string   `json:"stdout,omitempty"`
	StdoutFile      string   `json:"stdout_file,omitempty"` // appended after Stdout; relative to the fake's directory
	Stderr          string   `json:"stderr,omitempty"`
	ExitCode        int      `json:"exit_code,omitempty"`
	Block           bool     `json:"block,omitempty"`            // wait for SIGINT/SIGTERM, then exit 130
	IgnoreInterrupt bool     `json:"ignore_interrupt,omitempty"` // with Block: only a kill ends the process
	Files           []File   `json:"files,omitempty"`            // written before the rule answers
}

Rule is one canned response.

type Spec

type Spec struct {
	Rules     []Rule   `json:"rules"`
	RecordEnv []string `json:"record_env,omitempty"` // env vars recorded with each call
}

Spec describes a fake tool. The first rule whose Args is a prefix of the call's args, and whose Dir matches the call's working directory, answers it.

Jump to

Keyboard shortcuts

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