@@ -22,28 +22,79 @@ import (
22
22
"github.com/golang/mock/gomock"
23
23
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
24
24
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/mocks"
25
+ "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/pointer"
25
26
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/test"
26
27
atlasv2 "go.mongodb.org/atlas-sdk/v20231115014/admin"
27
28
)
28
29
29
30
func TestList_Run (t * testing.T ) {
30
- ctrl := gomock .NewController (t )
31
- mockStore := mocks .NewMockOrganizationLister (ctrl )
31
+ tests := []struct {
32
+ name string
33
+ expected * atlasv2.PaginatedOrganization
34
+ returnErr error
35
+ }{
36
+ {
37
+ name : "non-nil result" ,
38
+ expected : & atlasv2.PaginatedOrganization {
39
+ Results : & []atlasv2.AtlasOrganization {{}, {}, {}},
40
+ },
41
+ },
42
+ {
43
+ name : "nil result" ,
44
+ expected : & atlasv2.PaginatedOrganization {
45
+ Results : nil ,
46
+ },
47
+ },
48
+ {
49
+ name : "no results" ,
50
+ expected : & atlasv2.PaginatedOrganization {},
51
+ },
52
+ {
53
+ name : "no results" ,
54
+ expected : & atlasv2.PaginatedOrganization {
55
+ Results : & []atlasv2.AtlasOrganization {},
56
+ },
57
+ },
58
+ {
59
+ name : "with results" ,
60
+ expected : & atlasv2.PaginatedOrganization {
61
+ Results : & []atlasv2.AtlasOrganization {
62
+ {
63
+ Id : pointer .Get ("test" ),
64
+ Name : "test" ,
65
+ },
66
+ },
67
+ },
68
+ },
69
+ }
70
+
71
+ for _ , tt := range tests {
72
+ t .Run (tt .name , func (t * testing.T ) {
73
+ t .Parallel ()
74
+ ctrl := gomock .NewController (t )
75
+ defer ctrl .Finish ()
76
+
77
+ mockStore := mocks .NewMockOrganizationLister (ctrl )
78
+ listOpts := & ListOpts {store : mockStore }
32
79
33
- expected := & atlasv2.PaginatedOrganization {}
80
+ mockStore .
81
+ EXPECT ().
82
+ Organizations (listOpts .newOrganizationListOptions ()).
83
+ Return (tt .expected , nil ).
84
+ Times (1 )
34
85
35
- listOpts := & ListOpts {store : mockStore }
86
+ if err := listOpts .Run (); err != nil {
87
+ t .Fatalf ("Run() unexpected error: %v" , err )
88
+ }
36
89
37
- mockStore .
38
- EXPECT ().
39
- Organizations (listOpts .newOrganizationListOptions ()).
40
- Return (expected , nil ).
41
- Times (1 )
90
+ err := listOpts .Print (tt .expected )
91
+ if err != nil {
92
+ t .Fatalf ("Print() unexpected error: %v" , err )
93
+ }
42
94
43
- if err := listOpts . Run (); err != nil {
44
- t . Fatalf ( "Run() unexpected error: %v" , err )
95
+ test . VerifyOutputTemplate ( t , listTemplate , tt . expected )
96
+ } )
45
97
}
46
- test .VerifyOutputTemplate (t , listTemplate , expected )
47
98
}
48
99
49
100
func TestListBuilder (t * testing.T ) {
0 commit comments