diff --git a/kustomize/commands/create/create_test.go b/kustomize/commands/create/create_test.go index ec695235a36..4612eba93f6 100644 --- a/kustomize/commands/create/create_test.go +++ b/kustomize/commands/create/create_test.go @@ -7,6 +7,7 @@ import ( "reflect" "testing" + "github.com/stretchr/testify/assert" "sigs.k8s.io/kustomize/api/provider" "sigs.k8s.io/kustomize/api/types" "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile" @@ -51,8 +52,16 @@ func TestCreateWithResources(t *testing.T) { if !reflect.DeepEqual(m.Resources, expected) { t.Fatalf("expected %+v but got %+v", expected, m.Resources) } + } +func TestCreateWithResourcesWithFileNotFound(t *testing.T) { + fSys := filesys.MakeEmptyDirInMemory() + fSys.WriteFile("foo.yaml", []byte("")) + opts := createFlags{resources: "foo.yaml,bar.yaml"} + err := runCreate(opts, fSys, factory) + assert.EqualError(t, err, "bar.yaml has no match: must build at directory: not a valid directory: 'bar.yaml' doesn't exist") +} func TestCreateWithNamespace(t *testing.T) { fSys := filesys.MakeFsInMemory() want := "foo" diff --git a/kustomize/commands/edit/add/addcomponent_test.go b/kustomize/commands/edit/add/addcomponent_test.go index 3e99ff91073..a6d58e3204e 100644 --- a/kustomize/commands/edit/add/addcomponent_test.go +++ b/kustomize/commands/edit/add/addcomponent_test.go @@ -73,3 +73,13 @@ func TestAddComponentNoArgs(t *testing.T) { err := cmd.Execute() assert.EqualError(t, err, "must specify a component file") } + +func TestAddComponentFileNotFound(t *testing.T) { + fSys := filesys.MakeEmptyDirInMemory() + + cmd := newCmdAddComponent(fSys) + args := []string{componentFileName} + + err := cmd.RunE(cmd, args) + assert.EqualError(t, err, componentFileName+" has no match: must build at directory: not a valid directory: '"+componentFileName+"' doesn't exist") +} diff --git a/kustomize/commands/edit/add/addresource_test.go b/kustomize/commands/edit/add/addresource_test.go index 3602d89013c..c17621bd371 100644 --- a/kustomize/commands/edit/add/addresource_test.go +++ b/kustomize/commands/edit/add/addresource_test.go @@ -94,3 +94,13 @@ func TestAddResourceNoArgs(t *testing.T) { assert.Error(t, err) assert.Equal(t, "must specify a resource file", err.Error()) } + +func TestAddResourceFileNotFound(t *testing.T) { + fSys := filesys.MakeEmptyDirInMemory() + + cmd := newCmdAddResource(fSys) + args := []string{resourceFileName} + + err := cmd.RunE(cmd, args) + assert.EqualError(t, err, resourceFileName+" has no match: must build at directory: not a valid directory: '"+resourceFileName+"' doesn't exist") +}