github.com/kruglovmax/helm@v3.0.0-beta.3+incompatible/pkg/helmpath/lazypath_windows_test.go (about) 1 // Copyright The Helm Authors. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 6 // http://www.apache.org/licenses/LICENSE-2.0 7 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 // +build windows 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/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(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(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(CacheHomeEnvVar) 74 os.Setenv("APPDATA", 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(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 }