| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | // TestMain points HOME and XDG_CONFIG_HOME at an empty temp dir so no test |
| 9 | // reads the host's ~/.klaus/config.json. Tests that need a global config set |
| 10 | // their own HOME. |
| 11 | func TestMain(m *testing.M) { |
| 12 | home, err := os.MkdirTemp("", "klaus-config-test-home") |
| 13 | if err != nil { |
| 14 | panic(err) |
| 15 | } |
| 16 | os.Setenv("HOME", home) |
| 17 | os.Setenv("XDG_CONFIG_HOME", home+"/.config") |
| 18 | code := m.Run() |
| 19 | os.RemoveAll(home) |
| 20 | os.Exit(code) |
| 21 | } |