2017-11-13 09:52:04 +02:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2020-05-30 09:40:59 +02:00
|
|
|
"path/filepath"
|
2017-11-13 09:52:04 +02:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfigDir(t *testing.T) {
|
2020-05-30 09:40:59 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2017-11-13 09:52:04 +02:00
|
|
|
key := gopsConfigDirEnvKey
|
|
|
|
oldDir := os.Getenv(key)
|
|
|
|
defer os.Setenv(key, oldDir)
|
|
|
|
|
|
|
|
newDir := "foo-bar"
|
|
|
|
os.Setenv(key, newDir)
|
2020-05-30 09:40:59 +02:00
|
|
|
configDir, err = ConfigDir()
|
2017-11-13 09:52:04 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if g, w := configDir, newDir; g != w {
|
|
|
|
t.Errorf("ConfigDir: got=%v want=%v", g, w)
|
|
|
|
}
|
|
|
|
}
|