@@ -9,17 +9,16 @@ import (
9
9
"testing"
10
10
"time"
11
11
12
+ "github.com/google/go-cmp/cmp"
13
+ "github.com/google/go-cmp/cmp/cmpopts"
14
+ "github.com/google/uuid"
12
15
"github.com/stackitcloud/stackit-cli/internal/pkg/auth"
13
16
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
14
17
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
15
18
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
16
- "github.com/zalando/go-keyring"
17
-
18
- "github.com/google/go-cmp/cmp"
19
- "github.com/google/go-cmp/cmp/cmpopts"
20
- "github.com/google/uuid"
21
19
sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config"
22
20
"github.com/stackitcloud/stackit-sdk-go/services/resourcemanager"
21
+ "github.com/zalando/go-keyring"
23
22
)
24
23
25
24
type testCtxKey struct {}
@@ -495,3 +494,53 @@ func TestFetchProjects(t *testing.T) {
495
494
})
496
495
}
497
496
}
497
+
498
+ func Test_outputResult (t * testing.T ) {
499
+ type args struct {
500
+ outputFormat string
501
+ projects []resourcemanager.Project
502
+ }
503
+ tests := []struct {
504
+ name string
505
+ args args
506
+ wantErr bool
507
+ }{
508
+ {"empty" , args {}, false },
509
+ {"base" , args {"" , []resourcemanager.Project {{}}}, false },
510
+ {"complete" , args {"" , []resourcemanager.Project {
511
+ {
512
+ ContainerId : utils .Ptr ("container-id1" ),
513
+ CreationTime : utils .Ptr (time .Now ()),
514
+ Labels : & map [string ]string {"foo" : "bar" },
515
+ LifecycleState : utils .Ptr (resourcemanager .LIFECYCLESTATE_CREATING ),
516
+ Name : utils .Ptr ("some name" ),
517
+ Parent : & resourcemanager.Parent {
518
+ Id : utils .Ptr ("parent-id" ),
519
+ },
520
+ ProjectId : utils .Ptr ("project-id1" ),
521
+ },
522
+ {
523
+ ContainerId : utils .Ptr ("container-id2" ),
524
+ CreationTime : utils .Ptr (time .Now ()),
525
+ Labels : & map [string ]string {"foo" : "bar" },
526
+ LifecycleState : utils .Ptr (resourcemanager .LIFECYCLESTATE_CREATING ),
527
+ Name : utils .Ptr ("some name" ),
528
+ Parent : & resourcemanager.Parent {
529
+ Id : utils .Ptr ("parent-id" ),
530
+ },
531
+ ProjectId : utils .Ptr ("project-id2" ),
532
+ },
533
+ }}, false },
534
+ }
535
+
536
+ p := print .NewPrinter ()
537
+ p .Cmd = NewCmd (p )
538
+
539
+ for _ , tt := range tests {
540
+ t .Run (tt .name , func (t * testing.T ) {
541
+ if err := outputResult (p , tt .args .outputFormat , tt .args .projects ); (err != nil ) != tt .wantErr {
542
+ t .Errorf ("outputResult() error = %v, wantErr %v" , err , tt .wantErr )
543
+ }
544
+ })
545
+ }
546
+ }
0 commit comments