Isolate CLI tests from host configuration

This commit is contained in:
2026-09-22 18:25:46 +00:00
parent 4e4801dc98
commit 588ca36dfc
3 changed files with 55 additions and 1 deletions

View File

@@ -571,6 +571,15 @@ func runCLISubprocessContext(t *testing.T, ctx context.Context, extraEnv map[str
cmdArgs := append([]string{"-test.run=TestHelperProcess", "--"}, args...)
cmd := exec.CommandContext(ctx, os.Args[0], cmdArgs...)
env := append(filterAuditaEnv(os.Environ()), "GO_WANT_HELPER_PROCESS=1")
// Use defaults without discovering the host's installed configuration.
// Explicit test environment overrides and --config retain their precedence.
if _, supplied := extraEnv["AUDITA_CONFIG"]; !supplied {
configPath := filepath.Join(t.TempDir(), "config.yml")
if err := os.WriteFile(configPath, []byte("version: 1\n"), 0600); err != nil {
t.Fatalf("write baseline config: %v", err)
}
env = append(env, "AUDITA_CONFIG="+configPath)
}
for k, v := range extraEnv {
env = append(env, fmt.Sprintf("%s=%s", k, v))
}