-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
removeresource_test.go
111 lines (106 loc) · 2.46 KB
/
removeresource_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package remove
import (
"errors"
"testing"
testutils_test "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/testutils"
)
func TestRemoveResources(t *testing.T) {
testCases := []testutils_test.RemoveTestCase{
{
Description: "remove resources",
Given: testutils_test.RemoveTestGivenValues{
Items: []string{
"resource1.yaml",
"resource2.yaml",
"resource3.yaml",
},
RemoveArgs: []string{"resource1.yaml"},
},
Expected: testutils_test.RemoveTestExpectedValues{
Items: []string{
"resource2.yaml",
"resource3.yaml",
},
Deleted: []string{
"resource1.yaml",
},
},
},
{
Description: "remove resource with pattern",
Given: testutils_test.RemoveTestGivenValues{
Items: []string{
"foo/resource1.yaml",
"foo/resource2.yaml",
"foo/resource3.yaml",
"do/not/deleteme/please.yaml",
},
RemoveArgs: []string{"foo/resource*.yaml"},
},
Expected: testutils_test.RemoveTestExpectedValues{
Items: []string{
"do/not/deleteme/please.yaml",
},
Deleted: []string{
"foo/resource1.yaml",
"foo/resource2.yaml",
"foo/resource3.yaml",
},
},
},
{
Description: "nothing found to remove",
Given: testutils_test.RemoveTestGivenValues{
Items: []string{
"resource1.yaml",
"resource2.yaml",
"resource3.yaml",
},
RemoveArgs: []string{"foo"},
},
Expected: testutils_test.RemoveTestExpectedValues{
Items: []string{
"resource2.yaml",
"resource3.yaml",
"resource1.yaml",
},
},
},
{
Description: "no arguments",
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.RemoveTestGivenValues{
Items: []string{
"foo/foo.yaml",
"bar/bar.yaml",
"resource3.yaml",
"do/not/deleteme/please.yaml",
},
RemoveArgs: []string{
"foo/*.*",
"bar/*.*",
"res*.yaml",
},
},
Expected: testutils_test.RemoveTestExpectedValues{
Items: []string{
"do/not/deleteme/please.yaml",
},
Deleted: []string{
"foo/foo.yaml",
"bar/bar.yaml",
"resource3.yaml",
},
},
},
}
testutils_test.ExecuteRemoveTestCases(t, testCases, "resources", newCmdRemoveResource)
}