fix(helmpath): fix syntax errors for windows tests

Signed-off-by: Adam Reese <adam@reese.io>
pull/6183/head
Adam Reese 5 years ago
parent cc5dece910
commit 4e625df328
No known key found for this signature in database
GPG Key ID: 06F35E60A7A18DD6

@ -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 {

@ -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

@ -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)

@ -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)

@ -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") }

@ -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))

Loading…
Cancel
Save