testsupport

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 9 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 shared by Kivgraph tests. It is not imported by production code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClockResolvesShortDurations added in v0.9.1

func ClockResolvesShortDurations() bool

ClockResolvesShortDurations reports whether this platform's monotonic clock can measure an interval shorter than the work a fast unit test does.

It cannot everywhere. Go's monotonic clock on Windows reads the interrupt time, whose tick is the scheduler's rather than the counter's, and the difference is four orders of magnitude. Measured on the host this branch was developed against:

                                  linux/amd64   windows/amd64
smallest non-zero time.Since             9ns         52.6µs
short work measured as exactly 0     0 / 1000      996 / 1000

So an assertion that some duration is greater than zero is a claim about the clock and not about the code, and on Windows it is a claim the clock refuses almost always. A test whose subject is a counter keeps its counter and drops the duration beside it, the way a test whose subject is privacy drops a mode bit -- see ModeBitsHonoured, which is the same shape for the same reason.

This is not a licence to stop measuring duration. It is a statement that a duration under 52.6µs is unobservable there, and a test that needs one has to make the work long enough to see rather than assert its way past the tick.

func InstalledExecutable added in v0.9.1

func InstalledExecutable() string

InstalledExecutable is a plausible absolute path to an installed kivgraph, in the shape the running platform uses.

The fixtures that need one were written as "/opt/kivgraph/bin/kivgraph", which is not an absolute path on Windows and is not what a program is called there. integrations.New absolutises what it is handed -- correctly -- so the manager held "C:\opt\kivgraph\bin\kivgraph" while the assertion beside it still held the Unix spelling, and the test failed for the fixture rather than for the code.

A fixture demonstrates the real case or it demonstrates nothing.

func ModeBitsHonoured added in v0.9.1

func ModeBitsHonoured() bool

ModeBitsHonoured reports whether this platform stores the permission bits Go reports, so a test that checks a mode as one claim among several can drop that one claim and keep the rest instead of skipping whole.

func MovedExecutable added in v0.9.1

func MovedExecutable() string

MovedExecutable is a second plausible absolute path to an installed kivgraph, different from InstalledExecutable and in the same platform shape.

The fixtures that need one are testing that a client configuration naming a kivgraph which has since moved is replaced rather than appended beside. That needs two paths, and the second was written as "/usr/local/bin/kivgraph" -- which on Windows is not absolute, so it absolutised to "C:\usr\local\bin\kivgraph" while the assertion still held the Unix spelling. Same failure as above, one fixture further along.

func ProcessAlive added in v0.9.1

func ProcessAlive(pid int) bool

ProcessAlive reports whether a process exists and this one may signal it.

Signal 0 is the question without the request: the kernel performs every check it would for a real signal and delivers nothing.

func RequireRustAnalyzer

func RequireRustAnalyzer(t testing.TB)

RequireRustAnalyzer skips the test unless this machine can actually run rust-analyzer.

Presence on PATH does not answer that. rustup installs a proxy named rust-analyzer for every toolchain, whether or not the component behind it was ever added, and that proxy exits with "Unknown binary 'rust-analyzer' in official toolchain". A guard that only looks the name up reports the analyzer as installed on any machine with rustup, so the tests run and fail instead of skipping — which is exactly what a hosted runner without `rustup component add rust-analyzer` looks like.

Running `--version` is the cheapest question whose answer is the one the caller needs.

func RequireSpaceOrSkip

func RequireSpaceOrSkip(t *testing.T, err error)

RequireSpaceOrSkip turns the one failure that belongs to the host rather than to the code under test into a skip.

Publishing a generation refuses a filesystem that is more than 85% full, whatever the size of the database, so on such a host a test that needs a published generation never reaches the behaviour it asserts. The policy itself is covered by the generation package, which builds its store with an explicit one.

func SetHome added in v0.9.1

func SetHome(t testing.TB, directory string)

SetHome points os.UserHomeDir at directory for the duration of a test.

It exists because "the home directory" is not one environment variable. os.UserHomeDir reads HOME on Unix and USERPROFILE on Windows, so a test that sets only HOME redirects nothing there: it runs against the real profile of whoever is running it, and then fails by reporting that directory instead of the one it prepared. Twenty-odd tests in this repository set only HOME, and all of them read as bugs in the code under test when they fail.

Both are set on both platforms. The one the running platform does not consult costs nothing, and setting it keeps a test that shells out to a tool with its own idea of home from disagreeing with the process that spawned it.

func SkipWithoutModeBits added in v0.9.1

func SkipWithoutModeBits(t testing.TB)

SkipWithoutModeBits skips a test whose subject is a POSIX file permission.

It is a skip and not a relaxed assertion because the two are not the same claim. Windows keeps an access control list, and Go reports every regular file there as 0666 and every directory as 0777 regardless of it -- so a test that widened what it accepts would pass on a machine where the file really is readable by everyone, and report that as the privacy it was written to check. Nothing here sets an ACL yet; when something does, these tests get a sibling that asserts it, not a looser version of themselves.

func TempDir

func TempDir(t testing.TB) string

TempDir returns a per-test temporary directory whose path contains no symlink component.

Repository path validation rejects a path with a symlinked ancestor, and that policy is deliberate. On macOS the directory returned by t.TempDir() lives under /var/folders and /var is a symlink to /private/var, so a test that feeds t.TempDir() to the workspace layer exercises the rejection instead of the behaviour under test. Resolving the realpath here keeps the production policy untouched.

Types

This section is empty.

Jump to

Keyboard shortcuts

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