Skip to content

Commit

Permalink
Rewrite tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Fontein <felix@fontein.de>
  • Loading branch information
felixfontein committed Sep 21, 2023
1 parent 0dddcd2 commit e828588
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions age/keysource.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const (
// age keys file.
SopsAgeKeyFileEnv = "SOPS_AGE_KEY_FILE"
// SopsAgeKeyUserConfigPath is the default age keys file path in
// os.UserConfigDir.
// getUserConfigDir().
SopsAgeKeyUserConfigPath = "sops/age/keys.txt"
// On macOS, ignores os.UserConfigDir(). So we handle that manually.
// On macOS, os.UserConfigDir() ignores XDG_CONFIG_HOME. So we handle that manually.
xdgConfigHome = "XDG_CONFIG_HOME"
)

Expand Down
18 changes: 10 additions & 8 deletions age/keysource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,16 @@ func overwriteUserConfigDir(t *testing.T, path string) {
}
}

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

0 comments on commit e828588

Please sign in to comment.