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 <matt.fisher@microsoft.com>
pull/4934/head
Matthew Fisher 7 years ago
parent 14d856ff4e
commit 72765407a3
No known key found for this signature in database
GPG Key ID: 92AA783CBAAE8E3B

@ -86,7 +86,7 @@ func TestCreateStarterCmd(t *testing.T) {
defer testChdir(t, tdir)() defer testChdir(t, tdir)()
// Run a create // 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) t.Errorf("Failed to run create: %s", err)
return return
} }

@ -43,7 +43,7 @@ func TestDependencyBuildCmd(t *testing.T) {
t.Fatal(err) 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) out, err := executeCommand(nil, cmd)
// In the first pass, we basically want the same results as an update. // In the first pass, we basically want the same results as an update.

@ -52,7 +52,7 @@ func TestDependencyUpdateCmd(t *testing.T) {
t.Fatal(err) 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 { if err != nil {
t.Logf("Output: %s", out) t.Logf("Output: %s", out)
t.Fatal(err) t.Fatal(err)
@ -95,7 +95,7 @@ func TestDependencyUpdateCmd(t *testing.T) {
t.Fatal(err) 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 { if err != nil {
t.Logf("Output: %s", out) t.Logf("Output: %s", out)
t.Fatal(err) t.Fatal(err)
@ -133,7 +133,7 @@ func TestDependencyUpdateCmd_SkipRefresh(t *testing.T) {
t.Fatal(err) 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 { if err == nil {
t.Fatal("Expected failure to find the repo with skipRefresh") t.Fatal("Expected failure to find the repo with skipRefresh")
} }

@ -40,9 +40,6 @@ import (
"k8s.io/helm/pkg/storage/driver" "k8s.io/helm/pkg/storage/driver"
) )
// base temp directory
var testingDir string
func testTimestamper() time.Time { return time.Unix(242085845, 0).UTC() } func testTimestamper() time.Time { return time.Unix(242085845, 0).UTC() }
func init() { func init() {
@ -52,7 +49,6 @@ func init() {
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
os.Unsetenv("HELM_HOME") os.Unsetenv("HELM_HOME")
exitCode := m.Run() exitCode := m.Run()
os.RemoveAll(testingDir)
os.Exit(exitCode) os.Exit(exitCode)
} }
@ -62,7 +58,6 @@ func testTempDir(t *testing.T) string {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
testingDir = d
return d return d
} }

@ -46,7 +46,7 @@ func TestInstall(t *testing.T) {
// Install, values from yaml // Install, values from yaml
{ {
name: "install with values file", 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", golden: "output/install-with-values-file.txt",
}, },
// Install, no hooks // Install, no hooks

@ -17,10 +17,12 @@ package main
import ( import (
"bytes" "bytes"
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime"
"strings" "strings"
"testing" "testing"
@ -54,6 +56,13 @@ func TestSetVersion(t *testing.T) {
} }
func TestPackage(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()() defer resetEnv()()
tests := []struct { tests := []struct {
@ -115,7 +124,7 @@ func TestPackage(t *testing.T) {
name: "package --destination does-not-exist", name: "package --destination does-not-exist",
args: []string{"testdata/testcharts/alpine"}, args: []string{"testdata/testcharts/alpine"},
flags: map[string]string{"destination": "does-not-exist"}, 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, err: true,
}, },
{ {
@ -135,7 +144,7 @@ func TestPackage(t *testing.T) {
name: "package --values does-not-exist", name: "package --values does-not-exist",
args: []string{"testdata/testcharts/alpine"}, args: []string{"testdata/testcharts/alpine"},
flags: map[string]string{"values": "does-not-exist"}, 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, err: true,
}, },
} }

@ -129,7 +129,7 @@ func TestPullCmd(t *testing.T) {
os.RemoveAll(outdir) os.RemoveAll(outdir)
os.Mkdir(outdir, 0755) 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) out, err := executeCommand(nil, "fetch "+cmd)
if err != nil { if err != nil {
if tt.wantError { if tt.wantError {

@ -42,7 +42,7 @@ func TestRepoAddCmd(t *testing.T) {
tests := []cmdTestCase{{ tests := []cmdTestCase{{
name: "add a repository", 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", golden: "output/repo-add.txt",
}} }}

@ -20,6 +20,8 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
"k8s.io/client-go/util/homedir"
) )
func TestRootCmd(t *testing.T) { func TestRootCmd(t *testing.T) {
@ -32,7 +34,7 @@ func TestRootCmd(t *testing.T) {
{ {
name: "defaults", name: "defaults",
args: "home", args: "home",
home: filepath.Join(os.Getenv("HOME"), "/.helm"), home: filepath.Join(homedir.HomeDir(), ".helm"),
}, },
{ {
name: "with --home set", name: "with --home set",

@ -208,9 +208,10 @@ func (o *templateOptions) run(out io.Writer) error {
} }
in := func(needle string, haystack []string) bool { in := func(needle string, haystack []string) bool {
// make needle path absolute // make needle path absolute
d := strings.Split(needle, string(os.PathSeparator)) d := strings.Split(needle, "/")
dd := d[1:] dd := d[1:]
an := filepath.Join(o.chartPath, strings.Join(dd, string(os.PathSeparator))) an := filepath.Join(o.chartPath, strings.Join(dd, string(os.PathSeparator)))
fmt.Println(an)
for _, h := range haystack { for _, h := range haystack {
if h == an { if h == an {
@ -235,6 +236,7 @@ func (o *templateOptions) run(out io.Writer) error {
b := filepath.Base(m.Name) b := filepath.Base(m.Name)
switch { switch {
case len(o.renderFiles) > 0 && !in(m.Name, rf): case len(o.renderFiles) > 0 && !in(m.Name, rf):
fmt.Printf("%s not in %s\n", m.Name, rf)
continue continue
case !o.showNotes && b == "NOTES.txt": case !o.showNotes && b == "NOTES.txt":
continue continue

@ -17,6 +17,7 @@ limitations under the License.
package main package main
import ( import (
"fmt"
"path/filepath" "path/filepath"
"testing" "testing"
) )
@ -31,42 +32,42 @@ func TestTemplateCmd(t *testing.T) {
tests := []cmdTestCase{ tests := []cmdTestCase{
{ {
name: "check name", name: "check name",
cmd: "template " + chartPath, cmd: fmt.Sprintf("template '%s'", chartPath),
golden: "output/template.txt", golden: "output/template.txt",
}, },
{ {
name: "check set name", 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", golden: "output/template-set.txt",
}, },
{ {
name: "check execute absolute", 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", golden: "output/template-absolute.txt",
}, },
{ {
name: "check release name", name: "check release name",
cmd: "template --name test " + chartPath, cmd: fmt.Sprintf("template '%s' --name test", chartPath),
golden: "output/template-name.txt", golden: "output/template-name.txt",
}, },
{ {
name: "check notes", name: "check notes",
cmd: "template --notes " + chartPath, cmd: fmt.Sprintf("template '%s' --notes", chartPath),
golden: "output/template-notes.txt", golden: "output/template-notes.txt",
}, },
{ {
name: "check values files", 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", golden: "output/template-values-files.txt",
}, },
{ {
name: "check name template", 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", golden: "output/template-name-template.txt",
}, },
{ {
name: "check kube version", 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", golden: "output/template-kube-version.txt",
}, },
{ {

@ -17,6 +17,7 @@ limitations under the License.
package main package main
import ( import (
"fmt"
"testing" "testing"
"k8s.io/helm/pkg/chart" "k8s.io/helm/pkg/chart"
@ -89,55 +90,55 @@ func TestUpgradeCmd(t *testing.T) {
tests := []cmdTestCase{ tests := []cmdTestCase{
{ {
name: "upgrade a release", name: "upgrade a release",
cmd: "upgrade funny-bunny " + chartPath, cmd: fmt.Sprintf("upgrade funny-bunny '%s'", chartPath),
golden: "output/upgrade.txt", golden: "output/upgrade.txt",
rels: []*release.Release{relMock("funny-bunny", 2, ch)}, rels: []*release.Release{relMock("funny-bunny", 2, ch)},
}, },
{ {
name: "upgrade a release with timeout", 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", golden: "output/upgrade-with-timeout.txt",
rels: []*release.Release{relMock("funny-bunny", 3, ch2)}, rels: []*release.Release{relMock("funny-bunny", 3, ch2)},
}, },
{ {
name: "upgrade a release with --reset-values", 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", golden: "output/upgrade-with-reset-values.txt",
rels: []*release.Release{relMock("funny-bunny", 4, ch2)}, rels: []*release.Release{relMock("funny-bunny", 4, ch2)},
}, },
{ {
name: "upgrade a release with --reuse-values", 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", golden: "output/upgrade-with-reset-values2.txt",
rels: []*release.Release{relMock("funny-bunny", 5, ch2)}, rels: []*release.Release{relMock("funny-bunny", 5, ch2)},
}, },
{ {
name: "install a release with 'upgrade --install'", 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", golden: "output/upgrade-with-install.txt",
rels: []*release.Release{relMock("zany-bunny", 1, ch)}, rels: []*release.Release{relMock("zany-bunny", 1, ch)},
}, },
{ {
name: "install a release with 'upgrade --install' and timeout", 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", golden: "output/upgrade-with-install-timeout.txt",
rels: []*release.Release{relMock("crazy-bunny", 1, ch)}, rels: []*release.Release{relMock("crazy-bunny", 1, ch)},
}, },
{ {
name: "upgrade a release with wait", 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", golden: "output/upgrade-with-wait.txt",
rels: []*release.Release{relMock("crazy-bunny", 2, ch2)}, rels: []*release.Release{relMock("crazy-bunny", 2, ch2)},
}, },
{ {
name: "upgrade a release with missing dependencies", 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", golden: "output/upgrade-with-missing-dependencies.txt",
wantError: true, wantError: true,
}, },
{ {
name: "upgrade a release with bad dependencies", 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", golden: "output/upgrade-with-bad-dependencies.txt",
wantError: true, wantError: true,
}, },

@ -27,7 +27,7 @@ func TestVerifyCmd(t *testing.T) {
statPathMsg := "no such file or directory" statPathMsg := "no such file or directory"
statFileMsg := statPathMsg statFileMsg := statPathMsg
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
statExe = "GetFileAttributesEx" statExe = "FindFirstFile"
statPathMsg = "The system cannot find the path specified." statPathMsg = "The system cannot find the path specified."
statFileMsg = "The system cannot find the file specified." statFileMsg = "The system cannot find the file specified."
} }

@ -18,6 +18,7 @@ package getter
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"testing" "testing"
@ -67,6 +68,10 @@ func TestCollectPlugins(t *testing.T) {
} }
func TestPluginGetter(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") oldhh := os.Getenv("HELM_HOME")
defer os.Setenv("HELM_HOME", oldhh) defer os.Setenv("HELM_HOME", oldhh)
os.Setenv("HELM_HOME", "") os.Setenv("HELM_HOME", "")

Loading…
Cancel
Save