From 923385c1ef874440dc5ec4d4ca317a9783dfda3e Mon Sep 17 00:00:00 2001 From: Steve Moyer Date: Tue, 17 Feb 2026 10:33:45 -0500 Subject: [PATCH] test(git-dir): make tests (more) OS-agnostic --- commands/execenv/loading_test.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/commands/execenv/loading_test.go b/commands/execenv/loading_test.go index 6b803395b6fe20259b445a4c0d2ff6969f5f6919..fb37043e8c1b13febf847761057d44642b2881c5 100644 --- a/commands/execenv/loading_test.go +++ b/commands/execenv/loading_test.go @@ -23,7 +23,8 @@ func TestGetRepoPath(t *testing.T) { }) t.Run("flag provided", func(t *testing.T) { - gitDir := filepath.Join(string(filepath.Separator), "tmp") + gitDir, err := os.UserHomeDir() + require.NoError(t, err) path, err := getRepoPath(&Env{ GitDir: gitDir, @@ -33,7 +34,8 @@ func TestGetRepoPath(t *testing.T) { }) t.Run("environment variable provided", func(t *testing.T) { - gitDir := filepath.Join(string(filepath.Separator), "tmp") + gitDir, err := os.UserHomeDir() + require.NoError(t, err) t.Setenv("GIT_DIR", gitDir) path, err := getRepoPath(&Env{}) @@ -42,17 +44,18 @@ func TestGetRepoPath(t *testing.T) { }) t.Run("GIT_DIR supercedes --git-dir", func(t *testing.T) { - homeDir, err := os.UserHomeDir() + cacheDir, err := os.UserCacheDir() require.NoError(t, err) - tmpDir := filepath.Join(string(filepath.Separator), "tmp") - t.Setenv("GIT_DIR", tmpDir) + configDir, err := os.UserConfigDir() + require.NoError(t, err) + t.Setenv("GIT_DIR", configDir) path, err := getRepoPath(&Env{ - GitDir: homeDir, + GitDir: cacheDir, }) require.NoError(t, err) - assert.Equal(t, tmpDir, path) + assert.Equal(t, configDir, path) })