2020-08-10 23:25:49 +00:00
|
|
|
package pathutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestNormalizePath checks that NormalizePath returns the correct directory
|
|
|
|
func TestNormalizePath(t *testing.T) {
|
2020-08-13 21:09:36 +00:00
|
|
|
os.Setenv("XDG_CONFIG_HOME", "/tmp/.config")
|
|
|
|
|
2020-08-10 23:52:49 +00:00
|
|
|
home, _ := os.UserHomeDir()
|
|
|
|
configDir, _ := os.UserConfigDir()
|
2020-08-13 21:09:36 +00:00
|
|
|
|
2020-08-10 23:25:49 +00:00
|
|
|
cases := []struct {
|
2020-08-13 21:09:36 +00:00
|
|
|
in, out string
|
2020-08-10 23:25:49 +00:00
|
|
|
}{
|
2020-08-10 23:52:49 +00:00
|
|
|
{"~/.config/cointop/config.toml", filepath.Join(home, ".config/cointop/config.toml")},
|
2020-08-13 21:09:36 +00:00
|
|
|
{":HOME:/.cointop/config.toml", filepath.Join(home, "/.cointop/config.toml")},
|
|
|
|
{":PREFERRED_CONFIG_HOME:/cointop/config.toml", filepath.Join(configDir, "/cointop/config.toml")},
|
2020-08-10 23:25:49 +00:00
|
|
|
}
|
2020-08-11 16:48:49 +00:00
|
|
|
for _, c := range cases {
|
2020-08-10 23:25:49 +00:00
|
|
|
got := NormalizePath(c.in)
|
2020-08-13 21:09:36 +00:00
|
|
|
if got != c.out {
|
|
|
|
t.Errorf("NormalizePath(%q) == %q, want %q", c.in, got, c.out)
|
2020-08-10 23:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|