mirror of
https://github.com/google/gops.git
synced 2024-11-24 08:22:25 +02:00
1e1db3f61d
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
34 lines
574 B
Go
34 lines
574 B
Go
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()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if g, w := configDir, newDir; g != w {
|
|
t.Errorf("ConfigDir: got=%v want=%v", g, w)
|
|
}
|
|
}
|