Skip to content

Commit 0c461d6

Browse files
authored
Merge pull request #5495 from stormqueen1990/chore/removetest-internal-package
chore: move removetest.go to the internal package
2 parents b28e044 + 27ae069 commit 0c461d6

File tree

3 files changed

+46
-43
lines changed

3 files changed

+46
-43
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+
testutils_test "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/testutils"
1111
)
1212

1313
func TestRemoveResources(t *testing.T) {
14-
testCases := []remove_test.Case{
14+
testCases := []testutils_test.RemoveTestCase{
1515
{
1616
Description: "remove resources",
17-
Given: remove_test.Given{
17+
Given: testutils_test.RemoveTestGivenValues{
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: testutils_test.RemoveTestExpectedValues{
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: testutils_test.RemoveTestGivenValues{
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: testutils_test.RemoveTestExpectedValues{
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: testutils_test.RemoveTestGivenValues{
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: testutils_test.RemoveTestExpectedValues{
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: testutils_test.RemoveTestGivenValues{},
78+
Expected: testutils_test.RemoveTestExpectedValues{
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: testutils_test.RemoveTestGivenValues{
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: testutils_test.RemoveTestExpectedValues{
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+
testutils_test.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+
testutils_test "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/testutils"
1010
"sigs.k8s.io/kustomize/kyaml/errors"
1111
)
1212

1313
func TestRemoveTransformer(t *testing.T) {
14-
testCases := []remove_test.Case{
14+
testCases := []testutils_test.RemoveTestCase{
1515
{
1616
Description: "remove transformers",
17-
Given: remove_test.Given{
17+
Given: testutils_test.RemoveTestGivenValues{
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: testutils_test.RemoveTestExpectedValues{
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: testutils_test.RemoveTestGivenValues{
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: testutils_test.RemoveTestExpectedValues{
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: testutils_test.RemoveTestGivenValues{
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: testutils_test.RemoveTestExpectedValues{
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: testutils_test.RemoveTestGivenValues{},
78+
Expected: testutils_test.RemoveTestExpectedValues{
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: testutils_test.RemoveTestGivenValues{
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: testutils_test.RemoveTestExpectedValues{
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+
testutils_test.ExecuteRemoveTestCases(t, testCases, "transformers", newCmdRemoveTransformer)
111111
}

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

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

4-
package remove_test
4+
package testutils_test
55

66
import (
77
"fmt"
88
"strings"
99
"testing"
1010

1111
"github.com/spf13/cobra"
12-
testutils_test "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/testutils"
1312
"sigs.k8s.io/kustomize/kyaml/filesys"
1413
)
1514

16-
// Given represents the provided inputs for the test case.
17-
type Given struct {
15+
// RemoveTestGivenValues represents the provided inputs for the test case.
16+
type RemoveTestGivenValues struct {
1817
// Items is the given input items.
1918
Items []string
2019
// RemoveArgs are the arguments to pass to the remove command.
2120
RemoveArgs []string
2221
}
2322

24-
// Expected represents the expected outputs of the test case.
25-
type Expected struct {
26-
// Expected is the collection of expected output items.
23+
// RemoveTestExpectedValues represents the expected outputs of the test case.
24+
type RemoveTestExpectedValues struct {
25+
// RemoveTestExpectedValues is the collection of expected output items.
2726
Items []string
2827
// Deleted is the collection of expected Deleted items (if any).
2928
Deleted []string
3029
// Err represents the error that is expected in the output (if any).
3130
Err error
3231
}
3332

34-
// Case represents a test case to execute.
35-
type Case struct {
33+
// RemoveTestCase represents a test case to execute.
34+
type RemoveTestCase struct {
3635
// Description is the description of the test case.
3736
Description string
3837
// Given is the provided inputs for the test case.
39-
Given Given
38+
Given RemoveTestGivenValues
4039
// Expected is the expected outputs for the test case.
41-
Expected Expected
40+
Expected RemoveTestExpectedValues
4241
}
4342

44-
// ExecuteTestCases executes the provided test cases against the specified command
43+
// ExecuteRemoveTestCases executes the provided test cases against the specified command
4544
// for a particular collection (e.g. ) tests a command defined by the provided
4645
// 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) {
46+
func ExecuteRemoveTestCases(
47+
t *testing.T,
48+
testCases []RemoveTestCase,
49+
collectionName string,
50+
newRemoveCmdToTest func(filesys.FileSystem) *cobra.Command,
51+
) {
4952
t.Helper()
5053
for _, tc := range testCases {
5154
t.Run(tc.Description, func(t *testing.T) {
5255
fSys := filesys.MakeFsInMemory()
53-
testutils_test.WriteTestKustomizationWith(
56+
WriteTestKustomizationWith(
5457
fSys,
5558
[]byte(fmt.Sprintf("%s:\n - %s",
5659
collectionName,
@@ -61,13 +64,13 @@ func ExecuteTestCases(t *testing.T, testCases []Case, collectionName string,
6164
t.Errorf("unexpected cmd error: %v", err)
6265
} else if tc.Expected.Err != nil {
6366
if err.Error() != tc.Expected.Err.Error() {
64-
t.Errorf("expected error did not occurred. Expected: %v. Actual: %v",
67+
t.Errorf("expected error did not occur. Expected: %v. Actual: %v",
6568
tc.Expected.Err,
6669
err)
6770
}
6871
return
6972
}
70-
content, err := testutils_test.ReadTestKustomization(fSys)
73+
content, err := ReadTestKustomization(fSys)
7174
if err != nil {
7275
t.Errorf("unexpected read error: %v", err)
7376
}

0 commit comments

Comments
 (0)