Documentation
¶
Overview ¶
Package repopath finds the repository root and reads files by their root-relative paths, so a test names a fixture such as "api/access.openapi.yaml" the same way from any package directory. It also holds the walk rule that every repository walk shares.
Role ¶
platform module, test support layer (platform/testkit). It imports only the standard library, so a test in any package can use it without an import cycle.
Inputs ¶
- The working directory of the test, which go test sets to the package directory; the nearest go.mod at or above it marks the root.
- Slash-separated paths relative to that root, named by tests.
Outputs ¶
- Absolute paths and file contents. A failed lookup fails the test through testing.TB instead of returning an error to every caller.
- The sorted root-relative directories that hold Go files, for the layout tests.
Invariants ¶
- Every walk skips directories whose name starts with ".", testdata, vendor, node_modules and any directory below the root with its own go.mod. Untracked worktree copies under dot-directories such as .worktrees/ each hold a go.mod, so a walk without this rule would see every package many times over.
References ¶
- Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md.
- Plan: docs/implementation/plan.md#p9d-modular-monolith-migration.
- https://github.com/weaveplatform/artifactweave/issues/950
Status ¶
Implemented P9d.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoModule = errors.New("no go.mod at or above the directory")
ErrNoModule reports that no directory at or above the starting directory holds a go.mod file.
Functions ¶
func FindRoot ¶
FindRoot returns the nearest directory at or above dir, dir included, that holds a go.mod file. A relative dir is first made absolute against the working directory, so the search can climb above it. The error wraps ErrNoModule when the search reaches the file system root without a match.
func GoDirs ¶
GoDirs returns the directories under root that hold .go files directly, as sorted, slash-separated paths relative to root ("." for root itself), walking with SkipDir. A directory of _test.go files alone counts, since it is still a package directory.
func Path ¶
Path returns the absolute path of rel, a slash-separated path relative to the repository root such as "api/access.openapi.yaml". It fails the test when rel is empty, absolute or has "." or ".." elements, so a fixture path always names one place inside the repository.
func Read ¶
Read returns the contents of the file at rel, a root-relative path as Path takes it. It fails the test when the file cannot be read.
func Root ¶
Root returns the repository root: FindRoot of the working directory, which go test sets to the directory of the package under test. It fails the test when there is no root.
func SkipDir ¶
SkipDir is the walk rule the repository-wide walks in tests share. It reports whether a walk from root should skip the directory at path: one whose name starts with ".", testdata, vendor, node_modules, or any directory below root that holds its own go.mod. It never skips root itself or an entry that is not a directory. Use it from a filepath.WalkDir callback by returning filepath.SkipDir when it reports true.
Types ¶
This section is empty.