...
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
37 expected := filepath.Join(homedir.HomeDir(), ".local", "share", appName, testFile)
38
39 if lazy.dataPath(testFile) != expected {
40 t.Errorf("expected '%s', got '%s'", expected, lazy.dataPath(testFile))
41 }
42
43 os.Setenv(xdg.DataHomeEnvVar, "/tmp")
44
45 expected = filepath.Join("/tmp", appName, testFile)
46
47 if lazy.dataPath(testFile) != expected {
48 t.Errorf("expected '%s', got '%s'", expected, lazy.dataPath(testFile))
49 }
50 }
51
52 func TestConfigPath(t *testing.T) {
53 os.Unsetenv(xdg.ConfigHomeEnvVar)
54
55 expected := filepath.Join(homedir.HomeDir(), ".config", appName, testFile)
56
57 if lazy.configPath(testFile) != expected {
58 t.Errorf("expected '%s', got '%s'", expected, lazy.configPath(testFile))
59 }
60
61 os.Setenv(xdg.ConfigHomeEnvVar, "/tmp")
62
63 expected = filepath.Join("/tmp", appName, testFile)
64
65 if lazy.configPath(testFile) != expected {
66 t.Errorf("expected '%s', got '%s'", expected, lazy.configPath(testFile))
67 }
68 }
69
70 func TestCachePath(t *testing.T) {
71 os.Unsetenv(xdg.CacheHomeEnvVar)
72
73 expected := filepath.Join(homedir.HomeDir(), ".cache", appName, testFile)
74
75 if lazy.cachePath(testFile) != expected {
76 t.Errorf("expected '%s', got '%s'", expected, lazy.cachePath(testFile))
77 }
78
79 os.Setenv(xdg.CacheHomeEnvVar, "/tmp")
80
81 expected = filepath.Join("/tmp", appName, testFile)
82
83 if lazy.cachePath(testFile) != expected {
84 t.Errorf("expected '%s', got '%s'", expected, lazy.cachePath(testFile))
85 }
86 }
87
View as plain text