func withHostMap(t *testing.T, content string) {
dir := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", dir)
t.Setenv("HOME", dir)
if content != "" {
_ = os.MkdirAll(filepath.Join(dir, "tobi"), 0700)
_ = os.WriteFile(filepath.Join(dir, "tobi", "hosts.json"), []byte(content), 0600)
if content == "" {
return
}
// not the xdg layout: macos keeps its config under ~/Library
p := hostMapPath()
if p == "" {
t.Fatal("no config dir")
}
if err := os.MkdirAll(filepath.Dir(p), 0700); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(p, []byte(content), 0600); err != nil {
t.Fatal(err)
}
}
func TestHostMemory(t *testing.T) {
withHostMap(t, "")