37 lines
900 B
Go
37 lines
900 B
Go
package cli
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
// Tests supply their own overrides; inherited settings must not affect them.
|
|
for _, entry := range os.Environ() {
|
|
key, _, _ := strings.Cut(entry, "=")
|
|
if strings.HasPrefix(key, "AUDITA_") || key == "OPENROUTER_API_KEY" {
|
|
if err := os.Unsetenv(key); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
dir, err := os.MkdirTemp("", "audita-cli-test-config-")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer os.RemoveAll(dir)
|
|
configPath := filepath.Join(dir, "config.yml")
|
|
if err := os.WriteFile(configPath, []byte("version: 1\n"), 0600); err != nil {
|
|
panic(err)
|
|
}
|
|
// An explicit environment path prevents discovery of installed system config.
|
|
// Individual tests can still override it with t.Setenv or --config.
|
|
if err := os.Setenv("AUDITA_CONFIG", configPath); err != nil {
|
|
panic(err)
|
|
}
|
|
m.Run()
|
|
}
|