@@ -294,3 +294,47 @@ func TestBuildRequest(t *testing.T) {
294294 })
295295 }
296296}
297+
298+ func TestOutputResult (t * testing.T ) {
299+ tests := []struct {
300+ description string
301+ model * inputModel
302+ instance * logs.LogsInstance
303+ wantErr bool
304+ }{
305+ {
306+ description : "nil response" ,
307+ instance : nil ,
308+ wantErr : true ,
309+ },
310+ {
311+ description : "default output" ,
312+ instance : & logs.LogsInstance {},
313+ model : & inputModel {GlobalFlagModel : & globalflags.GlobalFlagModel {}},
314+ wantErr : false ,
315+ },
316+ {
317+ description : "json output" ,
318+ instance : & logs.LogsInstance {},
319+ model : & inputModel {GlobalFlagModel : & globalflags.GlobalFlagModel {OutputFormat : print .JSONOutputFormat }},
320+ wantErr : false ,
321+ },
322+ {
323+ description : "yaml output" ,
324+ instance : & logs.LogsInstance {},
325+ model : & inputModel {GlobalFlagModel : & globalflags.GlobalFlagModel {OutputFormat : print .YAMLOutputFormat }},
326+ wantErr : false ,
327+ },
328+ }
329+
330+ p := print .NewPrinter ()
331+ p .Cmd = NewCmd (& types.CmdParams {Printer : p })
332+ for _ , tt := range tests {
333+ t .Run (tt .description , func (t * testing.T ) {
334+ err := outputResult (p , tt .model , "label" , tt .instance )
335+ if (err != nil ) != tt .wantErr {
336+ t .Errorf ("outputResult() error = %v, wantErr %v" , err , tt .wantErr )
337+ }
338+ })
339+ }
340+ }
0 commit comments