@@ -43,6 +43,45 @@ func TestParseInput(t *testing.T) {
4343 },
4444 isValid : true ,
4545 },
46+ {
47+ description : "valid input with limit" ,
48+ globalFlags : map [string ]string {
49+ "limit" : "10" ,
50+ },
51+ expectedModel : & inputModel {
52+ GlobalFlagModel : & globalflags.GlobalFlagModel {
53+ Verbosity : globalflags .InfoVerbosity ,
54+ },
55+ Limit : utils .Ptr (int64 (10 )),
56+ },
57+ isValid : true ,
58+ },
59+ {
60+ description : "valid input without limit" ,
61+ globalFlags : map [string ]string {},
62+ expectedModel : & inputModel {
63+ GlobalFlagModel : & globalflags.GlobalFlagModel {
64+ Verbosity : globalflags .InfoVerbosity ,
65+ },
66+ },
67+ isValid : true ,
68+ },
69+ {
70+ description : "invalid limit (zero)" ,
71+ globalFlags : map [string ]string {
72+ "limit" : "0" ,
73+ },
74+ expectedModel : nil ,
75+ isValid : false ,
76+ },
77+ {
78+ description : "invalid limit (negative)" ,
79+ globalFlags : map [string ]string {
80+ "limit" : "-1" ,
81+ },
82+ expectedModel : nil ,
83+ isValid : false ,
84+ },
4685 }
4786
4887 for _ , tt := range tests {
@@ -78,80 +117,81 @@ func TestOutputResult(t *testing.T) {
78117 tests := []struct {
79118 name string
80119 outputFormat string
81- networkList iaas.PublicNetworkListResponse
120+ publicIpRanges [] iaas.PublicNetwork
82121 expectedOutput string
83122 wantErr bool
84123 }{
85124 {
86125 name : "JSON output single" ,
87126 outputFormat : "json" ,
88- networkList : iaas.PublicNetworkListResponse {
89- Items : & []iaas.PublicNetwork {
90- {Cidr : utils .Ptr ("192.168.0.0/24" )},
91- },
127+ publicIpRanges : []iaas.PublicNetwork {
128+ {Cidr : utils .Ptr ("192.168.0.0/24" )},
92129 },
93130 wantErr : false ,
94131 },
95132 {
96133 name : "JSON output multiple" ,
97134 outputFormat : "json" ,
98- networkList : iaas.PublicNetworkListResponse {
99- Items : & []iaas.PublicNetwork {
100- {Cidr : utils .Ptr ("192.168.0.0/24" )},
101- {Cidr : utils .Ptr ("192.167.0.0/24" )},
102- },
135+ publicIpRanges : []iaas.PublicNetwork {
136+ {Cidr : utils .Ptr ("192.168.0.0/24" )},
137+ {Cidr : utils .Ptr ("192.167.0.0/24" )},
103138 },
104139 wantErr : false ,
105140 },
106141 {
107142 name : "YAML output single" ,
108143 outputFormat : "yaml" ,
109- networkList : iaas.PublicNetworkListResponse {
110- Items : & []iaas.PublicNetwork {
111- {Cidr : utils .Ptr ("192.168.0.0/24" )},
112- },
144+ publicIpRanges : []iaas.PublicNetwork {
145+ {Cidr : utils .Ptr ("192.168.0.0/24" )},
113146 },
114147 wantErr : false ,
115148 },
116149 {
117150 name : "YAML output multiple" ,
118151 outputFormat : "yaml" ,
119- networkList : iaas.PublicNetworkListResponse {
120- Items : & []iaas.PublicNetwork {
121- {Cidr : utils .Ptr ("192.168.0.0/24" )},
122- {Cidr : utils .Ptr ("192.167.0.0/24" )},
123- },
152+ publicIpRanges : []iaas.PublicNetwork {
153+ {Cidr : utils .Ptr ("192.168.0.0/24" )},
154+ {Cidr : utils .Ptr ("192.167.0.0/24" )},
124155 },
125156 wantErr : false ,
126157 },
127158 {
128159 name : "pretty output single" ,
129160 outputFormat : "pretty" ,
130- networkList : iaas.PublicNetworkListResponse {
131- Items : & []iaas.PublicNetwork {
132- {Cidr : utils .Ptr ("192.168.0.0/24" )},
133- },
161+ publicIpRanges : []iaas.PublicNetwork {
162+ {Cidr : utils .Ptr ("192.168.0.0/24" )},
134163 },
135164 wantErr : false ,
136165 },
137166 {
138167 name : "pretty output multiple" ,
139168 outputFormat : "pretty" ,
140- networkList : iaas.PublicNetworkListResponse {
141- Items : & []iaas.PublicNetwork {
142- {Cidr : utils .Ptr ("192.168.0.0/24" )},
143- {Cidr : utils .Ptr ("192.167.0.0/24" )},
144- },
169+ publicIpRanges : []iaas.PublicNetwork {
170+ {Cidr : utils .Ptr ("192.168.0.0/24" )},
171+ {Cidr : utils .Ptr ("192.167.0.0/24" )},
145172 },
146173 wantErr : false ,
147174 },
148175 {
149176 name : "default output" ,
150177 outputFormat : "" ,
151- networkList : iaas.PublicNetworkListResponse {
152- Items : & []iaas.PublicNetwork {
153- {Cidr : utils .Ptr ("192.168.0.0/24" )},
154- },
178+ publicIpRanges : []iaas.PublicNetwork {
179+ {Cidr : utils .Ptr ("192.168.0.0/24" )},
180+ },
181+ wantErr : false ,
182+ },
183+ {
184+ name : "empty list" ,
185+ outputFormat : "json" ,
186+ publicIpRanges : []iaas.PublicNetwork {},
187+ wantErr : false ,
188+ },
189+ {
190+ name : "nil CIDR" ,
191+ outputFormat : "pretty" ,
192+ publicIpRanges : []iaas.PublicNetwork {
193+ {Cidr : nil },
194+ {Cidr : utils .Ptr ("192.168.0.0/24" )},
155195 },
156196 wantErr : false ,
157197 },
@@ -161,7 +201,7 @@ func TestOutputResult(t *testing.T) {
161201 t .Run (tt .name , func (t * testing.T ) {
162202 p := print .NewPrinter ()
163203 p .Cmd = NewCmd (& params.CmdParams {Printer : p })
164- err := outputResult (p , tt .outputFormat , tt .networkList )
204+ err := outputResult (p , tt .outputFormat , tt .publicIpRanges )
165205 if (err != nil ) != tt .wantErr {
166206 t .Errorf ("outputResult() error = %v, wantErr %v" , err , tt .wantErr )
167207 }
0 commit comments