@@ -6,13 +6,12 @@ import (
66 "strings"
77 "testing"
88
9- "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
10- "github.com/stackitcloud/stackit-cli/internal/pkg/print"
11- "github.com/stackitcloud/stackit-cli/internal/pkg/utils"
12-
139 "github.com/google/go-cmp/cmp"
1410 "github.com/google/go-cmp/cmp/cmpopts"
1511 "github.com/google/uuid"
12+ "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
13+ "github.com/stackitcloud/stackit-cli/internal/pkg/print"
14+ "github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1615 "github.com/stackitcloud/stackit-sdk-go/services/iaas"
1716)
1817
@@ -372,3 +371,53 @@ func TestBuildRequest(t *testing.T) {
372371 })
373372 }
374373}
374+
375+ func TestOutputResult (t * testing.T ) {
376+ type args struct {
377+ model * inputModel
378+ resp * iaas.ImageCreateResponse
379+ }
380+ tests := []struct {
381+ name string
382+ args args
383+ wantErr bool
384+ }{
385+ {
386+ name : "nil" ,
387+ args : args {
388+ model : nil ,
389+ resp : nil ,
390+ },
391+ wantErr : true ,
392+ },
393+ {
394+ name : "empty input" ,
395+ args : args {
396+ model : & inputModel {},
397+ resp : & iaas.ImageCreateResponse {},
398+ },
399+ wantErr : false ,
400+ },
401+ {
402+ name : "output json" ,
403+ args : args {
404+ model : & inputModel {
405+ GlobalFlagModel : & globalflags.GlobalFlagModel {
406+ OutputFormat : print .JSONOutputFormat ,
407+ },
408+ },
409+ resp : nil ,
410+ },
411+ wantErr : false ,
412+ },
413+ }
414+ p := print .NewPrinter ()
415+ p .Cmd = NewCmd (p )
416+ for _ , tt := range tests {
417+ t .Run (tt .name , func (t * testing.T ) {
418+ if err := outputResult (p , tt .args .model , tt .args .resp ); (err != nil ) != tt .wantErr {
419+ t .Errorf ("outputResult() error = %v, wantErr %v" , err , tt .wantErr )
420+ }
421+ })
422+ }
423+ }
0 commit comments