@@ -86,7 +86,7 @@ func TestSelectMissingSelectedField(t *testing.T) {
8686 }
8787}
8888
89- func TestRedact (t * testing.T ) {
89+ func TestRedactSecret (t * testing.T ) {
9090 resource := & unstructured.Unstructured {
9191 Object : map [string ]interface {}{
9292 "apiVersion" : "v1" ,
@@ -137,6 +137,48 @@ func TestRedact(t *testing.T) {
137137 }
138138}
139139
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+
140182func TestRedactMissingField (t * testing.T ) {
141183 resource := & unstructured.Unstructured {
142184 Object : map [string ]interface {}{
0 commit comments