testsupport

package
v0.39.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package testsupport provides shared test-fixture helpers used across awf's test suites: managed TestMain HOME lifecycle, project-config scaffolding, ADR frontmatter fixtures, file-writing primitives, and the seam-swap idiom. It is a leaf package - only the Go standard library may be imported here (see the gitfixture subpackage, the single home for Git fixtures and the only place permitted to reach Git directly) - so it is safe to import from any package's tests without risking an import cycle (ADR-0044). deps_test.go enforces the zero-internal-deps constraint mechanically.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ADR

func ADR(status string, opts ...ADROption) string

ADR builds a ---delimited ADR frontmatter fixture as a raw string: a status field plus any of date/tags/domains supplied via opts, a "# ADR-<title>" heading, and an optional trailing body. It intentionally does not import internal/adr and marshal its real frontmatter struct - doing so would break this package's zero-internal-deps invariant (see ADR-0044's Consequences).

func CleanTestTemps added in v0.30.0

func CleanTestTemps(mode CleanupMode, output io.Writer) error

CleanTestTemps cleans production managed test homes and writes their summary.

func Context added in v0.30.0

func Context(t *testing.T) context.Context

Context returns the test's context with a deadline attached, cancelled when the test ends. The seam's native Git runner refuses a context that carries no deadline, so every test whose subject reaches Git takes its context from here rather than from t.Context() or a bare background context; one helper means the refusal cannot be satisfied differently in different suites.

func RepoRoot added in v0.18.0

func RepoRoot(t *testing.T) string

RepoRoot ascends from the test's working directory to the directory holding go.mod, so a repo-wide scan is never anchored to a package's depth.

func RunIsolated

func RunIsolated(m *testing.M) int

func SwapVar

func SwapVar[T any](t *testing.T, seam *T, val T)

SwapVar overrides *seam with val for the duration of the test, restoring the original value via t.Cleanup. Covers the swapGetwd/swapHasGoMod/ forceNonInteractive-shaped idiom: a *T package-private seam variable reassigned for one test, in the same package as the test. Does not cover internal/adr's swapNow, an external-test-package accessor of a different shape (ADR-0044 Context). Serves the existing seam census only: minting a new package-level swap variable is banned for new work by code-design/test-design (no-new-global-seams).

func WalkRepoFiles added in v0.22.0

func WalkRepoFiles(t *testing.T, root string, include func(rel string) bool, fn func(rel string, body []byte))

WalkRepoFiles calls fn(relPath, contents) for each repository-owned file for which include returns true. It is the single definition of awf's repo-walk boundary: hidden trees (notably .claude/worktrees/) and nested checkouts (a directory carrying its own .git directory or gitdir-pointer file) are pruned. The caller owns file selection, so the same boundary can scan Go, Markdown, or any other repository surface without duplicating traversal rules.

func WalkRepoSources added in v0.18.0

func WalkRepoSources(t *testing.T, root string, fn func(rel string, body []byte))

WalkRepoSources preserves the production-Go scanner API over WalkRepoFiles.

func WriteAwfConfig

func WriteAwfConfig(t *testing.T, root, yamlContent string)

WriteAwfConfig writes <root>/.awf/config.yaml with the given content - the project-fixture seed step every scaffold-style helper across awf's test suites starts from.

func WriteFile

func WriteFile(t *testing.T, path, content string)

WriteFile creates path's parent directories and writes content to it, failing the test on either error. The primitive every other file-writing helper in this package is built from.

func WriteGoModule

func WriteGoModule(t *testing.T, dir, modPath, srcBody string)

WriteGoModule writes a minimal go.mod (pinned to this repo's Go toolchain version) and an f.go containing srcBody under dir.

func WriteProfile

func WriteProfile(t *testing.T, dir, body string) string

WriteProfile writes dir/cover.out with a "mode: set\n" prefix followed by body, returning the file's path.

Types

type ADROption

type ADROption func(*adrOpts)

ADROption configures an ADR fixture built by ADR.

func WithBody

func WithBody(body string) ADROption

WithBody appends raw markdown (e.g. "## Context\nx\n") after the title heading.

func WithDate

func WithDate(date string) ADROption

WithDate sets the frontmatter date field. Omitted from the frontmatter entirely when never called - some fixtures deliberately carry no date.

func WithDomains

func WithDomains(domains ...string) ADROption

WithDomains sets the frontmatter domains array.

func WithRelated added in v0.18.0

func WithRelated(nums ...int) ADROption

WithRelated sets the frontmatter related array (ADR numbers).

func WithTags

func WithTags(tags ...string) ADROption

WithTags sets the frontmatter tags array.

func WithTitle

func WithTitle(title string) ADROption

WithTitle sets the ADR's number+title heading text - the part after "# ADR-", e.g. "0001: My Title". Defaults to "0001: T".

type CleanupMode added in v0.30.0

type CleanupMode int

CleanupMode selects which managed test homes cleanup considers.

const (
	// CleanupStale removes only homes strictly older than 24 hours.
	CleanupStale CleanupMode = iota
	// CleanupAll removes every canonical managed home.
	CleanupAll
)

Directories

Path Synopsis
cmd
testtmpclean command
Command testtmpclean owns repo-private test-temp cleanup invoked by ./x clean-test-tmp and is not part of the shipped awf CLI.
Command testtmpclean owns repo-private test-temp cleanup invoked by ./x clean-test-tmp and is not part of the shipped awf CLI.
Package fsfixture provides the repository's kernel-backed controlled filesystem fault source as the distinct test source authorized by ADR-consumer-local-contracts-over-single-home-filesystem-access.
Package fsfixture provides the repository's kernel-backed controlled filesystem fault source as the distinct test source authorized by ADR-consumer-local-contracts-over-single-home-filesystem-access.
Package gitfixture is the single home for building git repository state in awf's test suites.
Package gitfixture is the single home for building git repository state in awf's test suites.

Jump to

Keyboard shortcuts

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