@@ -12,10 +12,11 @@ import (
1212
1313func TestNewYamlRedactor (t * testing.T ) {
1414 tests := []struct {
15- name string
16- path []string
17- inputString string
18- wantString string
15+ name string
16+ path []string
17+ inputString string
18+ wantString string
19+ wantRedactions RedactionList
1920 }{
2021 {
2122 name : "object paths" ,
3233xyz:
3334 hello: {}
3435` ,
36+ wantRedactions : RedactionList {
37+ ByRedactor : map [string ][]Redaction {
38+ "object paths" : []Redaction {
39+ {
40+ RedactorName : "object paths" ,
41+ CharactersRemoved : - 3 ,
42+ Line : 0 ,
43+ File : "testfile" ,
44+ },
45+ },
46+ },
47+ ByFile : map [string ][]Redaction {
48+ "testfile" : []Redaction {
49+ {
50+ RedactorName : "object paths" ,
51+ CharactersRemoved : - 3 ,
52+ Line : 0 ,
53+ File : "testfile" ,
54+ },
55+ },
56+ },
57+ },
3558 },
3659 {
3760 name : "one index in array" ,
5073xyz:
5174 hello: {}
5275` ,
76+ wantRedactions : RedactionList {
77+ ByRedactor : map [string ][]Redaction {
78+ "one index in array" : []Redaction {
79+ {
80+ RedactorName : "one index in array" ,
81+ CharactersRemoved : - 13 ,
82+ Line : 0 ,
83+ File : "testfile" ,
84+ },
85+ },
86+ },
87+ ByFile : map [string ][]Redaction {
88+ "testfile" : []Redaction {
89+ {
90+ RedactorName : "one index in array" ,
91+ CharactersRemoved : - 13 ,
92+ Line : 0 ,
93+ File : "testfile" ,
94+ },
95+ },
96+ },
97+ },
5398 },
5499 {
55100 name : "index after end of array" ,
68113 - b
69114xyz:
70115 hello: {}` ,
116+ wantRedactions : RedactionList {ByRedactor : map [string ][]Redaction {}, ByFile : map [string ][]Redaction {}},
71117 },
72118 {
73119 name : "non-integer index" ,
86132 - b
87133xyz:
88134 hello: {}` ,
135+ wantRedactions : RedactionList {ByRedactor : map [string ][]Redaction {}, ByFile : map [string ][]Redaction {}},
89136 },
90137 {
91138 name : "object paths, no matches" ,
104151 - b
105152xyz:
106153 hello: {}` ,
154+ wantRedactions : RedactionList {ByRedactor : map [string ][]Redaction {}, ByFile : map [string ][]Redaction {}},
107155 },
108156 {
109157 name : "star index in array" ,
@@ -122,6 +170,28 @@ xyz:
122170xyz:
123171 hello: {}
124172` ,
173+ wantRedactions : RedactionList {
174+ ByRedactor : map [string ][]Redaction {
175+ "star index in array" : []Redaction {
176+ {
177+ RedactorName : "star index in array" ,
178+ CharactersRemoved : - 26 ,
179+ Line : 0 ,
180+ File : "testfile" ,
181+ },
182+ },
183+ },
184+ ByFile : map [string ][]Redaction {
185+ "testfile" : []Redaction {
186+ {
187+ RedactorName : "star index in array" ,
188+ CharactersRemoved : - 26 ,
189+ Line : 0 ,
190+ File : "testfile" ,
191+ },
192+ },
193+ },
194+ },
125195 },
126196 {
127197 name : "objects within array index in array" ,
@@ -140,18 +210,42 @@ xyz:
140210xyz:
141211 hello: {}
142212` ,
213+ wantRedactions : RedactionList {
214+ ByRedactor : map [string ][]Redaction {
215+ "objects within array index in array" : []Redaction {
216+ {
217+ RedactorName : "objects within array index in array" ,
218+ CharactersRemoved : - 9 ,
219+ Line : 0 ,
220+ File : "testfile" ,
221+ },
222+ },
223+ },
224+ ByFile : map [string ][]Redaction {
225+ "testfile" : []Redaction {
226+ {
227+ RedactorName : "objects within array index in array" ,
228+ CharactersRemoved : - 9 ,
229+ Line : 0 ,
230+ File : "testfile" ,
231+ },
232+ },
233+ },
234+ },
143235 },
144236 {
145- name : "non-yaml file" ,
146- path : []string {"" },
147- inputString : `hello world, this is not valid yaml: {` ,
148- wantString : `hello world, this is not valid yaml: {` ,
237+ name : "non-yaml file" ,
238+ path : []string {"" },
239+ inputString : `hello world, this is not valid yaml: {` ,
240+ wantString : `hello world, this is not valid yaml: {` ,
241+ wantRedactions : RedactionList {ByRedactor : map [string ][]Redaction {}, ByFile : map [string ][]Redaction {}},
149242 },
150243 {
151- name : "no matches" ,
152- path : []string {"abc" },
153- inputString : `improperly-formatted: yaml` ,
154- wantString : `improperly-formatted: yaml` ,
244+ name : "no matches" ,
245+ path : []string {"abc" },
246+ inputString : `improperly-formatted: yaml` ,
247+ wantString : `improperly-formatted: yaml` ,
248+ wantRedactions : RedactionList {ByRedactor : map [string ][]Redaction {}, ByFile : map [string ][]Redaction {}},
155249 },
156250 {
157251 name : "star index in map" ,
@@ -172,6 +266,28 @@ xyz:
172266xyz:
173267 hello: {}
174268` ,
269+ wantRedactions : RedactionList {
270+ ByRedactor : map [string ][]Redaction {
271+ "star index in map" : []Redaction {
272+ {
273+ RedactorName : "star index in map" ,
274+ CharactersRemoved : - 39 ,
275+ Line : 0 ,
276+ File : "testfile" ,
277+ },
278+ },
279+ },
280+ ByFile : map [string ][]Redaction {
281+ "testfile" : []Redaction {
282+ {
283+ RedactorName : "star index in map" ,
284+ CharactersRemoved : - 39 ,
285+ Line : 0 ,
286+ File : "testfile" ,
287+ },
288+ },
289+ },
290+ },
175291 },
176292 }
177293 for _ , tt := range tests {
@@ -186,6 +302,10 @@ xyz:
186302 gotBytes , err := ioutil .ReadAll (outReader )
187303 req .NoError (err )
188304 req .Equal (tt .wantString , string (gotBytes ))
305+
306+ actualRedactions := GetRedactionList ()
307+ ResetRedactionList ()
308+ req .Equal (tt .wantRedactions , actualRedactions )
189309 })
190310 }
191311}
0 commit comments