Friendly error message for non-existent Chart while packaging (#7127)

* Fixes #6713 Friedly error message

Signed-off-by: Anshul Verma <ansverma@localhost.localdomain>

* Fixes #6713 Friedly error message

Signed-off-by: Anshul Verma <ansverma@localhost.localdomain>

* chaging error to no such file or directory

Signed-off-by: Anshul Verma <ansverma@localhost.localdomain>

* changed it for the wider stat error messages which comes directly from go standard library.

Signed-off-by: Anshul Verma <ansverma@localhost.localdomain>

* changed it for the wider stat error messages which comes directly from go standard library.

Signed-off-by: Anshul Verma <ansverma@localhost.localdomain>
pull/7466/head
Anshul Verma 5 years ago committed by Martin Hickey
parent e3675e3312
commit 5e3c7d7eb8

@ -20,6 +20,7 @@ import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"github.com/pkg/errors"
@ -80,6 +81,9 @@ func newPackageCmd(out io.Writer) *cobra.Command {
if err != nil {
return err
}
if _, err := os.Stat(args[i]); err != nil {
return err
}
if client.DependencyUpdate {
downloadManager := &downloader.Manager{

@ -296,6 +296,41 @@ func TestPackageValues(t *testing.T) {
}
}
func TestNonExistentDirAndBadPermission(t *testing.T) {
nonExistentDir := "testdata/testcharts/non-existent-directory"
tests := []struct {
name string
flags map[string]string
args []string
expect string
hasfile string
err bool
}{
{
name: "package testdata/testcharts/non-existent-directory",
args: []string{"testdata/testcharts/non-existent-directory"},
expect: fmt.Sprintf("stat %s: no such file or directory", nonExistentDir),
err: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var buf bytes.Buffer
c := newPackageCmd(&buf)
re := regexp.MustCompile(tt.expect)
err := c.RunE(c, tt.args)
if err != nil {
if tt.err && re.MatchString(err.Error()) {
return
}
t.Fatalf("%q: expected error %q, got %q", tt.name, tt.expect, err)
}
})
}
}
func createValuesFile(t *testing.T, data string) string {
outputDir := ensure.TempDir(t)

Loading…
Cancel
Save