Documentation
¶
Overview ¶
Package testsupport provides shared test-fixture helpers used across awf's test suites: TestMain HOME isolation, 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 for the go-git-dependent helpers) - 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 ¶
- func ADR(status string, opts ...ADROption) string
- func RepoRoot(t *testing.T) string
- func RunIsolated(m *testing.M, prefix string) int
- func SwapVar[T any](t *testing.T, seam *T, val T)
- func WalkRepoSources(t *testing.T, root string, fn func(rel string, body []byte))
- func WriteAwfConfig(t *testing.T, root, yamlContent string)
- func WriteFile(t *testing.T, path, content string)
- func WriteGoModule(t *testing.T, dir, modPath, srcBody string)
- func WriteProfile(t *testing.T, dir, body string) string
- type ADROption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ADR ¶
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 RepoRoot ¶ added in v0.18.0
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 ¶
RunIsolated gives m a throwaway HOME (os.MkdirTemp(prefix)) for the duration of its run, so go-git's global-gitignore read finds nothing belonging to the developer's real machine, then removes the temp HOME and returns the run's exit code for the caller to pass to os.Exit:
func TestMain(m *testing.M) { os.Exit(testsupport.RunIsolated(m, "awf-test-home")) }
func SwapVar ¶
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).
func WalkRepoSources ¶ added in v0.18.0
WalkRepoSources calls fn(relPath, contents) for every production Go file in the repository, and is the single definition of awf's repo-walk boundary. A hand-rolled walker must state that boundary or it silently reads foreign source as its own: hidden trees (notably .claude/worktrees/, which holds session checkouts of this very repo) and any nested checkout (a directory carrying its own .git entry, whether a directory or a gitdir-pointer file) are pruned, as are _test.go files. Two independent scanners drifted on this before it was stated once here.
func WriteAwfConfig ¶
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 ¶
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 ¶
WriteGoModule writes a minimal go.mod (pinned to this repo's Go toolchain version) and an f.go containing srcBody under dir.
Types ¶
type ADROption ¶
type ADROption func(*adrOpts)
ADROption configures an ADR fixture built by ADR.
func WithDate ¶
WithDate sets the frontmatter date field. Omitted from the frontmatter entirely when never called - some fixtures deliberately carry no date.
func WithDomains ¶
WithDomains sets the frontmatter domains array.
func WithRelated ¶ added in v0.18.0
WithRelated sets the frontmatter related array (ADR numbers).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package gitfixture provides go-git-backed test fixtures (a fixed commit signature, a fresh repo, and a write+commit helper) for awf's test suites that need a real git repository.
|
Package gitfixture provides go-git-backed test fixtures (a fixed commit signature, a fresh repo, and a write+commit helper) for awf's test suites that need a real git repository. |