From b6a174d4bca3da2707a7853cc7032c1d072d6b6a Mon Sep 17 00:00:00 2001 From: zwwhdls Date: Wed, 11 Dec 2019 14:42:49 +0800 Subject: [PATCH] complete testCase when file/dir existed. Signed-off-by: zwwhdls --- cmd/helm/pull_test.go | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/cmd/helm/pull_test.go b/cmd/helm/pull_test.go index 29abdc666..8d238e791 100644 --- a/cmd/helm/pull_test.go +++ b/cmd/helm/pull_test.go @@ -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)