From 72765407a32558b48e441a7eeb5ddfe016fa4f36 Mon Sep 17 00:00:00 2001 From: Matthew Fisher Date: Wed, 30 Jan 2019 21:44:56 -0800 Subject: [PATCH] wrap filepaths in single quotes mattn/go-shellwords (used only in the root tests) doesn't like windows-style filepaths as arguments. Wrapping it in single quotes prevents go-shellwords from stripping all the forward slashes as escape codes. Signed-off-by: Matthew Fisher --- cmd/helm/create_test.go | 2 +- cmd/helm/dependency_build_test.go | 2 +- cmd/helm/dependency_update_test.go | 6 +++--- cmd/helm/helm_test.go | 5 ----- cmd/helm/install_test.go | 2 +- cmd/helm/package_test.go | 13 +++++++++++-- cmd/helm/pull_test.go | 2 +- cmd/helm/repo_add_test.go | 2 +- cmd/helm/root_test.go | 4 +++- cmd/helm/template.go | 4 +++- cmd/helm/template_test.go | 17 +++++++++-------- cmd/helm/upgrade_test.go | 19 ++++++++++--------- cmd/helm/verify_test.go | 2 +- pkg/getter/plugingetter_test.go | 5 +++++ 14 files changed, 50 insertions(+), 35 deletions(-) diff --git a/cmd/helm/create_test.go b/cmd/helm/create_test.go index c8f0365ec..8e1ce8386 100644 --- a/cmd/helm/create_test.go +++ b/cmd/helm/create_test.go @@ -86,7 +86,7 @@ func TestCreateStarterCmd(t *testing.T) { defer testChdir(t, tdir)() // Run a create - if _, err := executeCommand(nil, fmt.Sprintf("--home=%s create --starter=starterchart %s", hh.String(), cname)); err != nil { + if _, err := executeCommand(nil, fmt.Sprintf("--home='%s' create --starter=starterchart %s", hh.String(), cname)); err != nil { t.Errorf("Failed to run create: %s", err) return } diff --git a/cmd/helm/dependency_build_test.go b/cmd/helm/dependency_build_test.go index 5c2f004fb..64e32a4b3 100644 --- a/cmd/helm/dependency_build_test.go +++ b/cmd/helm/dependency_build_test.go @@ -43,7 +43,7 @@ func TestDependencyBuildCmd(t *testing.T) { t.Fatal(err) } - cmd := fmt.Sprintf("--home=%s dependency build %s", hh, hh.Path(chartname)) + cmd := fmt.Sprintf("--home='%s' dependency build '%s'", hh, hh.Path(chartname)) out, err := executeCommand(nil, cmd) // In the first pass, we basically want the same results as an update. diff --git a/cmd/helm/dependency_update_test.go b/cmd/helm/dependency_update_test.go index 3d5d6bea6..fba560ee8 100644 --- a/cmd/helm/dependency_update_test.go +++ b/cmd/helm/dependency_update_test.go @@ -52,7 +52,7 @@ func TestDependencyUpdateCmd(t *testing.T) { t.Fatal(err) } - out, err := executeCommand(nil, fmt.Sprintf("--home=%s dependency update %s", hh.String(), hh.Path(chartname))) + out, err := executeCommand(nil, fmt.Sprintf("--home='%s' dependency update '%s'", hh.String(), hh.Path(chartname))) if err != nil { t.Logf("Output: %s", out) t.Fatal(err) @@ -95,7 +95,7 @@ func TestDependencyUpdateCmd(t *testing.T) { t.Fatal(err) } - out, err = executeCommand(nil, fmt.Sprintf("--home=%s dependency update %s", hh, hh.Path(chartname))) + out, err = executeCommand(nil, fmt.Sprintf("--home='%s' dependency update '%s'", hh, hh.Path(chartname))) if err != nil { t.Logf("Output: %s", out) t.Fatal(err) @@ -133,7 +133,7 @@ func TestDependencyUpdateCmd_SkipRefresh(t *testing.T) { t.Fatal(err) } - out, err := executeCommand(nil, fmt.Sprintf("--home=%s dependency update --skip-refresh %s", hh, hh.Path(chartname))) + out, err := executeCommand(nil, fmt.Sprintf("--home='%s' dependency update --skip-refresh %s", hh, hh.Path(chartname))) if err == nil { t.Fatal("Expected failure to find the repo with skipRefresh") } diff --git a/cmd/helm/helm_test.go b/cmd/helm/helm_test.go index 4b2d4fc5a..6d2d63fc9 100644 --- a/cmd/helm/helm_test.go +++ b/cmd/helm/helm_test.go @@ -40,9 +40,6 @@ import ( "k8s.io/helm/pkg/storage/driver" ) -// base temp directory -var testingDir string - func testTimestamper() time.Time { return time.Unix(242085845, 0).UTC() } func init() { @@ -52,7 +49,6 @@ func init() { func TestMain(m *testing.M) { os.Unsetenv("HELM_HOME") exitCode := m.Run() - os.RemoveAll(testingDir) os.Exit(exitCode) } @@ -62,7 +58,6 @@ func testTempDir(t *testing.T) string { if err != nil { t.Fatal(err) } - testingDir = d return d } diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go index 69635aa4d..9606a4d00 100644 --- a/cmd/helm/install_test.go +++ b/cmd/helm/install_test.go @@ -46,7 +46,7 @@ func TestInstall(t *testing.T) { // Install, values from yaml { name: "install with values file", - cmd: "install virgil testdata/testcharts/alpine -f testdata/testcharts/alpine/extra_values.yaml", + cmd: "install virgil testdata/testcharts/alpine -f testdata/testcharts/alpine/extra_values.yaml", golden: "output/install-with-values-file.txt", }, // Install, no hooks diff --git a/cmd/helm/package_test.go b/cmd/helm/package_test.go index fb032bc4b..f6a35ac77 100644 --- a/cmd/helm/package_test.go +++ b/cmd/helm/package_test.go @@ -17,10 +17,12 @@ package main import ( "bytes" + "fmt" "io/ioutil" "os" "path/filepath" "regexp" + "runtime" "strings" "testing" @@ -54,6 +56,13 @@ func TestSetVersion(t *testing.T) { } func TestPackage(t *testing.T) { + statExe := "stat" + statFileMsg := "no such file or directory" + if runtime.GOOS == "windows" { + statExe = "FindFirstFile" + statFileMsg = "The system cannot find the file specified." + } + defer resetEnv()() tests := []struct { @@ -115,7 +124,7 @@ func TestPackage(t *testing.T) { name: "package --destination does-not-exist", args: []string{"testdata/testcharts/alpine"}, flags: map[string]string{"destination": "does-not-exist"}, - expect: "stat does-not-exist: no such file or directory", + expect: fmt.Sprintf("failed to save: %s does-not-exist: %s", statExe, statFileMsg), err: true, }, { @@ -135,7 +144,7 @@ func TestPackage(t *testing.T) { name: "package --values does-not-exist", args: []string{"testdata/testcharts/alpine"}, flags: map[string]string{"values": "does-not-exist"}, - expect: "does-not-exist: no such file or directory", + expect: fmt.Sprintf("does-not-exist: %s", statFileMsg), err: true, }, } diff --git a/cmd/helm/pull_test.go b/cmd/helm/pull_test.go index cd09b26cb..f837df627 100644 --- a/cmd/helm/pull_test.go +++ b/cmd/helm/pull_test.go @@ -129,7 +129,7 @@ func TestPullCmd(t *testing.T) { os.RemoveAll(outdir) os.Mkdir(outdir, 0755) - cmd := strings.Join(append(tt.args, "-d", outdir, "--home", hh.String()), " ") + cmd := strings.Join(append(tt.args, "-d", "'"+outdir+"'", "--home", "'"+hh.String()+"'"), " ") out, err := executeCommand(nil, "fetch "+cmd) if err != nil { if tt.wantError { diff --git a/cmd/helm/repo_add_test.go b/cmd/helm/repo_add_test.go index 9de2be773..be320bc7c 100644 --- a/cmd/helm/repo_add_test.go +++ b/cmd/helm/repo_add_test.go @@ -42,7 +42,7 @@ func TestRepoAddCmd(t *testing.T) { tests := []cmdTestCase{{ name: "add a repository", - cmd: fmt.Sprintf("repo add test-name %s --home %s", srv.URL(), hh), + cmd: fmt.Sprintf("repo add test-name %s --home '%s'", srv.URL(), hh), golden: "output/repo-add.txt", }} diff --git a/cmd/helm/root_test.go b/cmd/helm/root_test.go index bd41b6ab6..163b24bb6 100644 --- a/cmd/helm/root_test.go +++ b/cmd/helm/root_test.go @@ -20,6 +20,8 @@ import ( "os" "path/filepath" "testing" + + "k8s.io/client-go/util/homedir" ) func TestRootCmd(t *testing.T) { @@ -32,7 +34,7 @@ func TestRootCmd(t *testing.T) { { name: "defaults", args: "home", - home: filepath.Join(os.Getenv("HOME"), "/.helm"), + home: filepath.Join(homedir.HomeDir(), ".helm"), }, { name: "with --home set", diff --git a/cmd/helm/template.go b/cmd/helm/template.go index 44285cb1a..e1b1b3385 100644 --- a/cmd/helm/template.go +++ b/cmd/helm/template.go @@ -208,9 +208,10 @@ func (o *templateOptions) run(out io.Writer) error { } in := func(needle string, haystack []string) bool { // make needle path absolute - d := strings.Split(needle, string(os.PathSeparator)) + d := strings.Split(needle, "/") dd := d[1:] an := filepath.Join(o.chartPath, strings.Join(dd, string(os.PathSeparator))) + fmt.Println(an) for _, h := range haystack { if h == an { @@ -235,6 +236,7 @@ func (o *templateOptions) run(out io.Writer) error { b := filepath.Base(m.Name) switch { case len(o.renderFiles) > 0 && !in(m.Name, rf): + fmt.Printf("%s not in %s\n", m.Name, rf) continue case !o.showNotes && b == "NOTES.txt": continue diff --git a/cmd/helm/template_test.go b/cmd/helm/template_test.go index 417030d1c..6dcc71fa3 100644 --- a/cmd/helm/template_test.go +++ b/cmd/helm/template_test.go @@ -17,6 +17,7 @@ limitations under the License. package main import ( + "fmt" "path/filepath" "testing" ) @@ -31,42 +32,42 @@ func TestTemplateCmd(t *testing.T) { tests := []cmdTestCase{ { name: "check name", - cmd: "template " + chartPath, + cmd: fmt.Sprintf("template '%s'", chartPath), golden: "output/template.txt", }, { name: "check set name", - cmd: "template -x templates/service.yaml --set service.name=apache " + chartPath, + cmd: fmt.Sprintf("template '%s' -x '%s' --set service.name=apache", chartPath, filepath.Join("templates", "service.yaml")), golden: "output/template-set.txt", }, { name: "check execute absolute", - cmd: "template -x " + absChartPath + "/templates/service.yaml --set service.name=apache " + chartPath, + cmd: fmt.Sprintf("template '%s' -x '%s' --set service.name=apache", chartPath, filepath.Join(absChartPath, "templates", "service.yaml")), golden: "output/template-absolute.txt", }, { name: "check release name", - cmd: "template --name test " + chartPath, + cmd: fmt.Sprintf("template '%s' --name test", chartPath), golden: "output/template-name.txt", }, { name: "check notes", - cmd: "template --notes " + chartPath, + cmd: fmt.Sprintf("template '%s' --notes", chartPath), golden: "output/template-notes.txt", }, { name: "check values files", - cmd: "template --values " + chartPath + "/charts/subchartA/values.yaml " + chartPath, + cmd: fmt.Sprintf("template '%s' --values '%s'", chartPath, filepath.Join(chartPath, "/charts/subchartA/values.yaml")), golden: "output/template-values-files.txt", }, { name: "check name template", - cmd: `template --name-template='foobar-{{ b64enc "abc" }}-baz' ` + chartPath, + cmd: fmt.Sprintf(`template '%s' --name-template='foobar-{{ b64enc "abc" }}-baz'`, chartPath), golden: "output/template-name-template.txt", }, { name: "check kube version", - cmd: "template --kube-version 1.6 " + chartPath, + cmd: fmt.Sprintf("template '%s' --kube-version 1.6", chartPath), golden: "output/template-kube-version.txt", }, { diff --git a/cmd/helm/upgrade_test.go b/cmd/helm/upgrade_test.go index 15b4067c8..c45f77026 100644 --- a/cmd/helm/upgrade_test.go +++ b/cmd/helm/upgrade_test.go @@ -17,6 +17,7 @@ limitations under the License. package main import ( + "fmt" "testing" "k8s.io/helm/pkg/chart" @@ -89,55 +90,55 @@ func TestUpgradeCmd(t *testing.T) { tests := []cmdTestCase{ { name: "upgrade a release", - cmd: "upgrade funny-bunny " + chartPath, + cmd: fmt.Sprintf("upgrade funny-bunny '%s'", chartPath), golden: "output/upgrade.txt", rels: []*release.Release{relMock("funny-bunny", 2, ch)}, }, { name: "upgrade a release with timeout", - cmd: "upgrade funny-bunny --timeout 120 " + chartPath, + cmd: fmt.Sprintf("upgrade funny-bunny --timeout 120 '%s'", chartPath), golden: "output/upgrade-with-timeout.txt", rels: []*release.Release{relMock("funny-bunny", 3, ch2)}, }, { name: "upgrade a release with --reset-values", - cmd: "upgrade funny-bunny --reset-values " + chartPath, + cmd: fmt.Sprintf("upgrade funny-bunny --reset-values '%s'", chartPath), golden: "output/upgrade-with-reset-values.txt", rels: []*release.Release{relMock("funny-bunny", 4, ch2)}, }, { name: "upgrade a release with --reuse-values", - cmd: "upgrade funny-bunny --reuse-values " + chartPath, + cmd: fmt.Sprintf("upgrade funny-bunny --reuse-values '%s'", chartPath), golden: "output/upgrade-with-reset-values2.txt", rels: []*release.Release{relMock("funny-bunny", 5, ch2)}, }, { name: "install a release with 'upgrade --install'", - cmd: "upgrade zany-bunny -i " + chartPath, + cmd: fmt.Sprintf("upgrade zany-bunny -i '%s'", chartPath), golden: "output/upgrade-with-install.txt", rels: []*release.Release{relMock("zany-bunny", 1, ch)}, }, { name: "install a release with 'upgrade --install' and timeout", - cmd: "upgrade crazy-bunny -i --timeout 120 " + chartPath, + cmd: fmt.Sprintf("upgrade crazy-bunny -i --timeout 120 '%s'", chartPath), golden: "output/upgrade-with-install-timeout.txt", rels: []*release.Release{relMock("crazy-bunny", 1, ch)}, }, { name: "upgrade a release with wait", - cmd: "upgrade crazy-bunny --wait " + chartPath, + cmd: fmt.Sprintf("upgrade crazy-bunny --wait '%s'", chartPath), golden: "output/upgrade-with-wait.txt", rels: []*release.Release{relMock("crazy-bunny", 2, ch2)}, }, { name: "upgrade a release with missing dependencies", - cmd: "upgrade bonkers-bunny" + missingDepsPath, + cmd: fmt.Sprintf("upgrade bonkers-bunny%s", missingDepsPath), golden: "output/upgrade-with-missing-dependencies.txt", wantError: true, }, { name: "upgrade a release with bad dependencies", - cmd: "upgrade bonkers-bunny " + badDepsPath, + cmd: fmt.Sprintf("upgrade bonkers-bunny '%s'", badDepsPath), golden: "output/upgrade-with-bad-dependencies.txt", wantError: true, }, diff --git a/cmd/helm/verify_test.go b/cmd/helm/verify_test.go index f4ddc42f1..4d01c61b9 100644 --- a/cmd/helm/verify_test.go +++ b/cmd/helm/verify_test.go @@ -27,7 +27,7 @@ func TestVerifyCmd(t *testing.T) { statPathMsg := "no such file or directory" statFileMsg := statPathMsg if runtime.GOOS == "windows" { - statExe = "GetFileAttributesEx" + statExe = "FindFirstFile" statPathMsg = "The system cannot find the path specified." statFileMsg = "The system cannot find the file specified." } diff --git a/pkg/getter/plugingetter_test.go b/pkg/getter/plugingetter_test.go index 9bfe6144d..7c0bd6c1e 100644 --- a/pkg/getter/plugingetter_test.go +++ b/pkg/getter/plugingetter_test.go @@ -18,6 +18,7 @@ package getter import ( "os" "path/filepath" + "runtime" "strings" "testing" @@ -67,6 +68,10 @@ func TestCollectPlugins(t *testing.T) { } func TestPluginGetter(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("TODO: refactor this test to work on windows") + } + oldhh := os.Getenv("HELM_HOME") defer os.Setenv("HELM_HOME", oldhh) os.Setenv("HELM_HOME", "")