Skip to content

Commit e828588

Browse files
committed
Rewrite tests.
Signed-off-by: Felix Fontein <felix@fontein.de>
1 parent 0dddcd2 commit e828588

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

age/keysource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ const (
2424
// age keys file.
2525
SopsAgeKeyFileEnv = "SOPS_AGE_KEY_FILE"
2626
// SopsAgeKeyUserConfigPath is the default age keys file path in
27-
// os.UserConfigDir.
27+
// getUserConfigDir().
2828
SopsAgeKeyUserConfigPath = "sops/age/keys.txt"
29-
// On macOS, ignores os.UserConfigDir(). So we handle that manually.
29+
// On macOS, os.UserConfigDir() ignores XDG_CONFIG_HOME. So we handle that manually.
3030
xdgConfigHome = "XDG_CONFIG_HOME"
3131
)
3232

age/keysource_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,16 @@ func overwriteUserConfigDir(t *testing.T, path string) {
387387
}
388388
}
389389

390+
// Make sure that on all supported platforms but Windows, XDG_CONFIG_HOME
391+
// can be used to specify the user's home directory. For most platforms
392+
// this is handled by Go's os.UserConfigDir(), but for Darwin our code
393+
// in getUserConfigDir() handles this explicitly.
390394
func TestUserConfigDir(t *testing.T) {
391-
const dir = "/test/home/dir"
392-
overwriteUserConfigDir(t, dir)
393-
expectedDir := dir
394-
if runtime.GOOS == "plan9" {
395-
expectedDir += "/lib"
395+
if runtime.GOOS != "windows" {
396+
const dir = "/test/home/dir"
397+
t.Setenv("XDG_CONFIG_HOME", dir)
398+
home, err := getUserConfigDir()
399+
assert.Nil(t, err)
400+
assert.Equal(t, home, dir)
396401
}
397-
home, err := getUserConfigDir()
398-
assert.Nil(t, err)
399-
assert.Equal(t, home, dir)
400402
}

0 commit comments

Comments
 (0)