add testcase

Signed-off-by: zwwhdls <zwwhdls@hotmail.com>
pull/7188/head
zwwhdls 6 years ago
parent 835880bf12
commit 908f8316ed

@ -22,6 +22,7 @@ import (
"os"
"path/filepath"
"regexp"
"strings"
"testing"
"k8s.io/helm/pkg/repo/repotest"
@ -48,6 +49,9 @@ func TestFetchCmd(t *testing.T) {
chart string
flags []string
fail bool
wantErrorMsg string
existFile string
existDir string
failExpect string
expectFile string
expectDir bool
@ -98,11 +102,25 @@ func TestFetchCmd(t *testing.T) {
expectFile: "./signtest",
expectDir: true,
},
{
name: "Fetch untar when file with same name existed",
flags: []string{"test/test1 --untar --untardir test1"},
existFile: "test1",
fail: true,
wantErrorMsg: "failed to untar",
},
{
name: "Fetch untar when dir with same name existed",
flags: []string{"test/test2 --untar --untardir test2"},
existDir: "test2",
fail: true,
wantErrorMsg: "failed to untar",
},
{
name: "Fetch, verify, untar",
chart: "test/signtest",
flags: []string{"--verify", "--keyring", "testdata/helm-test-key.pub", "--untar", "--untardir", "signtest"},
expectFile: "./signtest",
flags: []string{"--verify", "--keyring", "testdata/helm-test-key.pub", "--untar", "--untardir", "signtest2"},
expectFile: "./signtest2",
expectDir: true,
expectVerify: true,
failExpect: "Failed to untar signtest",
@ -148,13 +166,31 @@ func TestFetchCmd(t *testing.T) {
os.RemoveAll(outdir)
os.Mkdir(outdir, 0755)
// Create file or Dir before helm pull --untar, see: https://github.com/helm/helm/issues/7182
if tt.existFile != "" {
file := filepath.Join(outdir, tt.existFile)
_, err := os.Create(file)
if err != nil {
t.Fatal("err")
}
}
if tt.existDir != "" {
file := filepath.Join(outdir, tt.existDir)
err := os.Mkdir(file, 0755)
if err != nil {
t.Fatal(err)
}
}
buf := bytes.NewBuffer(nil)
cmd := newFetchCmd(buf)
tt.flags = append(tt.flags, "-d", outdir)
cmd.ParseFlags(tt.flags)
if err := cmd.RunE(cmd, []string{tt.chart}); err != nil {
if tt.fail {
continue
if tt.wantErrorMsg != "" && strings.Contains(tt.wantErrorMsg, err.Error()) {
t.Fatalf("%q reported error not equel wantErr, reported: %s, wanted: %s", tt.name, err, tt.wantErrorMsg)
}
return
}
t.Errorf("%q reported error: %s", tt.name, err)
continue

Loading…
Cancel
Save