Skip to content

Commit

Permalink
Add the test cases for check the file when edit add command
Browse files Browse the repository at this point in the history
  • Loading branch information
koba1t committed Feb 28, 2023
1 parent cd49194 commit 85a4c4b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions kustomize/commands/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions kustomize/commands/edit/add/addcomponent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
10 changes: 10 additions & 0 deletions kustomize/commands/edit/add/addresource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit 85a4c4b

Please sign in to comment.