complete testCase when file/dir existed.

Signed-off-by: zwwhdls <zwwhdls@hotmail.com>
pull/7187/head
zwwhdls 6 years ago
parent 2bdea5ae14
commit b6a174d4bc

@ -21,6 +21,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings"
"testing" "testing"
"helm.sh/helm/v3/pkg/repo/repotest" "helm.sh/helm/v3/pkg/repo/repotest"
@ -41,7 +42,10 @@ func TestPullCmd(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
args string args string
existFile string
existDir string
wantError bool wantError bool
wantErrorMsg string
failExpect string failExpect string
expectFile string expectFile string
expectDir bool expectDir bool
@ -87,14 +91,26 @@ func TestPullCmd(t *testing.T) {
expectFile: "./signtest", expectFile: "./signtest",
expectDir: true, expectDir: true,
}, },
{
name: "Fetch untar when file with same name existed",
args: "test/test1 --untar --untardir test1",
existFile: "test1",
wantError: true,
wantErrorMsg: "failed to untar",
},
{
name: "Fetch untar when dir with same name existed",
args: "test/test2 --untar --untardir test2",
existDir: "test2",
wantError: true,
wantErrorMsg: "failed to untar",
},
{ {
name: "Fetch, verify, untar", name: "Fetch, verify, untar",
args: "test/signtest --verify --keyring=testdata/helm-test-key.pub --untar --untardir signtest", args: "test/signtest --verify --keyring=testdata/helm-test-key.pub --untar --untardir signtest2",
expectFile: "./signtest", expectFile: "./signtest2",
expectDir: true, expectDir: true,
expectVerify: true, expectVerify: true,
failExpect: "Failed to untar signtest",
wantError: true,
}, },
{ {
name: "Chart fetch using repo URL", name: "Chart fetch using repo URL",
@ -129,9 +145,27 @@ func TestPullCmd(t *testing.T) {
filepath.Join(outdir, "repositories.yaml"), filepath.Join(outdir, "repositories.yaml"),
outdir, outdir,
) )
// 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)
}
}
_, out, err := executeActionCommand(cmd) _, out, err := executeActionCommand(cmd)
if err != nil { if err != nil {
if tt.wantError { if tt.wantError {
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 return
} }
t.Fatalf("%q reported error: %s", tt.name, err) t.Fatalf("%q reported error: %s", tt.name, err)

Loading…
Cancel
Save