gunk-dev/the-valley

config_main_test.go

source601b054bc28emain's published tip history
464 bytes
1package config
2
3import (
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.
11func 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}