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)()
// 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
}

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

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

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

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

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

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

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

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

@ -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",
},
{

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

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

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

Loading…
Cancel
Save