1
0
mirror of https://github.com/google/gops.git synced 2025-02-19 19:59:55 +02:00

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
This commit is contained in:
Tobias Klauser 2020-05-30 09:40:59 +02:00 committed by GitHub
parent 38c00cd8c2
commit 1e1db3f61d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -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" {

View File

@ -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)
}