fix(helm): add descriptive error if dependency has blank "repository" (#5152)

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
pull/5275/head
adshmh 7 years ago committed by Matthew Fisher
parent 1984f436af
commit d8bdf484cc

@ -371,6 +371,9 @@ func (m *Manager) getRepoNames(deps []*chartutil.Dependency) (map[string]string,
// by Helm. // by Helm.
missing := []string{} missing := []string{}
for _, dd := range deps { for _, dd := range deps {
if dd.Repository == "" {
return nil, fmt.Errorf("no 'repository' field specified for dependency: %q", dd.Name)
}
// if dep chart is from local path, verify the path is valid // if dep chart is from local path, verify the path is valid
if strings.HasPrefix(dd.Repository, "file://") { if strings.HasPrefix(dd.Repository, "file://") {
if _, err := resolver.GetLocalPath(dd.Repository, m.ChartPath); err != nil { if _, err := resolver.GetLocalPath(dd.Repository, m.ChartPath); err != nil {

@ -18,6 +18,7 @@ package downloader
import ( import (
"bytes" "bytes"
"reflect" "reflect"
"strings"
"testing" "testing"
"k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/chartutil"
@ -99,10 +100,11 @@ func TestGetRepoNames(t *testing.T) {
HelmHome: helmpath.Home("testdata/helmhome"), HelmHome: helmpath.Home("testdata/helmhome"),
} }
tests := []struct { tests := []struct {
name string name string
req []*chartutil.Dependency req []*chartutil.Dependency
expect map[string]string expect map[string]string
err bool err bool
expectedErr string
}{ }{
{ {
name: "no repo definition failure", name: "no repo definition failure",
@ -118,6 +120,14 @@ func TestGetRepoNames(t *testing.T) {
}, },
err: true, err: true,
}, },
{
name: "dependency entry missing 'repository' field -- e.g. spelled 'repo'",
req: []*chartutil.Dependency{
{Name: "dependency-missing-repository-field"},
},
err: true,
expectedErr: "no 'repository' field specified for dependency: \"dependency-missing-repository-field\"",
},
{ {
name: "no repo definition failure", name: "no repo definition failure",
req: []*chartutil.Dependency{ req: []*chartutil.Dependency{
@ -152,6 +162,9 @@ func TestGetRepoNames(t *testing.T) {
l, err := m.getRepoNames(tt.req) l, err := m.getRepoNames(tt.req)
if err != nil { if err != nil {
if tt.err { if tt.err {
if !strings.Contains(err.Error(), tt.expectedErr) {
t.Fatalf("%s: expected error: %s, got: %s", tt.name, tt.expectedErr, err.Error())
}
continue continue
} }
t.Fatal(err) t.Fatal(err)

Loading…
Cancel
Save