Merge pull request #31464 from benoittgt/fix-test

Properly test error messages on pull command's test
pull/31539/head
George Jenkins 10 months ago committed by GitHub
commit 63dcb5c74c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -106,16 +106,16 @@ func TestPullCmd(t *testing.T) {
{ {
name: "Fetch untar when file with same name existed", name: "Fetch untar when file with same name existed",
args: "test/test1 --untar --untardir test1", args: "test/test1 --untar --untardir test1",
existFile: "test1", existFile: "test1/test1",
wantError: true, wantError: true,
wantErrorMsg: fmt.Sprintf("failed to untar: a file or directory with the name %s already exists", filepath.Join(srv.Root(), "test1")), wantErrorMsg: fmt.Sprintf("failed to untar: a file or directory with the name %s already exists", filepath.Join(srv.Root(), "test1", "test1")),
}, },
{ {
name: "Fetch untar when dir with same name existed", name: "Fetch untar when dir with same name existed",
args: "test/test2 --untar --untardir test2", args: "test/test --untar --untardir test2",
existDir: "test2", existDir: "test2/test",
wantError: true, wantError: true,
wantErrorMsg: fmt.Sprintf("failed to untar: a file or directory with the name %s already exists", filepath.Join(srv.Root(), "test2")), wantErrorMsg: fmt.Sprintf("failed to untar: a file or directory with the name %s already exists", filepath.Join(srv.Root(), "test2", "test")),
}, },
{ {
name: "Fetch, verify, untar", name: "Fetch, verify, untar",
@ -178,9 +178,10 @@ func TestPullCmd(t *testing.T) {
}, },
{ {
name: "OCI Fetch untar when dir with same name existed", name: "OCI Fetch untar when dir with same name existed",
args: fmt.Sprintf("oci-test-chart oci://%s/u/ocitestuser/oci-dependent-chart --version 0.1.0 --untar --untardir ocitest2 --untar --untardir ocitest2", ociSrv.RegistryURL), args: fmt.Sprintf("oci://%s/u/ocitestuser/oci-dependent-chart --version 0.1.0 --untar --untardir ocitest2", ociSrv.RegistryURL),
existDir: "ocitest2/oci-dependent-chart",
wantError: true, wantError: true,
wantErrorMsg: fmt.Sprintf("failed to untar: a file or directory with the name %s already exists", filepath.Join(srv.Root(), "ocitest2")), wantErrorMsg: fmt.Sprintf("failed to untar: a file or directory with the name %s already exists", filepath.Join(srv.Root(), "ocitest2", "oci-dependent-chart")),
}, },
{ {
name: "Fail fetching non-existent OCI chart", name: "Fail fetching non-existent OCI chart",
@ -189,10 +190,9 @@ func TestPullCmd(t *testing.T) {
wantError: true, wantError: true,
}, },
{ {
name: "Fail fetching OCI chart without version specified", name: "Fail fetching OCI chart without version specified",
args: fmt.Sprintf("oci://%s/u/ocitestuser/nosuchthing", ociSrv.RegistryURL), args: fmt.Sprintf("oci://%s/u/ocitestuser/nosuchthing", ociSrv.RegistryURL),
wantErrorMsg: "Error: --version flag is explicitly required for OCI registries", wantError: true,
wantError: true,
}, },
{ {
name: "Fetching OCI chart without version option specified", name: "Fetching OCI chart without version option specified",
@ -207,7 +207,7 @@ func TestPullCmd(t *testing.T) {
{ {
name: "Fail fetching OCI chart with version mismatch", name: "Fail fetching OCI chart with version mismatch",
args: fmt.Sprintf("oci://%s/u/ocitestuser/oci-dependent-chart:0.2.0 --version 0.1.0", ociSrv.RegistryURL), args: fmt.Sprintf("oci://%s/u/ocitestuser/oci-dependent-chart:0.2.0 --version 0.1.0", ociSrv.RegistryURL),
wantErrorMsg: "Error: chart reference and version mismatch: 0.2.0 is not 0.1.0", wantErrorMsg: "chart reference and version mismatch: 0.1.0 is not 0.2.0",
wantError: true, wantError: true,
}, },
} }
@ -228,6 +228,9 @@ func TestPullCmd(t *testing.T) {
// Create file or Dir before helm pull --untar, see: https://github.com/helm/helm/issues/7182 // Create file or Dir before helm pull --untar, see: https://github.com/helm/helm/issues/7182
if tt.existFile != "" { if tt.existFile != "" {
file := filepath.Join(outdir, tt.existFile) file := filepath.Join(outdir, tt.existFile)
if err := os.MkdirAll(filepath.Dir(file), 0755); err != nil {
t.Fatal(err)
}
_, err := os.Create(file) _, err := os.Create(file)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -235,7 +238,7 @@ func TestPullCmd(t *testing.T) {
} }
if tt.existDir != "" { if tt.existDir != "" {
file := filepath.Join(outdir, tt.existDir) file := filepath.Join(outdir, tt.existDir)
err := os.Mkdir(file, 0755) err := os.MkdirAll(file, 0755)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -243,8 +246,8 @@ func TestPullCmd(t *testing.T) {
_, out, err := executeActionCommand(cmd) _, out, err := executeActionCommand(cmd)
if err != nil { if err != nil {
if tt.wantError { if tt.wantError {
if tt.wantErrorMsg != "" && tt.wantErrorMsg == err.Error() { if tt.wantErrorMsg != "" && tt.wantErrorMsg != err.Error() {
t.Fatalf("Actual error %s, not equal to expected error %s", err, tt.wantErrorMsg) t.Fatalf("Actual error '%s', not equal to expected error '%s'", err, tt.wantErrorMsg)
} }
return return
} }
@ -303,16 +306,19 @@ func runPullTests(t *testing.T, tests []struct {
} }
if tt.existDir != "" { if tt.existDir != "" {
file := filepath.Join(outdir, tt.existDir) file := filepath.Join(outdir, tt.existDir)
err := os.Mkdir(file, 0755) err := os.MkdirAll(file, 0755)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
_, _, err := executeActionCommand(cmd) _, _, err := executeActionCommand(cmd)
if tt.wantError && err == nil {
t.Fatalf("%q: expected error but got none", tt.name)
}
if err != nil { if err != nil {
if tt.wantError { if tt.wantError {
if tt.wantErrorMsg != "" && tt.wantErrorMsg == err.Error() { if tt.wantErrorMsg != "" && tt.wantErrorMsg != err.Error() {
t.Fatalf("Actual error %s, not equal to expected error %s", err, tt.wantErrorMsg) t.Fatalf("Actual error '%s', not equal to expected error '%s'", err, tt.wantErrorMsg)
} }
return return
} }
@ -487,10 +493,9 @@ func TestPullWithCredentialsCmdOCIRegistry(t *testing.T) {
wantError: true, wantError: true,
}, },
{ {
name: "Fail fetching OCI chart without version specified", name: "Fail fetching OCI chart without version specified",
args: buildOCIURL(ociSrv.RegistryURL, "nosuchthing", "", ociSrv.TestUsername, ociSrv.TestPassword), args: buildOCIURL(ociSrv.RegistryURL, "nosuchthing", "", ociSrv.TestUsername, ociSrv.TestPassword),
wantErrorMsg: "Error: --version flag is explicitly required for OCI registries", wantError: true,
wantError: true,
}, },
} }

Binary file not shown.

@ -0,0 +1,4 @@
apiVersion: v1
description: Test chart for untar conflict testing
name: test
version: 0.1.0

@ -0,0 +1 @@
# Default values for test

Binary file not shown.

@ -0,0 +1,4 @@
apiVersion: v1
description: Test chart for untar conflict testing
name: test1
version: 0.1.0

@ -0,0 +1,2 @@
# Default values for test1# Default values for test1
Loading…
Cancel
Save