Skip to content

Commit 39e3df9

Browse files
committed
test: make config path tests hermetic
1 parent b71ea57 commit 39e3df9

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

internal/cli/setup_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,15 +428,17 @@ func TestSetupUnsupportedShell(t *testing.T) {
428428

429429
func TestSetupFishSupported(t *testing.T) {
430430
home := t.TempDir()
431+
configHome := filepath.Join(home, ".config")
431432
t.Setenv("HOME", home)
433+
t.Setenv("XDG_CONFIG_HOME", configHome)
432434

433435
c, _, _ := newTestCLI(t)
434436
c.Hooks().ConfigPath = t.TempDir() + "/restish.json"
435437
err := c.Run([]string{"restish", "shell", "setup", "fish", "--yes"})
436438
if err != nil {
437439
t.Fatalf("expected fish setup to succeed, got: %v", err)
438440
}
439-
rcPath := filepath.Join(home, ".config", "fish", "config.fish")
441+
rcPath := filepath.Join(configHome, "fish", "config.fish")
440442
if _, statErr := os.Stat(rcPath); statErr != nil {
441443
t.Fatalf("expected fish config to be written: %v", statErr)
442444
}

internal/config/config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ func setLegacyConfigEnv(t *testing.T, home string) {
4040
if runtime.GOOS == "windows" {
4141
t.Setenv("USERPROFILE", home)
4242
t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming"))
43+
} else {
44+
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
4345
}
4446
}
4547

internal/config/migrate.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,21 @@ func legacyConfigDirs() []string {
8787
seen := map[string]bool{}
8888
var dirs []string
8989

90-
if userDir, err := os.UserConfigDir(); err == nil && userDir != "" {
91-
dir := filepath.Join(userDir, "restish")
92-
if !seen[dir] {
93-
seen[dir] = true
94-
dirs = append(dirs, dir)
90+
add := func(dir string) {
91+
if dir == "" || seen[dir] {
92+
return
9593
}
94+
seen[dir] = true
95+
dirs = append(dirs, dir)
9696
}
97-
if home, err := os.UserHomeDir(); err == nil && home != "" {
98-
dir := filepath.Join(home, ".config", "restish")
99-
if !seen[dir] {
100-
seen[dir] = true
101-
dirs = append(dirs, dir)
102-
}
97+
98+
if userDir, err := userConfigDirFunc(); err == nil && userDir != "" {
99+
dir := filepath.Join(userDir, "restish")
100+
add(dir)
101+
}
102+
if home, err := userHomeDirFunc(); err == nil && home != "" {
103+
add(filepath.Join(home, "Library", "Application Support", "restish"))
104+
add(filepath.Join(home, ".config", "restish"))
103105
}
104106
return dirs
105107
}

0 commit comments

Comments
 (0)