Add the test cases for check the file when edit add command

This commit is contained in:
koba1t
2023-03-01 04:11:55 +09:00
parent cd49194383
commit 694b3c9318
3 changed files with 29 additions and 0 deletions

View File

@@ -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"

View File

@@ -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")
}

View File

@@ -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")
}