testsupport

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 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 testsupport holds helpers that tests in many packages share. Only tests import it.

WriteExecutable writes a program that a test runs in place of an external tool, such as a stand-in tart, git, or portindex, so that the program starts even when a parallel test forks while it is being written.

Index

Constants

View Source
const ISCText = `` /* 697-byte string literal not displayed */

ISCText is the ISC license's text, below where its copyright line goes.

View Source
const MITText = `` /* 1023-byte string literal not displayed */

MITText is the MIT license's text, below where its copyright line goes.

View Source
const Settle = 2 * time.Minute

Settle bounds a test's wait for what a process or another goroutine does. It's a bound, not a pace: a wait ends as soon as its condition holds, and on a loaded machine, such as CI's runner beside the other tests, that can take far longer than it does alone; five seconds failed there for serve's words (2026-10-02), and ten for a local check's install beside the full suite (rc6's gate). A wait that asserts something happens within a time keeps its own bound and says so.

Variables

This section is empty.

Functions

func BaseAdapter

func BaseAdapter() string

BaseAdapter is DOCKHAND_TEST_BASE_ADAPTER, the evaluator adapter the tests select: "preview" admits a development build of Base, such as master, which the evaluator otherwise refuses.

func Git

func Git(t testing.TB, dir string, args ...string) string

Git runs git in dir for a test's fixture and returns what it printed, trimmed, failing the test where git fails. It is the one way tests set up repositories: commits by a fixed author, master the first branch, and nothing of the person's git configuration, hooks, signing, or GIT_ variables reaching it, so a fixture is the same on every Mac.

func GitEnv added in v0.8.0

func GitEnv(t testing.TB) []string

GitEnv is the environment for a git.Program a test runs: the process's, but nothing of the person's git configuration, the system's, or GIT_ variables. HOME and the global configuration are the test's own, in a temporary directory, where commits are by a fixed author, master is the first branch, and hooks and signing are off. A test that needs git to see one more variable, such as GIT_SSH_COMMAND, appends it, so it runs in parallel where t.Setenv would keep it serial. It is an environment rather than a git.Program because testsupport can't import internal/git, which imports internal/subprocess.

func IsolateHome

func IsolateHome() func()

IsolateHome points HOME at a fresh temporary directory for a test binary, so what dockhand keeps per user, such as its Tart image locks in ~/.dockhand, stays out of the person's. Call it from TestMain before m.Run; the returned function removes the directory.

func IsolateHomeKeepingTart

func IsolateHomeKeepingTart() func()

IsolateHomeKeepingTart is IsolateHome for packages with opt-in live Tart tests: where one is asked for, it first pins dockhand's Tart home, DOCKHAND_TART_HOME, its SSH keys, DOCKHAND_SSH_DIR, and the person's Tart home, TART_HOME, unless set, to the real ones, so those tests still find and reach their images, and share their locks. Otherwise it's IsolateHome, and the locks the other tests take stay out of the person's ~/.dockhand.

func IsolateTemp added in v0.8.0

func IsolateTemp() func()

IsolateTemp points TMPDIR at a fresh directory for a test binary, so the process's run root, which internal/scratch makes under the temporary directory and every transient directory lives in, stays out of the person's, where the next dockhand command would sweep it as a dead root. Call it from TestMain before m.Run; the returned function removes the directory.

It is for the binary, not one test: the run root is the process's, made under the temporary directory of the moment, so a test can't have its own without a t.Setenv, which keeps it from running in parallel.

func MacPortsTclsh

func MacPortsTclsh(t testing.TB) string

MacPortsTclsh is the port-tclsh MacPorts integration tests run against: DOCKHAND_TEST_MACPORTS_TCLSH, and never one found on PATH, which would test whichever Base PATH happens to reach. Without it the test skips.

func MacPortsTool

func MacPortsTool(t testing.TB, name string) string

MacPortsTool is another program of the installation MacPortsTclsh names, such as portindex, from the same bin directory.

func Program added in v0.8.0

func Program(t testing.TB, name string) string

Program is where the test's PATH has the program named, as compose finds one on the command line's, for a test to give where compose would; the test fails where it hasn't one.

func Tarball

func Tarball(t testing.TB, top string, files map[string]string) string

Tarball writes a gzipped tar of files under one top directory, as a release's source archive is laid out, and returns its path.

func WriteExecutable

func WriteExecutable(t testing.TB, path, program string)

WriteExecutable writes program to path for a test to run, creating the file with mode 0700 or truncating one that exists.

The file is open for writing only while no process can be forked. A child forked meanwhile, for a parallel test's command, would inherit the write descriptor until it execs, and running the program then fails with ETXTBSY, "text file busy". Forks hold syscall.ForkLock for writing, so the read lock keeps every child from ever holding the descriptor.

func WriteFiles added in v0.8.0

func WriteFiles(t testing.TB, root string, files map[string]string)

WriteFiles writes each of files, by its slash-separated path, under root, making the directories it needs, so a test lays out a ports tree, a source directory, or a configuration in one call.

func Zipball

func Zipball(t testing.TB, top string, files map[string]string) string

Zipball writes a zip of files under one top directory, and returns its path.

Types

type HTTPSAnswers

type HTTPSAnswers map[string]bool

HTTPSAnswers stands in for asking URLs over HTTPS: those it holds true answer, and no test asks the network. It's an engine's probe (engine.HTTPSProbe) and an edit's answers (portedit.HTTPSAnswers).

func (HTTPSAnswers) Answers

func (a HTTPSAnswers) Answers(_ context.Context, url string) bool

func (HTTPSAnswers) Ask added in v0.7.0

Ask has the answer at once, so starts nothing.

Jump to

Keyboard shortcuts

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