harness

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 14 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 harness builds and drives the real heraut binary for the e2e suite (ADR-0066).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Binary

func Binary(t testing.TB, tags ...string) string

Binary builds cmd/heraut once per distinct tag set and returns the executable path.

func Cleanup

func Cleanup()

Cleanup removes the build directory; call it from TestMain after m.Run.

Types

type GitHub added in v0.82.0

type GitHub struct {
	URL string
	// contains filtered or unexported fields
}

GitHub is a loopback stand-in for the GitHub REST API, laid out as a GitHub Enterprise Server without subdomain isolation: the API under /api/v3 and uploads under /api/uploads, on one origin. It answers 200 to reads (an empty array for a releases list), 201 to release creation and uploads (with the uploaded name rewritten as GitHub does: "#" becomes "."), 200 to the publish PATCH and 204 to a delete. Every request is logged as "github [METHOD] [/path]" in the call log both stand-ins share, so a test can assert on the order of calls across forges.

func (*GitHub) FailReleases added in v0.82.0

func (g *GitHub) FailReleases()

FailReleases makes every following release creation answer 403 (the call is still logged).

func (*GitHub) FailUploads added in v0.82.0

func (g *GitHub) FailUploads()

FailUploads makes every following asset upload answer 422, as GitHub does for a duplicate name (the call is still logged).

func (*GitHub) Hang added in v0.83.0

func (g *GitHub) Hang(kind Hang) <-chan struct{}

Hang makes every following request of kind wait without answering until the client gives up (the call is still logged, and an upload is not accepted). The returned channel is closed when the first such request arrives, so a test can act while the client waits.

func (*GitHub) Release added in v0.82.0

func (g *GitHub) Release() map[string]any

Release is the JSON body of the last accepted release creation (nil if none).

func (*GitHub) Uploads added in v0.82.0

func (g *GitHub) Uploads() []string

Uploads lists the asset names of the accepted uploads, as sent, oldest first.

type GitLab added in v0.77.0

type GitLab struct {
	URL string
	// contains filtered or unexported fields
}

GitLab is a loopback stand-in for the GitLab REST API. It answers 200 to reads (an empty array for a releases list), 201 to uploads and release creation, and logs every request as "gitlab [METHOD] [/decoded/path]" in the call log both stand-ins share, so a test can assert on the order of calls across forges.

func (*GitLab) FailReleases added in v0.77.0

func (g *GitLab) FailReleases()

FailReleases makes every following release creation answer 403 (the call is still logged).

func (*GitLab) Release added in v0.77.0

func (g *GitLab) Release() map[string]any

Release is the JSON body of the last accepted release creation (nil if none).

type Hang added in v0.83.0

type Hang int

Hang names a kind of request the stand-in can be told to leave unanswered.

const (
	HangUploads      Hang = iota // asset uploads
	HangReleaseLists             // GET .../releases, the token check
	HangGraphQL                  // POST /api/graphql, the pull-request lookups
)

type Process added in v0.82.0

type Process struct {
	// contains filtered or unexported fields
}

Process is a command started in the background by Repo.Start, for a scenario that acts while it runs (an interrupt, for one).

func (*Process) Interrupt added in v0.82.0

func (p *Process) Interrupt(t testing.TB)

Interrupt sends the process SIGINT, as Ctrl-C in a terminal does.

func (*Process) Wait added in v0.82.0

func (p *Process) Wait(t testing.TB) Result

Wait returns the outcome once the process exits, and fails the test if it is still running after thirty seconds (the process is then killed).

func (*Process) WaitForOutput added in v0.82.0

func (p *Process) WaitForOutput(t testing.TB, want string)

WaitForOutput blocks until the process has printed want on stdout, and fails the test after ten seconds or when the process exits first.

type Repo

type Repo struct {
	Dir string
	// contains filtered or unexported fields
}

Repo is a throwaway git repository with deterministic identity and no signing.

func NewRepo

func NewRepo(t testing.TB) *Repo

NewRepo initialises an empty repository on branch main; it skips when git is not on PATH.

func (*Repo) APICalls added in v0.82.0

func (r *Repo) APICalls() []string

APICalls returns every request the stand-ins of this repository received, oldest first, as "forge [METHOD] path".

func (*Repo) AddRemote

func (r *Repo) AddRemote()

AddRemote creates a bare repository, wires it as origin and pushes the current branch with upstream tracking. The repository needs at least one commit.

func (*Repo) Checkout

func (r *Repo) Checkout(branch string)

Checkout creates branch at HEAD and switches to it.

func (*Repo) Commit

func (r *Repo) Commit(msg string)

Commit records an empty commit with the given message.

func (*Repo) Detach

func (r *Repo) Detach()

Detach detaches HEAD at its current commit.

func (*Repo) FakeGitHub added in v0.82.0

func (r *Repo) FakeGitHub() *GitHub

FakeGitHub starts the stand-in for this repository (once; later calls return the same one) and shuts it down with the test. Point a forge's base_url at URL. The call log exists from here on.

func (*Repo) FakeGitLab added in v0.77.0

func (r *Repo) FakeGitLab() *GitLab

FakeGitLab starts the stand-in for this repository (once; later calls return the same one) and shuts it down with the test. Point a forge's base_url at URL. The call log exists from here on.

func (*Repo) Git

func (r *Repo) Git(args ...string) string

Git runs git in the repository and returns its trimmed output.

func (*Repo) GitRemote

func (r *Repo) GitRemote(args ...string) string

GitRemote runs git against the bare remote and returns its trimmed output.

func (*Repo) Home

func (r *Repo) Home() string

Home is the HOME directory the repository's commands run with.

func (*Repo) MergeNoFF

func (r *Repo) MergeNoFF(branch string)

MergeNoFF merges branch into the current branch with a merge commit.

func (*Repo) PushOptions added in v0.84.0

func (r *Repo) PushOptions() [][]string

PushOptions returns the options of every push the remote received since RecordPushOptions, one entry per push in order. A push without options is an empty entry.

func (*Repo) ReadFile

func (r *Repo) ReadFile(rel string) string

ReadFile returns the contents of a file relative to the repository root.

func (*Repo) RecordPushOptions added in v0.84.0

func (r *Repo) RecordPushOptions()

RecordPushOptions makes the bare remote accept push options and record them; read them back with PushOptions. Call it after AddRemote.

func (*Repo) RemoveRemote

func (r *Repo) RemoveRemote()

RemoveRemote deletes the bare remote so a later push fails.

func (*Repo) RestoreRemote

func (r *Repo) RestoreRemote(rev string)

RestoreRemote recreates the bare remote removed by RemoveRemote, holding only main at rev (typically the commit the remote had before the failed push), so a retry meets a remote that is reachable again but still behind.

func (*Repo) Run

func (r *Repo) Run(bin string, env []string, args ...string) Result

Run executes bin with args inside the repository. The environment is built from scratch (PATH, HOME, NO_COLOR, ...) plus env, so ambient CI variables never reach the binary.

func (*Repo) RunStdin

func (r *Repo) RunStdin(bin string, env []string, stdin string, args ...string) Result

RunStdin is Run with the given text on the command's standard input.

func (*Repo) Start added in v0.82.0

func (r *Repo) Start(bin string, env []string, args ...string) *Process

Start runs bin with args inside the repository, with the environment Run uses, and returns at once. The test must call Wait.

func (*Repo) Switch

func (r *Repo) Switch(branch string)

Switch moves to an existing branch.

func (*Repo) Tag

func (r *Repo) Tag(name string)

Tag creates an annotated tag on HEAD.

func (*Repo) WriteConfig

func (r *Repo) WriteConfig(yaml string)

WriteConfig writes .heraut.yml at the repository root.

func (*Repo) WriteFile

func (r *Repo) WriteFile(rel, content string)

WriteFile writes content to a path relative to the repository root, creating directories.

func (*Repo) WriteHomeFile

func (r *Repo) WriteHomeFile(rel, content string)

WriteHomeFile writes content to a path relative to HOME, creating directories.

type Result

type Result struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

Result is the observable outcome of one binary invocation.

Jump to

Keyboard shortcuts

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