execxtest

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 5 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 execxtest provides a scripted fake execx.Runner for transcript tests: each expected call is asserted in order and answered with a recorded result, so tests pin the exact argument vectors the core sends to git and gh without running either.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

type Call struct {
	// Name is the expected Cmd.Name, for example "git".
	Name string
	// Args is the expected exact argument vector.
	Args []string
	// Dir is the expected Cmd.Dir; empty skips the check because
	// many tests build paths from t.TempDir().
	Dir string
	// Env, when non-nil, is the expected exact Cmd.Env.
	Env []string
	// Stdin, when non-empty, is the expected full standard input;
	// empty skips the check, matching the Dir convention.
	Stdin string

	// Stdout, Stderr, and Exit form the scripted Result.
	Stdout string
	Stderr string
	Exit   int
	// Err, when non-nil, is returned instead of a Result, modeling
	// a command that could not run at all.
	Err error
}

Call is one expected invocation and its scripted response.

type Script

type Script struct {
	T     *testing.T
	Calls []Call
	// contains filtered or unexported fields
}

Script is a Runner that fails the test on any call that deviates from the recorded transcript.

func (*Script) AssertExhausted

func (s *Script) AssertExhausted()

AssertExhausted fails the test unless every scripted call was consumed. Tests use it to prove fail-closed short circuits: an operation that must be denied before touching git leaves an empty script untouched.

func (*Script) Run

func (s *Script) Run(_ context.Context, c execx.Cmd) (execx.Result, error)

Run asserts that c matches the next scripted call and returns its recorded response.

func (*Script) StdinAt added in v0.4.0

func (s *Script) StdinAt(i int) string

StdinAt returns the standard input the i-th consumed call received (0-based, "" when that call had none). It exists for bodies a test wants to assert on structurally — parse the posted issue body and check the record — rather than spell out byte-for-byte in a Call.Stdin expectation, which would only restate the code that produced it.

Jump to

Keyboard shortcuts

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