Skip to content

Commit

Permalink
stop using XDG_CACHE_HOME as home directory (#299)
Browse files Browse the repository at this point in the history
* stop using XDG_CACHE_HOME as home directory

XDG_CACHE_HOME is not a substitute for $HOME, see [1].

[1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

* fix bats testing setup/teardown

since cmdutil.Homedir() would treat $XDG_CACHE_HOME as $HOME, deleting
$XDG_CACHE_HOME would wipe out previous kubens state. now that we're not
doing that, we need to make a real synthetic $HOME and clear it out so
that $HOME/.kube/kubens doesn't persist between runs.
  • Loading branch information
pjjw authored May 28, 2021
1 parent 34e9024 commit ff2f966
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
3 changes: 0 additions & 3 deletions internal/cmdutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import (
)

func HomeDir() string {
if v := os.Getenv("XDG_CACHE_HOME"); v != "" {
return v
}
home := os.Getenv("HOME")
if home == "" {
home = os.Getenv("USERPROFILE") // windows
Expand Down
6 changes: 2 additions & 4 deletions internal/cmdutil/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func Test_homeDir(t *testing.T) {
want string
}{
{
name: "XDG_CACHE_HOME precedence",
name: "don't use XDG_CACHE_HOME as homedir",
envs: []env{
{"XDG_CACHE_HOME", "xdg"},
{"HOME", "home"},
},
want: "xdg",
want: "home",
},
{
name: "HOME over USERPROFILE",
Expand All @@ -46,7 +46,6 @@ func Test_homeDir(t *testing.T) {
{
name: "only USERPROFILE available",
envs: []env{
{"XDG_CACHE_HOME", ""},
{"HOME", ""},
{"USERPROFILE", "up"},
},
Expand All @@ -55,7 +54,6 @@ func Test_homeDir(t *testing.T) {
{
name: "none available",
envs: []env{
{"XDG_CACHE_HOME", ""},
{"HOME", ""},
{"USERPROFILE", ""},
},
Expand Down
8 changes: 5 additions & 3 deletions test/common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

# bats setup function
setup() {
export XDG_CACHE_HOME="$(mktemp -d)"
export KUBECONFIG="${XDG_CACHE_HOME}/config"
TEMP_HOME="$(mktemp -d)"
export TEMP_HOME
export HOME=$TEMP_HOME
export KUBECONFIG="${TEMP_HOME}/config"
}

# bats teardown function
teardown() {
rm -rf "$XDG_CACHE_HOME"
rm -rf "$TEMP_HOME"
}

use_config() {
Expand Down

0 comments on commit ff2f966

Please sign in to comment.