Skip to content

Commit

Permalink
fix: rename helper structs to use more specific names
Browse files Browse the repository at this point in the history
  • Loading branch information
stormqueen1990 committed Dec 22, 2023
1 parent 42d5870 commit 27ae069
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 34 deletions.
22 changes: 11 additions & 11 deletions kustomize/commands/edit/remove/removeresource_test.go
Expand Up @@ -11,18 +11,18 @@ import (
)

func TestRemoveResources(t *testing.T) {
testCases := []testutils_test.Case{
testCases := []testutils_test.RemoveTestCase{
{
Description: "remove resources",
Given: testutils_test.Given{
Given: testutils_test.RemoveTestGivenValues{
Items: []string{
"resource1.yaml",
"resource2.yaml",
"resource3.yaml",
},
RemoveArgs: []string{"resource1.yaml"},
},
Expected: testutils_test.Expected{
Expected: testutils_test.RemoveTestExpectedValues{
Items: []string{
"resource2.yaml",
"resource3.yaml",
Expand All @@ -34,7 +34,7 @@ func TestRemoveResources(t *testing.T) {
},
{
Description: "remove resource with pattern",
Given: testutils_test.Given{
Given: testutils_test.RemoveTestGivenValues{
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: testutils_test.Expected{
Expected: testutils_test.RemoveTestExpectedValues{
Items: []string{
"do/not/deleteme/please.yaml",
},
Expand All @@ -56,15 +56,15 @@ func TestRemoveResources(t *testing.T) {
},
{
Description: "nothing found to remove",
Given: testutils_test.Given{
Given: testutils_test.RemoveTestGivenValues{
Items: []string{
"resource1.yaml",
"resource2.yaml",
"resource3.yaml",
},
RemoveArgs: []string{"foo"},
},
Expected: testutils_test.Expected{
Expected: testutils_test.RemoveTestExpectedValues{
Items: []string{
"resource2.yaml",
"resource3.yaml",
Expand All @@ -74,14 +74,14 @@ func TestRemoveResources(t *testing.T) {
},
{
Description: "no arguments",
Given: testutils_test.Given{},
Expected: testutils_test.Expected{
Given: testutils_test.RemoveTestGivenValues{},
Expected: testutils_test.RemoveTestExpectedValues{
Err: errors.New("must specify a resource file"),
},
},
{
Description: "remove with multiple pattern arguments",
Given: testutils_test.Given{
Given: testutils_test.RemoveTestGivenValues{
Items: []string{
"foo/foo.yaml",
"bar/bar.yaml",
Expand All @@ -94,7 +94,7 @@ func TestRemoveResources(t *testing.T) {
"res*.yaml",
},
},
Expected: testutils_test.Expected{
Expected: testutils_test.RemoveTestExpectedValues{
Items: []string{
"do/not/deleteme/please.yaml",
},
Expand Down
23 changes: 11 additions & 12 deletions kustomize/commands/edit/remove/removetransformer_test.go
Expand Up @@ -7,23 +7,22 @@ import (
"testing"

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

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

func TestRemoveTransformer(t *testing.T) {
testCases := []testutils_test.Case{
testCases := []testutils_test.RemoveTestCase{
{
Description: "remove transformers",
Given: testutils_test.Given{
Given: testutils_test.RemoveTestGivenValues{
Items: []string{
"transformer1.yaml",
"transformer2.yaml",
"transformer3.yaml",
},
RemoveArgs: []string{"transformer1.yaml"},
},
Expected: testutils_test.Expected{
Expected: testutils_test.RemoveTestExpectedValues{
Items: []string{
"transformer2.yaml",
"transformer3.yaml",
Expand All @@ -35,7 +34,7 @@ func TestRemoveTransformer(t *testing.T) {
},
{
Description: "remove transformer with pattern",
Given: testutils_test.Given{
Given: testutils_test.RemoveTestGivenValues{
Items: []string{
"foo/transformer1.yaml",
"foo/transformer2.yaml",
Expand All @@ -44,7 +43,7 @@ func TestRemoveTransformer(t *testing.T) {
},
RemoveArgs: []string{"foo/transformer*.yaml"},
},
Expected: testutils_test.Expected{
Expected: testutils_test.RemoveTestExpectedValues{
Items: []string{
"do/not/deleteme/please.yaml",
},
Expand All @@ -57,15 +56,15 @@ func TestRemoveTransformer(t *testing.T) {
},
{
Description: "nothing found to remove",
Given: testutils_test.Given{
Given: testutils_test.RemoveTestGivenValues{
Items: []string{
"transformer1.yaml",
"transformer2.yaml",
"transformer3.yaml",
},
RemoveArgs: []string{"foo"},
},
Expected: testutils_test.Expected{
Expected: testutils_test.RemoveTestExpectedValues{
Items: []string{
"transformer2.yaml",
"transformer3.yaml",
Expand All @@ -75,14 +74,14 @@ func TestRemoveTransformer(t *testing.T) {
},
{
Description: "no arguments",
Given: testutils_test.Given{},
Expected: testutils_test.Expected{
Given: testutils_test.RemoveTestGivenValues{},
Expected: testutils_test.RemoveTestExpectedValues{
Err: errors.Errorf("must specify a transformer file"),
},
},
{
Description: "remove with multiple pattern arguments",
Given: testutils_test.Given{
Given: testutils_test.RemoveTestGivenValues{
Items: []string{
"foo/foo.yaml",
"bar/bar.yaml",
Expand All @@ -95,7 +94,7 @@ func TestRemoveTransformer(t *testing.T) {
"tra*.yaml",
},
},
Expected: testutils_test.Expected{
Expected: testutils_test.RemoveTestExpectedValues{
Items: []string{
"do/not/deleteme/please.yaml",
},
Expand Down
22 changes: 11 additions & 11 deletions kustomize/commands/internal/testutils/remove_testutils.go
Expand Up @@ -12,40 +12,40 @@ import (
"sigs.k8s.io/kustomize/kyaml/filesys"
)

// Given represents the provided inputs for the test case.
type Given struct {
// RemoveTestGivenValues represents the provided inputs for the test case.
type RemoveTestGivenValues struct {
// Items is the given input items.
Items []string
// RemoveArgs are the arguments to pass to the remove command.
RemoveArgs []string
}

// Expected represents the expected outputs of the test case.
type Expected struct {
// Expected is the collection of expected output items.
// RemoveTestExpectedValues represents the expected outputs of the test case.
type RemoveTestExpectedValues struct {
// RemoveTestExpectedValues is the collection of expected output items.
Items []string
// Deleted is the collection of expected Deleted items (if any).
Deleted []string
// Err represents the error that is expected in the output (if any).
Err error
}

// Case represents a test case to execute.
type Case struct {
// RemoveTestCase represents a test case to execute.
type RemoveTestCase struct {
// Description is the description of the test case.
Description string
// Given is the provided inputs for the test case.
Given Given
Given RemoveTestGivenValues
// Expected is the expected outputs for the test case.
Expected Expected
Expected RemoveTestExpectedValues
}

// 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 ExecuteRemoveTestCases(
t *testing.T,
testCases []Case,
testCases []RemoveTestCase,
collectionName string,
newRemoveCmdToTest func(filesys.FileSystem) *cobra.Command,
) {
Expand All @@ -64,7 +64,7 @@ func ExecuteRemoveTestCases(
t.Errorf("unexpected cmd error: %v", err)
} else if tc.Expected.Err != nil {
if err.Error() != tc.Expected.Err.Error() {
t.Errorf("expected error did not occurred. Expected: %v. Actual: %v",
t.Errorf("expected error did not occur. Expected: %v. Actual: %v",
tc.Expected.Err,
err)
}
Expand Down

0 comments on commit 27ae069

Please sign in to comment.