diff --git a/kustomize/commands/edit/add/addcomponent_test.go b/kustomize/commands/edit/add/addcomponent_test.go index a6d58e3204..e1a137060f 100644 --- a/kustomize/commands/edit/add/addcomponent_test.go +++ b/kustomize/commands/edit/add/addcomponent_test.go @@ -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" ) @@ -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) { diff --git a/kustomize/commands/edit/add/addresource_test.go b/kustomize/commands/edit/add/addresource_test.go index c17621bd37..d35f162623 100644 --- a/kustomize/commands/edit/add/addresource_test.go +++ b/kustomize/commands/edit/add/addresource_test.go @@ -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" ) @@ -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) {