Skip to content

Commit

Permalink
chore: move removetest_testutils.go to internal/testutils
Browse files Browse the repository at this point in the history
  • Loading branch information
stormqueen1990 committed Dec 20, 2023
1 parent 21faa8d commit 16ca8e1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
26 changes: 13 additions & 13 deletions kustomize/commands/edit/remove/removeresource_test.go
Expand Up @@ -7,22 +7,22 @@ import (
"errors"
"testing"

"sigs.k8s.io/kustomize/kustomize/v5/commands/internal/remove"
testutils_test "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/testutils"
)

func TestRemoveResources(t *testing.T) {
testCases := []remove.Case{
testCases := []testutils_test.Case{
{
Description: "remove resources",
Given: remove.Given{
Given: testutils_test.Given{
Items: []string{
"resource1.yaml",
"resource2.yaml",
"resource3.yaml",
},
RemoveArgs: []string{"resource1.yaml"},
},
Expected: remove.Expected{
Expected: testutils_test.Expected{
Items: []string{
"resource2.yaml",
"resource3.yaml",
Expand All @@ -34,7 +34,7 @@ func TestRemoveResources(t *testing.T) {
},
{
Description: "remove resource with pattern",
Given: remove.Given{
Given: testutils_test.Given{
Items: []string{
"foo/resource1.yaml",
"foo/resource2.yaml",
Expand All @@ -43,7 +43,7 @@ func TestRemoveResources(t *testing.T) {
},
RemoveArgs: []string{"foo/resource*.yaml"},
},
Expected: remove.Expected{
Expected: testutils_test.Expected{
Items: []string{
"do/not/deleteme/please.yaml",
},
Expand All @@ -56,15 +56,15 @@ func TestRemoveResources(t *testing.T) {
},
{
Description: "nothing found to remove",
Given: remove.Given{
Given: testutils_test.Given{
Items: []string{
"resource1.yaml",
"resource2.yaml",
"resource3.yaml",
},
RemoveArgs: []string{"foo"},
},
Expected: remove.Expected{
Expected: testutils_test.Expected{
Items: []string{
"resource2.yaml",
"resource3.yaml",
Expand All @@ -74,14 +74,14 @@ func TestRemoveResources(t *testing.T) {
},
{
Description: "no arguments",
Given: remove.Given{},
Expected: remove.Expected{
Given: testutils_test.Given{},
Expected: testutils_test.Expected{
Err: errors.New("must specify a resource file"),
},
},
{
Description: "remove with multiple pattern arguments",
Given: remove.Given{
Given: testutils_test.Given{
Items: []string{
"foo/foo.yaml",
"bar/bar.yaml",
Expand All @@ -94,7 +94,7 @@ func TestRemoveResources(t *testing.T) {
"res*.yaml",
},
},
Expected: remove.Expected{
Expected: testutils_test.Expected{
Items: []string{
"do/not/deleteme/please.yaml",
},
Expand All @@ -107,5 +107,5 @@ func TestRemoveResources(t *testing.T) {
},
}

remove.ExecuteRemoveTestCases(t, testCases, "resources", newCmdRemoveResource)
testutils_test.ExecuteRemoveTestCases(t, testCases, "resources", newCmdRemoveResource)
}
27 changes: 14 additions & 13 deletions kustomize/commands/edit/remove/removetransformer_test.go
Expand Up @@ -6,23 +6,24 @@ package remove
import (
"testing"

"sigs.k8s.io/kustomize/kustomize/v5/commands/internal/remove"
testutils_test "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/testutils"

"sigs.k8s.io/kustomize/kyaml/errors"
)

func TestRemoveTransformer(t *testing.T) {
testCases := []remove.Case{
testCases := []testutils_test.Case{
{
Description: "remove transformers",
Given: remove.Given{
Given: testutils_test.Given{
Items: []string{
"transformer1.yaml",
"transformer2.yaml",
"transformer3.yaml",
},
RemoveArgs: []string{"transformer1.yaml"},
},
Expected: remove.Expected{
Expected: testutils_test.Expected{
Items: []string{
"transformer2.yaml",
"transformer3.yaml",
Expand All @@ -34,7 +35,7 @@ func TestRemoveTransformer(t *testing.T) {
},
{
Description: "remove transformer with pattern",
Given: remove.Given{
Given: testutils_test.Given{
Items: []string{
"foo/transformer1.yaml",
"foo/transformer2.yaml",
Expand All @@ -43,7 +44,7 @@ func TestRemoveTransformer(t *testing.T) {
},
RemoveArgs: []string{"foo/transformer*.yaml"},
},
Expected: remove.Expected{
Expected: testutils_test.Expected{
Items: []string{
"do/not/deleteme/please.yaml",
},
Expand All @@ -56,15 +57,15 @@ func TestRemoveTransformer(t *testing.T) {
},
{
Description: "nothing found to remove",
Given: remove.Given{
Given: testutils_test.Given{
Items: []string{
"transformer1.yaml",
"transformer2.yaml",
"transformer3.yaml",
},
RemoveArgs: []string{"foo"},
},
Expected: remove.Expected{
Expected: testutils_test.Expected{
Items: []string{
"transformer2.yaml",
"transformer3.yaml",
Expand All @@ -74,14 +75,14 @@ func TestRemoveTransformer(t *testing.T) {
},
{
Description: "no arguments",
Given: remove.Given{},
Expected: remove.Expected{
Given: testutils_test.Given{},
Expected: testutils_test.Expected{
Err: errors.Errorf("must specify a transformer file"),
},
},
{
Description: "remove with multiple pattern arguments",
Given: remove.Given{
Given: testutils_test.Given{
Items: []string{
"foo/foo.yaml",
"bar/bar.yaml",
Expand All @@ -94,7 +95,7 @@ func TestRemoveTransformer(t *testing.T) {
"tra*.yaml",
},
},
Expected: remove.Expected{
Expected: testutils_test.Expected{
Items: []string{
"do/not/deleteme/please.yaml",
},
Expand All @@ -107,5 +108,5 @@ func TestRemoveTransformer(t *testing.T) {
},
}

remove.ExecuteRemoveTestCases(t, testCases, "transformers", newCmdRemoveTransformer)
testutils_test.ExecuteRemoveTestCases(t, testCases, "transformers", newCmdRemoveTransformer)
}
@@ -1,15 +1,14 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0

package remove
package testutils_test

import (
"fmt"
"strings"
"testing"

"github.com/spf13/cobra"
testutils_test "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/testutils"
"sigs.k8s.io/kustomize/kyaml/filesys"
)

Expand Down Expand Up @@ -54,7 +53,7 @@ func ExecuteRemoveTestCases(
for _, tc := range testCases {
t.Run(tc.Description, func(t *testing.T) {
fSys := filesys.MakeFsInMemory()
testutils_test.WriteTestKustomizationWith(
WriteTestKustomizationWith(
fSys,
[]byte(fmt.Sprintf("%s:\n - %s",
collectionName,
Expand All @@ -71,7 +70,7 @@ func ExecuteRemoveTestCases(
}
return
}
content, err := testutils_test.ReadTestKustomization(fSys)
content, err := ReadTestKustomization(fSys)
if err != nil {
t.Errorf("unexpected read error: %v", err)
}
Expand Down

0 comments on commit 16ca8e1

Please sign in to comment.