mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-30 09:51:23 +00:00
chore: move removetest.go to the internal package
* Move the edit/remove_test/removetest.go file to the internal package, as it is intended to aid testing. * Rename the method ExecuteTestCases to ExecuteRemoveTestCases.
This commit is contained in:
@@ -7,14 +7,14 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove_test"
|
||||
"sigs.k8s.io/kustomize/kustomize/v5/commands/internal/remove"
|
||||
)
|
||||
|
||||
func TestRemoveResources(t *testing.T) {
|
||||
testCases := []remove_test.Case{
|
||||
testCases := []remove.Case{
|
||||
{
|
||||
Description: "remove resources",
|
||||
Given: remove_test.Given{
|
||||
Given: remove.Given{
|
||||
Items: []string{
|
||||
"resource1.yaml",
|
||||
"resource2.yaml",
|
||||
@@ -22,7 +22,7 @@ func TestRemoveResources(t *testing.T) {
|
||||
},
|
||||
RemoveArgs: []string{"resource1.yaml"},
|
||||
},
|
||||
Expected: remove_test.Expected{
|
||||
Expected: remove.Expected{
|
||||
Items: []string{
|
||||
"resource2.yaml",
|
||||
"resource3.yaml",
|
||||
@@ -34,7 +34,7 @@ func TestRemoveResources(t *testing.T) {
|
||||
},
|
||||
{
|
||||
Description: "remove resource with pattern",
|
||||
Given: remove_test.Given{
|
||||
Given: remove.Given{
|
||||
Items: []string{
|
||||
"foo/resource1.yaml",
|
||||
"foo/resource2.yaml",
|
||||
@@ -43,7 +43,7 @@ func TestRemoveResources(t *testing.T) {
|
||||
},
|
||||
RemoveArgs: []string{"foo/resource*.yaml"},
|
||||
},
|
||||
Expected: remove_test.Expected{
|
||||
Expected: remove.Expected{
|
||||
Items: []string{
|
||||
"do/not/deleteme/please.yaml",
|
||||
},
|
||||
@@ -56,7 +56,7 @@ func TestRemoveResources(t *testing.T) {
|
||||
},
|
||||
{
|
||||
Description: "nothing found to remove",
|
||||
Given: remove_test.Given{
|
||||
Given: remove.Given{
|
||||
Items: []string{
|
||||
"resource1.yaml",
|
||||
"resource2.yaml",
|
||||
@@ -64,7 +64,7 @@ func TestRemoveResources(t *testing.T) {
|
||||
},
|
||||
RemoveArgs: []string{"foo"},
|
||||
},
|
||||
Expected: remove_test.Expected{
|
||||
Expected: remove.Expected{
|
||||
Items: []string{
|
||||
"resource2.yaml",
|
||||
"resource3.yaml",
|
||||
@@ -74,14 +74,14 @@ func TestRemoveResources(t *testing.T) {
|
||||
},
|
||||
{
|
||||
Description: "no arguments",
|
||||
Given: remove_test.Given{},
|
||||
Expected: remove_test.Expected{
|
||||
Given: remove.Given{},
|
||||
Expected: remove.Expected{
|
||||
Err: errors.New("must specify a resource file"),
|
||||
},
|
||||
},
|
||||
{
|
||||
Description: "remove with multiple pattern arguments",
|
||||
Given: remove_test.Given{
|
||||
Given: remove.Given{
|
||||
Items: []string{
|
||||
"foo/foo.yaml",
|
||||
"bar/bar.yaml",
|
||||
@@ -94,7 +94,7 @@ func TestRemoveResources(t *testing.T) {
|
||||
"res*.yaml",
|
||||
},
|
||||
},
|
||||
Expected: remove_test.Expected{
|
||||
Expected: remove.Expected{
|
||||
Items: []string{
|
||||
"do/not/deleteme/please.yaml",
|
||||
},
|
||||
@@ -107,5 +107,5 @@ func TestRemoveResources(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
remove_test.ExecuteTestCases(t, testCases, "resources", newCmdRemoveResource)
|
||||
remove.ExecuteRemoveTestCases(t, testCases, "resources", newCmdRemoveResource)
|
||||
}
|
||||
|
||||
@@ -6,15 +6,15 @@ package remove
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove_test"
|
||||
"sigs.k8s.io/kustomize/kustomize/v5/commands/internal/remove"
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
)
|
||||
|
||||
func TestRemoveTransformer(t *testing.T) {
|
||||
testCases := []remove_test.Case{
|
||||
testCases := []remove.Case{
|
||||
{
|
||||
Description: "remove transformers",
|
||||
Given: remove_test.Given{
|
||||
Given: remove.Given{
|
||||
Items: []string{
|
||||
"transformer1.yaml",
|
||||
"transformer2.yaml",
|
||||
@@ -22,7 +22,7 @@ func TestRemoveTransformer(t *testing.T) {
|
||||
},
|
||||
RemoveArgs: []string{"transformer1.yaml"},
|
||||
},
|
||||
Expected: remove_test.Expected{
|
||||
Expected: remove.Expected{
|
||||
Items: []string{
|
||||
"transformer2.yaml",
|
||||
"transformer3.yaml",
|
||||
@@ -34,7 +34,7 @@ func TestRemoveTransformer(t *testing.T) {
|
||||
},
|
||||
{
|
||||
Description: "remove transformer with pattern",
|
||||
Given: remove_test.Given{
|
||||
Given: remove.Given{
|
||||
Items: []string{
|
||||
"foo/transformer1.yaml",
|
||||
"foo/transformer2.yaml",
|
||||
@@ -43,7 +43,7 @@ func TestRemoveTransformer(t *testing.T) {
|
||||
},
|
||||
RemoveArgs: []string{"foo/transformer*.yaml"},
|
||||
},
|
||||
Expected: remove_test.Expected{
|
||||
Expected: remove.Expected{
|
||||
Items: []string{
|
||||
"do/not/deleteme/please.yaml",
|
||||
},
|
||||
@@ -56,7 +56,7 @@ func TestRemoveTransformer(t *testing.T) {
|
||||
},
|
||||
{
|
||||
Description: "nothing found to remove",
|
||||
Given: remove_test.Given{
|
||||
Given: remove.Given{
|
||||
Items: []string{
|
||||
"transformer1.yaml",
|
||||
"transformer2.yaml",
|
||||
@@ -64,7 +64,7 @@ func TestRemoveTransformer(t *testing.T) {
|
||||
},
|
||||
RemoveArgs: []string{"foo"},
|
||||
},
|
||||
Expected: remove_test.Expected{
|
||||
Expected: remove.Expected{
|
||||
Items: []string{
|
||||
"transformer2.yaml",
|
||||
"transformer3.yaml",
|
||||
@@ -74,14 +74,14 @@ func TestRemoveTransformer(t *testing.T) {
|
||||
},
|
||||
{
|
||||
Description: "no arguments",
|
||||
Given: remove_test.Given{},
|
||||
Expected: remove_test.Expected{
|
||||
Given: remove.Given{},
|
||||
Expected: remove.Expected{
|
||||
Err: errors.Errorf("must specify a transformer file"),
|
||||
},
|
||||
},
|
||||
{
|
||||
Description: "remove with multiple pattern arguments",
|
||||
Given: remove_test.Given{
|
||||
Given: remove.Given{
|
||||
Items: []string{
|
||||
"foo/foo.yaml",
|
||||
"bar/bar.yaml",
|
||||
@@ -94,7 +94,7 @@ func TestRemoveTransformer(t *testing.T) {
|
||||
"tra*.yaml",
|
||||
},
|
||||
},
|
||||
Expected: remove_test.Expected{
|
||||
Expected: remove.Expected{
|
||||
Items: []string{
|
||||
"do/not/deleteme/please.yaml",
|
||||
},
|
||||
@@ -107,5 +107,5 @@ func TestRemoveTransformer(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
remove_test.ExecuteTestCases(t, testCases, "transformers", newCmdRemoveTransformer)
|
||||
remove.ExecuteRemoveTestCases(t, testCases, "transformers", newCmdRemoveTransformer)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2022 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package remove_test
|
||||
package remove
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -41,11 +41,15 @@ type Case struct {
|
||||
Expected Expected
|
||||
}
|
||||
|
||||
// ExecuteTestCases executes the provided test cases against the specified command
|
||||
// ExecuteRemoveTestCases executes the provided test cases against the specified command
|
||||
// for a particular collection (e.g. ) tests a command defined by the provided
|
||||
// collection Name (e.g. transformers or resources) and newRemoveCmdToTest function.
|
||||
func ExecuteTestCases(t *testing.T, testCases []Case, collectionName string,
|
||||
newRemoveCmdToTest func(filesys.FileSystem) *cobra.Command) {
|
||||
func ExecuteRemoveTestCases(
|
||||
t *testing.T,
|
||||
testCases []Case,
|
||||
collectionName string,
|
||||
newRemoveCmdToTest func(filesys.FileSystem) *cobra.Command,
|
||||
) {
|
||||
t.Helper()
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.Description, func(t *testing.T) {
|
||||
Reference in New Issue
Block a user