Skip to content

Commit

Permalink
update test add KustomizationFile
Browse files Browse the repository at this point in the history
  • Loading branch information
koba1t committed May 24, 2023
1 parent 8383b28 commit 565cff2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions kustomize/commands/edit/add/addcomponent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sigs.k8s.io/kustomize/api/konfig"
testutils_test "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/testutils"
"sigs.k8s.io/kustomize/kyaml/filesys"
)
Expand Down Expand Up @@ -51,19 +52,19 @@ func TestAddComponentAlreadyThere(t *testing.T) {
assert.NoError(t, cmd.RunE(cmd, args))
}

// Test for trying to add the kustomization.yaml file itself for resources.
// This adding operation is not allowed.
func TestAddKustomizationFileAsComponent(t *testing.T) {
fSys := filesys.MakeEmptyDirInMemory()
err := fSys.WriteFile(componentFileName, []byte(componentFileContent))
require.NoError(t, err)
testutils_test.WriteTestKustomization(fSys)

cmd := newCmdAddComponent(fSys)
args := []string{componentFileName}
args := []string{konfig.DefaultKustomizationFileName()}
require.NoError(t, cmd.RunE(cmd, args))

content, err := testutils_test.ReadTestKustomization(fSys)
require.NoError(t, err)
assert.Contains(t, string(content), componentFileName)
assert.NotContains(t, string(content), konfig.DefaultKustomizationFileName())
}

func TestAddComponentNoArgs(t *testing.T) {
Expand Down
9 changes: 5 additions & 4 deletions kustomize/commands/edit/add/addresource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sigs.k8s.io/kustomize/api/konfig"
testutils_test "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/testutils"
"sigs.k8s.io/kustomize/kyaml/filesys"
)
Expand Down Expand Up @@ -70,20 +71,20 @@ func TestAddResourceAlreadyThere(t *testing.T) {
assert.NoError(t, cmd.RunE(cmd, args))
}

// Test for trying to add the kustomization.yaml file itself for resources.
// This adding operation is not allowed.
func TestAddKustomizationFileAsResource(t *testing.T) {
fSys := filesys.MakeEmptyDirInMemory()
err := fSys.WriteFile(resourceFileName, []byte(resourceFileContent))
require.NoError(t, err)
testutils_test.WriteTestKustomization(fSys)

cmd := newCmdAddResource(fSys)
args := []string{resourceFileName}
args := []string{konfig.DefaultKustomizationFileName()}
assert.NoError(t, cmd.RunE(cmd, args))

content, err := testutils_test.ReadTestKustomization(fSys)
assert.NoError(t, err)

assert.Contains(t, string(content), resourceFileName)
assert.NotContains(t, string(content), konfig.DefaultKustomizationFileName())
}

func TestAddResourceNoArgs(t *testing.T) {
Expand Down

0 comments on commit 565cff2

Please sign in to comment.