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

Loading…
Cancel
Save