@@ -9,17 +9,16 @@ import (
99 "testing"
1010 "time"
1111
12+ "github.com/google/go-cmp/cmp"
13+ "github.com/google/go-cmp/cmp/cmpopts"
14+ "github.com/google/uuid"
1215 "github.com/stackitcloud/stackit-cli/internal/pkg/auth"
1316 "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1417 "github.com/stackitcloud/stackit-cli/internal/pkg/print"
1518 "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"
2119 sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config"
2220 "github.com/stackitcloud/stackit-sdk-go/services/resourcemanager"
21+ "github.com/zalando/go-keyring"
2322)
2423
2524type testCtxKey struct {}
@@ -495,3 +494,53 @@ func TestFetchProjects(t *testing.T) {
495494 })
496495 }
497496}
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