@@ -48,6 +48,7 @@ func TestScanCmd_Valid(t *testing.T) {
4848 {args : []string {"scan" , "--tf-provider-version" , "3.30.2" }},
4949 {args : []string {"scan" , "--driftignore" , "./path/to/driftignore.s3" }},
5050 {args : []string {"scan" , "--driftignore" , ".driftignore" }},
51+ {args : []string {"scan" , "-o" , "html://result.html" , "-o" , "json://result.json" }},
5152 }
5253
5354 for _ , tt := range cases {
@@ -164,98 +165,161 @@ func Test_parseFromFlag(t *testing.T) {
164165
165166func Test_parseOutputFlag (t * testing.T ) {
166167 type args struct {
167- out string
168+ out [] string
168169 }
169170 tests := []struct {
170171 name string
171172 args args
172- want * output.OutputConfig
173+ want [] output.OutputConfig
173174 err error
174175 }{
175176 {
176- name : "test empty" ,
177+ name : "test empty output " ,
177178 args : args {
178- out : "" ,
179+ out : [] string { "" } ,
179180 },
180- want : nil ,
181+ want : []output. OutputConfig {} ,
181182 err : fmt .Errorf ("Unable to parse output flag '': \n Accepted formats are: console://,html://PATH/TO/FILE.html,json://PATH/TO/FILE.json,plan://PATH/TO/FILE.json" ),
182183 },
184+ {
185+ name : "test empty array" ,
186+ args : args {
187+ out : []string {},
188+ },
189+ want : []output.OutputConfig {},
190+ err : nil ,
191+ },
183192 {
184193 name : "test invalid" ,
185194 args : args {
186- out : "sdgjsdgjsdg" ,
195+ out : [] string { "sdgjsdgjsdg" } ,
187196 },
188- want : nil ,
197+ want : []output. OutputConfig {} ,
189198 err : fmt .Errorf ("Unable to parse output flag 'sdgjsdgjsdg': \n Accepted formats are: console://,html://PATH/TO/FILE.html,json://PATH/TO/FILE.json,plan://PATH/TO/FILE.json" ),
190199 },
191200 {
192201 name : "test invalid" ,
193202 args : args {
194- out : "://" ,
203+ out : [] string { "://" } ,
195204 },
196- want : nil ,
205+ want : []output. OutputConfig {} ,
197206 err : fmt .Errorf ("Unable to parse output flag '://': \n Accepted formats are: console://,html://PATH/TO/FILE.html,json://PATH/TO/FILE.json,plan://PATH/TO/FILE.json" ),
198207 },
199208 {
200209 name : "test unsupported" ,
201210 args : args {
202- out : "foobar://" ,
211+ out : [] string { "foobar://" } ,
203212 },
204- want : nil ,
213+ want : []output. OutputConfig {} ,
205214 err : fmt .Errorf ("Unsupported output 'foobar': \n Valid formats are: console://,html://PATH/TO/FILE.html,json://PATH/TO/FILE.json,plan://PATH/TO/FILE.json" ),
206215 },
207216 {
208217 name : "test empty json" ,
209218 args : args {
210- out : "json://" ,
219+ out : [] string { "json://" } ,
211220 },
212- want : nil ,
221+ want : []output. OutputConfig {} ,
213222 err : fmt .Errorf ("Invalid json output 'json://': \n Must be of kind: json://PATH/TO/FILE.json" ),
214223 },
215224 {
216225 name : "test valid console" ,
217226 args : args {
218- out : "console://" ,
227+ out : [] string { "console://" } ,
219228 },
220- want : & output.OutputConfig {
221- Key : "console" ,
229+ want : []output.OutputConfig {
230+ {
231+ Key : "console" ,
232+ },
222233 },
223234 err : nil ,
224235 },
225236 {
226237 name : "test valid json" ,
227238 args : args {
228- out : "json:///tmp/foobar.json" ,
239+ out : [] string { "json:///tmp/foobar.json" } ,
229240 },
230- want : & output.OutputConfig {
231- Key : "json" ,
232- Path : "/tmp/foobar.json" ,
241+ want : []output.OutputConfig {
242+ {
243+ Key : "json" ,
244+ Path : "/tmp/foobar.json" ,
245+ },
233246 },
234247 err : nil ,
235248 },
236249 {
237250 name : "test empty jsonplan" ,
238251 args : args {
239- out : "plan://" ,
252+ out : [] string { "plan://" } ,
240253 },
241- want : nil ,
254+ want : []output. OutputConfig {} ,
242255 err : fmt .Errorf ("Invalid plan output 'plan://': \n Must be of kind: plan://PATH/TO/FILE.json" ),
243256 },
244257 {
245258 name : "test valid jsonplan" ,
246259 args : args {
247- out : "plan:///tmp/foobar.json" ,
260+ out : []string {"plan:///tmp/foobar.json" },
261+ },
262+ want : []output.OutputConfig {
263+ {
264+ Key : "plan" ,
265+ Path : "/tmp/foobar.json" ,
266+ },
267+ },
268+ err : nil ,
269+ },
270+ {
271+ name : "test multiple output values" ,
272+ args : args {
273+ out : []string {"console:///dev/stdout" , "json://result.json" },
248274 },
249- want : & output.OutputConfig {
250- Key : "plan" ,
251- Path : "/tmp/foobar.json" ,
275+ want : []output.OutputConfig {
276+ {
277+ Key : "console" ,
278+ },
279+ {
280+ Key : "json" ,
281+ Path : "result.json" ,
282+ },
283+ },
284+ err : nil ,
285+ },
286+ {
287+ name : "test multiple output values with invalid value" ,
288+ args : args {
289+ out : []string {"console:///dev/stdout" , "invalid://result.json" },
290+ },
291+ want : []output.OutputConfig {
292+ {
293+ Key : "console" ,
294+ },
295+ },
296+ err : fmt .Errorf ("Unsupported output 'invalid': \n Valid formats are: console://,html://PATH/TO/FILE.html,json://PATH/TO/FILE.json,plan://PATH/TO/FILE.json" ),
297+ },
298+ {
299+ name : "test multiple valid output values" ,
300+ args : args {
301+ out : []string {"json://result1.json" , "json://result2.json" , "json://result3.json" },
302+ },
303+ want : []output.OutputConfig {
304+ {
305+ Key : "json" ,
306+ Path : "result1.json" ,
307+ },
308+ {
309+ Key : "json" ,
310+ Path : "result2.json" ,
311+ },
312+ {
313+ Key : "json" ,
314+ Path : "result3.json" ,
315+ },
252316 },
253317 err : nil ,
254318 },
255319 }
256320 for _ , tt := range tests {
257321 t .Run (tt .name , func (t * testing.T ) {
258- got , err := parseOutputFlag (tt .args .out )
322+ got , err := parseOutputFlags (tt .args .out )
259323 if err != nil && err .Error () != tt .err .Error () {
260324 t .Fatalf ("got error = '%v', expected '%v'" , err , tt .err )
261325 }
0 commit comments