chaging error to no such file or directory

Signed-off-by: Anshul Verma <ansverma@localhost.localdomain>
pull/7127/head
Anshul Verma 6 years ago
parent d49b66e210
commit 170f894e9c

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

@ -296,6 +296,40 @@ func TestPackageValues(t *testing.T) {
} }
} }
func TestNonExistentDir(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 { func createValuesFile(t *testing.T, data string) string {
outputDir := ensure.TempDir(t) outputDir := ensure.TempDir(t)

@ -194,7 +194,7 @@ icon: https://example.com/64x64.png
if _, err = LoadFiles([]*BufferedFile{}); err == nil { if _, err = LoadFiles([]*BufferedFile{}); err == nil {
t.Fatal("Expected err to be non-nil") t.Fatal("Expected err to be non-nil")
} }
if err.Error() != "validation: No such Chart found" { if err.Error() != "validation: chart.metadata is required" {
t.Errorf("Expected chart metadata missing error, got '%s'", err.Error()) t.Errorf("Expected chart metadata missing error, got '%s'", err.Error())
} }
} }
@ -268,7 +268,7 @@ func TestLoadInvalidArchive(t *testing.T) {
{"illegal-name.tgz", "./.", "chart illegally contains content outside the base directory"}, {"illegal-name.tgz", "./.", "chart illegally contains content outside the base directory"},
{"illegal-name2.tgz", "/./.", "chart illegally contains content outside the base directory"}, {"illegal-name2.tgz", "/./.", "chart illegally contains content outside the base directory"},
{"illegal-name3.tgz", "missing-leading-slash", "chart illegally contains content outside the base directory"}, {"illegal-name3.tgz", "missing-leading-slash", "chart illegally contains content outside the base directory"},
{"illegal-name4.tgz", "/missing-leading-slash", "validation: No such Chart found"}, {"illegal-name4.tgz", "/missing-leading-slash", "validation: chart.metadata is required"},
{"illegal-abspath.tgz", "//foo", "chart illegally contains absolute paths"}, {"illegal-abspath.tgz", "//foo", "chart illegally contains absolute paths"},
{"illegal-abspath2.tgz", "///foo", "chart illegally contains absolute paths"}, {"illegal-abspath2.tgz", "///foo", "chart illegally contains absolute paths"},
{"illegal-abspath3.tgz", "\\\\foo", "chart illegally contains absolute paths"}, {"illegal-abspath3.tgz", "\\\\foo", "chart illegally contains absolute paths"},
@ -302,7 +302,7 @@ func TestLoadInvalidArchive(t *testing.T) {
illegalChart = filepath.Join(tmpdir, "abs-path2.tgz") illegalChart = filepath.Join(tmpdir, "abs-path2.tgz")
writeTar(illegalChart, "files/whatever.yaml", []byte("hello: world")) writeTar(illegalChart, "files/whatever.yaml", []byte("hello: world"))
_, err = Load(illegalChart) _, err = Load(illegalChart)
if err.Error() != "validation: No such Chart found" { if err.Error() != "validation: chart.metadata is required" {
t.Error(err) t.Error(err)
} }

@ -67,7 +67,7 @@ type Metadata struct {
// Validate checks the metadata for known issues, returning an error if metadata is not correct // Validate checks the metadata for known issues, returning an error if metadata is not correct
func (md *Metadata) Validate() error { func (md *Metadata) Validate() error {
if md == nil { if md == nil {
return ValidationError("No such Chart found") return ValidationError("chart.metadata is required")
} }
if md.APIVersion == "" { if md.APIVersion == "" {
return ValidationError("chart.metadata.apiVersion is required") return ValidationError("chart.metadata.apiVersion is required")

@ -1,27 +0,0 @@
/*
Copyright The Helm Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package chart
import "testing"
func TestValidate(t *testing.T) {
var metadata *Metadata = nil
error := metadata.Validate()
errorMessage := "validation: No such Chart found"
if error.Error() != errorMessage {
t.Errorf("The error message is other than '%s'", errorMessage)
}
}
Loading…
Cancel
Save