1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package helmpath
17
18 import (
19 "os"
20 "path/filepath"
21 "testing"
22
23 "k8s.io/client-go/util/homedir"
24
25 "helm.sh/helm/v3/pkg/helmpath/xdg"
26 )
27
28 const (
29 appName = "helm"
30 testFile = "test.txt"
31 lazy = lazypath(appName)
32 )
33
34 func TestDataPath(t *testing.T) {
35 os.Unsetenv(xdg.DataHomeEnvVar)
36 os.Setenv("APPDATA", filepath.Join(homedir.HomeDir(), "foo"))
37
38 expected := filepath.Join(homedir.HomeDir(), "foo", appName, testFile)
39
40 if lazy.dataPath(testFile) != expected {
41 t.Errorf("expected '%s', got '%s'", expected, lazy.dataPath(testFile))
42 }
43
44 os.Setenv(xdg.DataHomeEnvVar, filepath.Join(homedir.HomeDir(), "xdg"))
45
46 expected = filepath.Join(homedir.HomeDir(), "xdg", appName, testFile)
47
48 if lazy.dataPath(testFile) != expected {
49 t.Errorf("expected '%s', got '%s'", expected, lazy.dataPath(testFile))
50 }
51 }
52
53 func TestConfigPath(t *testing.T) {
54 os.Unsetenv(xdg.ConfigHomeEnvVar)
55 os.Setenv("APPDATA", filepath.Join(homedir.HomeDir(), "foo"))
56
57 expected := filepath.Join(homedir.HomeDir(), "foo", appName, testFile)
58
59 if lazy.configPath(testFile) != expected {
60 t.Errorf("expected '%s', got '%s'", expected, lazy.configPath(testFile))
61 }
62
63 os.Setenv(xdg.ConfigHomeEnvVar, filepath.Join(homedir.HomeDir(), "xdg"))
64
65 expected = filepath.Join(homedir.HomeDir(), "xdg", appName, testFile)
66
67 if lazy.configPath(testFile) != expected {
68 t.Errorf("expected '%s', got '%s'", expected, lazy.configPath(testFile))
69 }
70 }
71
72 func TestCachePath(t *testing.T) {
73 os.Unsetenv(xdg.CacheHomeEnvVar)
74 os.Setenv("TEMP", filepath.Join(homedir.HomeDir(), "foo"))
75
76 expected := filepath.Join(homedir.HomeDir(), "foo", appName, testFile)
77
78 if lazy.cachePath(testFile) != expected {
79 t.Errorf("expected '%s', got '%s'", expected, lazy.cachePath(testFile))
80 }
81
82 os.Setenv(xdg.CacheHomeEnvVar, filepath.Join(homedir.HomeDir(), "xdg"))
83
84 expected = filepath.Join(homedir.HomeDir(), "xdg", appName, testFile)
85
86 if lazy.cachePath(testFile) != expected {
87 t.Errorf("expected '%s', got '%s'", expected, lazy.cachePath(testFile))
88 }
89 }
90
View as plain text