The testutil package provides shared test helpers for isolating test artifacts and capturing output.
This package is imported only in test files (_test.go). It provides:
- A shared, isolated temporary directory for each test run (outside the git repository).
- Per-test subdirectories that are cleaned up automatically.
- Helpers for capturing
os.Stderroutput during tests. - A helper for stripping YAML comment headers from compiled workflow output.
Returns the path to the unique top-level directory for the current test run. It is created once per process under $TMPDIR/gh-aw-test-runs/<timestamp>-<pid>. Using a directory outside the repository prevents git commands from interfering with test artifacts.
dir := testutil.GetTestRunDir()
// e.g. /tmp/gh-aw-test-runs/20240101-120000-12345Creates a temporary subdirectory inside the test run directory matching pattern. The directory is automatically removed when the test completes via t.Cleanup.
func TestCompile(t *testing.T) {
dir := testutil.TempDir(t, "compile-*")
// Use dir for test artifacts; cleaned up automatically
}Runs fn and returns everything written to os.Stderr during its execution. os.Stderr is restored automatically via t.Cleanup.
func TestWarningMessage(t *testing.T) {
output := testutil.CaptureStderr(t, func() {
myFunction() // writes to os.Stderr
})
assert.Contains(t, output, "expected warning")
}Removes the leading comment block from a generated YAML file and returns only the non-comment content. Useful for tests that need to verify compiled output without matching the auto-generated header.
raw, _ := os.ReadFile("workflow.lock.yml")
yaml := testutil.StripYAMLCommentHeader(string(raw))
assert.Contains(t, yaml, "runs-on: ubuntu-latest")GetTestRunDirusessync.Onceso the directory is created exactly once per process even when multiple test packages run concurrently.TempDirdelegates toos.MkdirTempto generate unique subdirectory names.- Test artifacts placed in the test run directory are outside any git repository, which prevents
gitcommands executed by tests from picking them up as untracked files.