Skip to content

Commit f814039

Browse files
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.
1 parent b28e044 commit f814039

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

kustomize/commands/edit/remove/removeresource_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ import (
77
"errors"
88
"testing"
99

10-
"sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove_test"
10+
"sigs.k8s.io/kustomize/kustomize/v5/commands/internal/remove"
1111
)
1212

1313
func TestRemoveResources(t *testing.T) {
14-
testCases := []remove_test.Case{
14+
testCases := []remove.Case{
1515
{
1616
Description: "remove resources",
17-
Given: remove_test.Given{
17+
Given: remove.Given{
1818
Items: []string{
1919
"resource1.yaml",
2020
"resource2.yaml",
2121
"resource3.yaml",
2222
},
2323
RemoveArgs: []string{"resource1.yaml"},
2424
},
25-
Expected: remove_test.Expected{
25+
Expected: remove.Expected{
2626
Items: []string{
2727
"resource2.yaml",
2828
"resource3.yaml",
@@ -34,7 +34,7 @@ func TestRemoveResources(t *testing.T) {
3434
},
3535
{
3636
Description: "remove resource with pattern",
37-
Given: remove_test.Given{
37+
Given: remove.Given{
3838
Items: []string{
3939
"foo/resource1.yaml",
4040
"foo/resource2.yaml",
@@ -43,7 +43,7 @@ func TestRemoveResources(t *testing.T) {
4343
},
4444
RemoveArgs: []string{"foo/resource*.yaml"},
4545
},
46-
Expected: remove_test.Expected{
46+
Expected: remove.Expected{
4747
Items: []string{
4848
"do/not/deleteme/please.yaml",
4949
},
@@ -56,15 +56,15 @@ func TestRemoveResources(t *testing.T) {
5656
},
5757
{
5858
Description: "nothing found to remove",
59-
Given: remove_test.Given{
59+
Given: remove.Given{
6060
Items: []string{
6161
"resource1.yaml",
6262
"resource2.yaml",
6363
"resource3.yaml",
6464
},
6565
RemoveArgs: []string{"foo"},
6666
},
67-
Expected: remove_test.Expected{
67+
Expected: remove.Expected{
6868
Items: []string{
6969
"resource2.yaml",
7070
"resource3.yaml",
@@ -74,14 +74,14 @@ func TestRemoveResources(t *testing.T) {
7474
},
7575
{
7676
Description: "no arguments",
77-
Given: remove_test.Given{},
78-
Expected: remove_test.Expected{
77+
Given: remove.Given{},
78+
Expected: remove.Expected{
7979
Err: errors.New("must specify a resource file"),
8080
},
8181
},
8282
{
8383
Description: "remove with multiple pattern arguments",
84-
Given: remove_test.Given{
84+
Given: remove.Given{
8585
Items: []string{
8686
"foo/foo.yaml",
8787
"bar/bar.yaml",
@@ -94,7 +94,7 @@ func TestRemoveResources(t *testing.T) {
9494
"res*.yaml",
9595
},
9696
},
97-
Expected: remove_test.Expected{
97+
Expected: remove.Expected{
9898
Items: []string{
9999
"do/not/deleteme/please.yaml",
100100
},
@@ -107,5 +107,5 @@ func TestRemoveResources(t *testing.T) {
107107
},
108108
}
109109

110-
remove_test.ExecuteTestCases(t, testCases, "resources", newCmdRemoveResource)
110+
remove.ExecuteRemoveTestCases(t, testCases, "resources", newCmdRemoveResource)
111111
}

kustomize/commands/edit/remove/removetransformer_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ package remove
66
import (
77
"testing"
88

9-
"sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove_test"
9+
"sigs.k8s.io/kustomize/kustomize/v5/commands/internal/remove"
1010
"sigs.k8s.io/kustomize/kyaml/errors"
1111
)
1212

1313
func TestRemoveTransformer(t *testing.T) {
14-
testCases := []remove_test.Case{
14+
testCases := []remove.Case{
1515
{
1616
Description: "remove transformers",
17-
Given: remove_test.Given{
17+
Given: remove.Given{
1818
Items: []string{
1919
"transformer1.yaml",
2020
"transformer2.yaml",
2121
"transformer3.yaml",
2222
},
2323
RemoveArgs: []string{"transformer1.yaml"},
2424
},
25-
Expected: remove_test.Expected{
25+
Expected: remove.Expected{
2626
Items: []string{
2727
"transformer2.yaml",
2828
"transformer3.yaml",
@@ -34,7 +34,7 @@ func TestRemoveTransformer(t *testing.T) {
3434
},
3535
{
3636
Description: "remove transformer with pattern",
37-
Given: remove_test.Given{
37+
Given: remove.Given{
3838
Items: []string{
3939
"foo/transformer1.yaml",
4040
"foo/transformer2.yaml",
@@ -43,7 +43,7 @@ func TestRemoveTransformer(t *testing.T) {
4343
},
4444
RemoveArgs: []string{"foo/transformer*.yaml"},
4545
},
46-
Expected: remove_test.Expected{
46+
Expected: remove.Expected{
4747
Items: []string{
4848
"do/not/deleteme/please.yaml",
4949
},
@@ -56,15 +56,15 @@ func TestRemoveTransformer(t *testing.T) {
5656
},
5757
{
5858
Description: "nothing found to remove",
59-
Given: remove_test.Given{
59+
Given: remove.Given{
6060
Items: []string{
6161
"transformer1.yaml",
6262
"transformer2.yaml",
6363
"transformer3.yaml",
6464
},
6565
RemoveArgs: []string{"foo"},
6666
},
67-
Expected: remove_test.Expected{
67+
Expected: remove.Expected{
6868
Items: []string{
6969
"transformer2.yaml",
7070
"transformer3.yaml",
@@ -74,14 +74,14 @@ func TestRemoveTransformer(t *testing.T) {
7474
},
7575
{
7676
Description: "no arguments",
77-
Given: remove_test.Given{},
78-
Expected: remove_test.Expected{
77+
Given: remove.Given{},
78+
Expected: remove.Expected{
7979
Err: errors.Errorf("must specify a transformer file"),
8080
},
8181
},
8282
{
8383
Description: "remove with multiple pattern arguments",
84-
Given: remove_test.Given{
84+
Given: remove.Given{
8585
Items: []string{
8686
"foo/foo.yaml",
8787
"bar/bar.yaml",
@@ -94,7 +94,7 @@ func TestRemoveTransformer(t *testing.T) {
9494
"tra*.yaml",
9595
},
9696
},
97-
Expected: remove_test.Expected{
97+
Expected: remove.Expected{
9898
Items: []string{
9999
"do/not/deleteme/please.yaml",
100100
},
@@ -107,5 +107,5 @@ func TestRemoveTransformer(t *testing.T) {
107107
},
108108
}
109109

110-
remove_test.ExecuteTestCases(t, testCases, "transformers", newCmdRemoveTransformer)
110+
remove.ExecuteRemoveTestCases(t, testCases, "transformers", newCmdRemoveTransformer)
111111
}

kustomize/commands/edit/remove_test/removetest.go renamed to kustomize/commands/internal/remove/remove_testutils.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2022 The Kubernetes Authors.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package remove_test
4+
package remove
55

66
import (
77
"fmt"
@@ -41,11 +41,15 @@ type Case struct {
4141
Expected Expected
4242
}
4343

44-
// ExecuteTestCases executes the provided test cases against the specified command
44+
// ExecuteRemoveTestCases executes the provided test cases against the specified command
4545
// for a particular collection (e.g. ) tests a command defined by the provided
4646
// collection Name (e.g. transformers or resources) and newRemoveCmdToTest function.
47-
func ExecuteTestCases(t *testing.T, testCases []Case, collectionName string,
48-
newRemoveCmdToTest func(filesys.FileSystem) *cobra.Command) {
47+
func ExecuteRemoveTestCases(
48+
t *testing.T,
49+
testCases []Case,
50+
collectionName string,
51+
newRemoveCmdToTest func(filesys.FileSystem) *cobra.Command,
52+
) {
4953
t.Helper()
5054
for _, tc := range testCases {
5155
t.Run(tc.Description, func(t *testing.T) {

0 commit comments

Comments
 (0)