From 4e625df3285ebcef3782c07f8b10817af7ef4515 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Thu, 8 Aug 2019 10:07:56 -0700 Subject: [PATCH] fix(helmpath): fix syntax errors for windows tests Signed-off-by: Adam Reese --- pkg/helmpath/home.go | 2 +- pkg/helmpath/lazypath.go | 8 ++------ pkg/helmpath/lazypath_darwin_test.go | 10 +++++----- pkg/helmpath/lazypath_unix_test.go | 7 +++---- pkg/helmpath/lazypath_windows.go | 12 +++--------- pkg/helmpath/lazypath_windows_test.go | 21 +++++++++++---------- 6 files changed, 25 insertions(+), 35 deletions(-) diff --git a/pkg/helmpath/home.go b/pkg/helmpath/home.go index 7de824dc5..9c9fe9379 100644 --- a/pkg/helmpath/home.go +++ b/pkg/helmpath/home.go @@ -19,7 +19,7 @@ import ( ) // This helper builds paths to Helm's configuration, cache and data paths. -var lp = lazypath{name: "helm"} +const lp = lazypath("helm") // ConfigPath returns the path where Helm stores configuration. func ConfigPath() string { diff --git a/pkg/helmpath/lazypath.go b/pkg/helmpath/lazypath.go index 842f93923..39d349552 100644 --- a/pkg/helmpath/lazypath.go +++ b/pkg/helmpath/lazypath.go @@ -20,18 +20,14 @@ import ( ) // lazypath is an lazy-loaded path buffer for the XDG base directory specification. -// -// name is the base name of the application referenced in the base directories. -type lazypath struct { - name string -} +type lazypath string func (l lazypath) path(envVar string, defaultFn func() string, file string) string { base := os.Getenv(envVar) if base == "" { base = defaultFn() } - return filepath.Join(base, l.name, file) + return filepath.Join(base, string(l), file) } // cachePath defines the base directory relative to which user specific non-essential data files diff --git a/pkg/helmpath/lazypath_darwin_test.go b/pkg/helmpath/lazypath_darwin_test.go index bf222ec4b..ce5240c4e 100644 --- a/pkg/helmpath/lazypath_darwin_test.go +++ b/pkg/helmpath/lazypath_darwin_test.go @@ -20,17 +20,17 @@ import ( "path/filepath" "testing" - "helm.sh/helm/pkg/helmpath/xdg" "k8s.io/client-go/util/homedir" + + "helm.sh/helm/pkg/helmpath/xdg" ) const ( - appName string = "helm" - testFile string = "test.txt" + appName = "helm" + testFile = "test.txt" + lazy = lazypath(appName) ) -var lazy = lazypath{name: appName} - func TestDataPath(t *testing.T) { os.Unsetenv(xdg.DataHomeEnvVar) diff --git a/pkg/helmpath/lazypath_unix_test.go b/pkg/helmpath/lazypath_unix_test.go index f465ead75..34a1dfff5 100644 --- a/pkg/helmpath/lazypath_unix_test.go +++ b/pkg/helmpath/lazypath_unix_test.go @@ -26,12 +26,11 @@ import ( ) const ( - appName string = "helm" - testFile string = "test.txt" + appName = "helm" + testFile = "test.txt" + lazy = lazypath(appName) ) -var lazy = lazypath{name: appName} - func TestDataPath(t *testing.T) { os.Unsetenv(xdg.DataHomeEnvVar) diff --git a/pkg/helmpath/lazypath_windows.go b/pkg/helmpath/lazypath_windows.go index 38d9dec9a..057a3af14 100644 --- a/pkg/helmpath/lazypath_windows.go +++ b/pkg/helmpath/lazypath_windows.go @@ -17,14 +17,8 @@ package helmpath import "os" -func dataHome() string { - return configHome() -} +func dataHome() string { return configHome() } -func configHome() string { - return os.Getenv("APPDATA") -} +func configHome() string { return os.Getenv("APPDATA") } -func cacheHome() string { - return os.Getenv("TEMP") -} +func cacheHome() string { return os.Getenv("TEMP") } diff --git a/pkg/helmpath/lazypath_windows_test.go b/pkg/helmpath/lazypath_windows_test.go index 92f5a7be9..c82430a27 100644 --- a/pkg/helmpath/lazypath_windows_test.go +++ b/pkg/helmpath/lazypath_windows_test.go @@ -21,15 +21,16 @@ import ( "testing" "k8s.io/client-go/util/homedir" + + "helm.sh/helm/pkg/helmpath/xdg" ) const ( - appName string = "helm" - testFile string = "test.txt" + appName = "helm" + testFile = "test.txt" + lazy = lazypath(appName) ) -var lazy = lazypath{name: appName} - func TestDataPath(t *testing.T) { os.Unsetenv(DataHomeEnvVar) os.Setenv("APPDATA", filepath.Join(homedir.HomeDir(), "foo")) @@ -40,9 +41,9 @@ func TestDataPath(t *testing.T) { t.Errorf("expected '%s', got '%s'", expected, lazy.dataPath(testFile)) } - os.Setenv(DataHomeEnvVar, filepath.Join(homedir.HomeDir(), "xdg"))) + os.Setenv(DataHomeEnvVar, filepath.Join(homedir.HomeDir(), "xdg")) - expected = filepath.Join(homedir.HomeDir(), "xdg" appName, testFile) + expected = filepath.Join(homedir.HomeDir(), "xdg", appName, testFile) if lazy.dataPath(testFile) != expected { t.Errorf("expected '%s', got '%s'", expected, lazy.dataPath(testFile)) @@ -59,9 +60,9 @@ func TestConfigPath(t *testing.T) { t.Errorf("expected '%s', got '%s'", expected, lazy.configPath(testFile)) } - os.Setenv(xdg.ConfigHomeEnvVar, filepath.Join(homedir.HomeDir(), "xdg"))) + os.Setenv(xdg.ConfigHomeEnvVar, filepath.Join(homedir.HomeDir(), "xdg")) - expected = filepath.Join(homedir.HomeDir(), "xdg" appName, testFile) + expected = filepath.Join(homedir.HomeDir(), "xdg", appName, testFile) if lazy.configPath(testFile) != expected { t.Errorf("expected '%s', got '%s'", expected, lazy.configPath(testFile)) @@ -78,9 +79,9 @@ func TestCachePath(t *testing.T) { t.Errorf("expected '%s', got '%s'", expected, lazy.cachePath(testFile)) } - os.Setenv(CacheHomeEnvVar, filepath.Join(homedir.HomeDir(), "xdg"))) + os.Setenv(CacheHomeEnvVar, filepath.Join(homedir.HomeDir(), "xdg")) - expected = filepath.Join(homedir.HomeDir(), "xdg" appName, testFile) + expected = filepath.Join(homedir.HomeDir(), "xdg", appName, testFile) if lazy.cachePath(testFile) != expected { t.Errorf("expected '%s', got '%s'", expected, lazy.cachePath(testFile))