Skip to content

Commit

Permalink
Merge pull request #783 from monopole/testKustFileMissingMessage
Browse files Browse the repository at this point in the history
Test missing kust file message
  • Loading branch information
monopole committed Feb 11, 2019
2 parents f66024b + 1a03dca commit 74d3e92
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
4 changes: 2 additions & 2 deletions k8sdeps/configmapandsecret/configmapfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func (f *ConfigMapFactory) MakeConfigMap(
}
all = append(all, pairs...)

for _, kv := range all {
err = addKvToConfigMap(cm, kv.Key, kv.Value)
for _, p := range all {
err = addKvToConfigMap(cm, p.Key, p.Value)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions k8sdeps/configmapandsecret/secretfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (f *SecretFactory) MakeSecret(args *types.SecretArgs, options *types.Genera
}
all = append(all, pairs...)

for _, kv := range all {
err = addKvToSecret(s, kv.Key, kv.Value)
for _, p := range all {
err = addKvToSecret(s, p.Key, p.Value)
if err != nil {
return nil, err
}
Expand Down
17 changes: 15 additions & 2 deletions pkg/target/kusttarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ func NewKustTarget(
}, nil
}

func quoted(l []string) []string {
r := make([]string, len(l))
for i, v := range l {
r[i] = "'" + v + "'"
}
return r
}

func commaOr(q []string) string {
return strings.Join(q[:len(q)-1], ", ") + " or " + q[len(q)-1]
}

func loadKustFile(ldr ifc.Loader) ([]byte, error) {
var content []byte
match := 0
Expand All @@ -88,8 +100,9 @@ func loadKustFile(ldr ifc.Loader) ([]byte, error) {
}
switch match {
case 0:
return nil, fmt.Errorf("No kustomization file found in %s. Kustomize supports the following kustomization files: %s",
ldr.Root(), strings.Join(constants.KustomizationFileNames, ", "))
return nil, fmt.Errorf(
"unable to find one of %v in directory '%s'",
commaOr(quoted(constants.KustomizationFileNames)), ldr.Root())
case 1:
return content, nil
default:
Expand Down
14 changes: 14 additions & 0 deletions pkg/target/kusttarget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (
"strings"
"testing"

"sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/ifc"
"sigs.k8s.io/kustomize/pkg/internal/loadertest"
"sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource"
Expand Down Expand Up @@ -195,6 +197,18 @@ func TestResources1(t *testing.T) {
}
}

func TestKustomizationNotFound(t *testing.T) {
_, err := NewKustTarget(
loadertest.NewFakeLoader("/foo"), fs.MakeFakeFS(), nil, nil)
if err == nil {
t.Fatalf("expected an error")
}
if err.Error() !=
`unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization' in directory '/foo'` {
t.Fatalf("unexpected error: %q", err)
}
}

func TestResourceNotFound(t *testing.T) {
th := NewKustTestHarness(t, "/whatever")
th.writeK("/whatever", kustomizationContent1)
Expand Down

0 comments on commit 74d3e92

Please sign in to comment.