Isolate CLI tests from host configuration
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user