mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Add the test cases for check the file when edit add command
This commit is contained in:
@@ -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"
|
||||
@@ -53,6 +54,14 @@ func TestCreateWithResources(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateWithResourcesWithFileNotFound(t *testing.T) {
|
||||
fSys := filesys.MakeEmptyDirInMemory()
|
||||
assert.NoError(t, 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"
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user