mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Test missing file report
This commit is contained in:
@@ -81,8 +81,8 @@ func (f *ConfigMapFactory) MakeConfigMap(
|
|||||||
}
|
}
|
||||||
all = append(all, pairs...)
|
all = append(all, pairs...)
|
||||||
|
|
||||||
for _, kv := range all {
|
for _, p := range all {
|
||||||
err = addKvToConfigMap(cm, kv.Key, kv.Value)
|
err = addKvToConfigMap(cm, p.Key, p.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ func (f *SecretFactory) MakeSecret(args *types.SecretArgs, options *types.Genera
|
|||||||
}
|
}
|
||||||
all = append(all, pairs...)
|
all = append(all, pairs...)
|
||||||
|
|
||||||
for _, kv := range all {
|
for _, p := range all {
|
||||||
err = addKvToSecret(s, kv.Key, kv.Value)
|
err = addKvToSecret(s, p.Key, p.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,18 @@ func NewKustTarget(
|
|||||||
}, nil
|
}, 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) {
|
func loadKustFile(ldr ifc.Loader) ([]byte, error) {
|
||||||
var content []byte
|
var content []byte
|
||||||
match := 0
|
match := 0
|
||||||
@@ -88,8 +100,9 @@ func loadKustFile(ldr ifc.Loader) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
switch match {
|
switch match {
|
||||||
case 0:
|
case 0:
|
||||||
return nil, fmt.Errorf("No kustomization file found in %s. Kustomize supports the following kustomization files: %s",
|
return nil, fmt.Errorf(
|
||||||
ldr.Root(), strings.Join(constants.KustomizationFileNames, ", "))
|
"unable to find one of %v in directory '%s'",
|
||||||
|
commaOr(quoted(constants.KustomizationFileNames)), ldr.Root())
|
||||||
case 1:
|
case 1:
|
||||||
return content, nil
|
return content, nil
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -23,8 +23,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/pkg/fs"
|
||||||
"sigs.k8s.io/kustomize/pkg/gvk"
|
"sigs.k8s.io/kustomize/pkg/gvk"
|
||||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||||
|
"sigs.k8s.io/kustomize/pkg/internal/loadertest"
|
||||||
"sigs.k8s.io/kustomize/pkg/resid"
|
"sigs.k8s.io/kustomize/pkg/resid"
|
||||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/pkg/resource"
|
"sigs.k8s.io/kustomize/pkg/resource"
|
||||||
@@ -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) {
|
func TestResourceNotFound(t *testing.T) {
|
||||||
th := NewKustTestHarness(t, "/whatever")
|
th := NewKustTestHarness(t, "/whatever")
|
||||||
th.writeK("/whatever", kustomizationContent1)
|
th.writeK("/whatever", kustomizationContent1)
|
||||||
|
|||||||
Reference in New Issue
Block a user