Documentation
¶
Overview ¶
Package testutil holds the test helpers that tests of many packages need and that need nothing of AgentKit: file trees, a git environment that ignores the machine's configuration, polling with a deadline, JSON, tar, golden files, the repository root, and running a program with `go run`.
It imports only the standard library, so the tests of every package, the root's and the nested modules' alike, can use it. Test doubles over core (a scripted provider, an echo tool) are in internal/testkit.
Index ¶
- func Environ(drop ...string) map[string]string
- func Eventually(t testing.TB, what string, cond func() bool)
- func Golden(t testing.TB, path string, got []byte)
- func Hermetic(t *testing.T)
- func MustJSON(t testing.TB, v any) string
- func Object(t testing.TB, b []byte) map[string]any
- func RepoRoot(t testing.TB) string
- func SameJSON(a, b []byte) bool
- func Tree(t testing.TB, files map[string]string) string
- func Within(d time.Duration, cond func() bool) bool
- func WriteTree(t testing.TB, dir string, files map[string]string)
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Environ ¶
Environ is the test process's environment as a map, without the variables named in drop.
func Eventually ¶
Eventually fails t unless cond holds within five seconds; what names the condition in the failure.
func Golden ¶
Golden compares got with the file at path. Run with -update to rewrite the file instead; the diff is then reviewed, not blessed, since a golden regenerated from the output it checks proves nothing.
func Hermetic ¶
Hermetic points HOME, XDG_CONFIG_HOME and git's global and system configuration at empty places for the rest of the test, so that what git and the ignore rules read does not depend on whose machine runs it.
func Object ¶
Object decodes b as a JSON object, numbers as json.Number, the form schema.Validate and the tools' Data take.
func RepoRoot ¶
RepoRoot is the repository's root directory: the nearest ancestor of the working directory whose go.mod declares the root module.
func SameJSON ¶
SameJSON reports whether a and b are the same JSON value, whatever their spacing and key order.
Types ¶
type Result ¶
A Result is what a program run with GoRun printed and its exit code.