From 1e1db3f61d0f324c5efa956977db2e2910fd4673 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sat, 30 May 2020 09:40:59 +0200 Subject: [PATCH] internal: add gops subdirectory in ConfigDir (#112) Use a subdirectory of the directory returned by os.UserConfigDir instead of the UserConfigDir directly. This was missed in #103. Also add a test. Based on a change by @42wim submitted in #107 --- internal/internal.go | 2 +- internal/internal_test.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/internal.go b/internal/internal.go index 3ae0044..3e1f7eb 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -23,7 +23,7 @@ func ConfigDir() (string, error) { } if osUserConfigDir := getOSUserConfigDir(); osUserConfigDir != "" { - return osUserConfigDir, nil + return filepath.Join(osUserConfigDir, "gops"), nil } if runtime.GOOS == "windows" { diff --git a/internal/internal_test.go b/internal/internal_test.go index 6d86a3d..b08823b 100644 --- a/internal/internal_test.go +++ b/internal/internal_test.go @@ -2,17 +2,27 @@ package internal import ( "os" + "path/filepath" "testing" ) func TestConfigDir(t *testing.T) { + configDir, err := ConfigDir() + if err != nil { + t.Fatal(err) + } + + if g, w := filepath.Base(configDir), "gops"; g != w { + t.Errorf("ConfigDir: got base directory %q, want %q", g, w) + } + key := gopsConfigDirEnvKey oldDir := os.Getenv(key) defer os.Setenv(key, oldDir) newDir := "foo-bar" os.Setenv(key, newDir) - configDir, err := ConfigDir() + configDir, err = ConfigDir() if err != nil { t.Fatal(err) }