@@ -86,7 +86,7 @@ func TestSelectMissingSelectedField(t *testing.T) {
86
86
}
87
87
}
88
88
89
- func TestRedact (t * testing.T ) {
89
+ func TestRedactSecret (t * testing.T ) {
90
90
resource := & unstructured.Unstructured {
91
91
Object : map [string ]interface {}{
92
92
"apiVersion" : "v1" ,
@@ -137,6 +137,48 @@ func TestRedact(t *testing.T) {
137
137
}
138
138
}
139
139
140
+ func TestRedactPod (t * testing.T ) {
141
+ resource := & unstructured.Unstructured {
142
+ Object : map [string ]interface {}{
143
+ "apiVersion" : "v1" ,
144
+ "kind" : "Pod" ,
145
+ "metadata" : map [string ]interface {}{
146
+ "name" : "example" ,
147
+ "namespace" : "example" ,
148
+ "managedFields" : []interface {}{},
149
+ },
150
+ "spec" : map [string ]interface {}{
151
+ "serviceAccountName" : "example" ,
152
+ },
153
+ },
154
+ }
155
+
156
+ fieldsToRedact := []string {
157
+ "metadata.managedFields" ,
158
+ }
159
+
160
+ err := Redact (fieldsToRedact , resource )
161
+ if err != nil {
162
+ t .Fatalf ("unexpected error: %s" , err )
163
+ }
164
+
165
+ bytes , err := json .MarshalIndent (resource , "" , " " )
166
+ expectedJSON := `{
167
+ "apiVersion": "v1",
168
+ "kind": "Pod",
169
+ "metadata": {
170
+ "name": "example",
171
+ "namespace": "example"
172
+ },
173
+ "spec": {
174
+ "serviceAccountName": "example"
175
+ }
176
+ }`
177
+ if string (bytes ) != expectedJSON {
178
+ t .Fatalf ("unexpected JSON: \n got \n %s\n want\n %s" , string (bytes ), expectedJSON )
179
+ }
180
+ }
181
+
140
182
func TestRedactMissingField (t * testing.T ) {
141
183
resource := & unstructured.Unstructured {
142
184
Object : map [string ]interface {}{
0 commit comments