@@ -63,64 +63,161 @@ func TestClient_GetOperatorsByISO(t *testing.T) {
63
63
defer teardown ()
64
64
65
65
mux .HandleFunc ("/" , func (rw http.ResponseWriter , req * http.Request ) {
66
- rw .WriteHeader (http .StatusOK )
67
- data := reloadly.Operators {
68
- TotalPages : 5 ,
69
- Size : 20 ,
70
- }
71
-
72
- json .NewEncoder (rw ).Encode (data )
73
-
66
+ rw .WriteHeader (http .StatusInternalServerError )
74
67
})
75
68
76
- body , err := client .GetOperatorsByISO ("011" )
77
- if err != nil {
78
- t .Errorf ("Expected error to be nil but got %q" , err )
69
+ body , err := client .GetOperatorsByISO ("" )
70
+
71
+ if err == nil {
72
+ t .Errorf ("Expected error but got nil" )
79
73
}
80
74
81
- if body . Size != 20 {
82
- t .Errorf ("Expected Size to be 20 but got %v" , body . Size )
75
+ if body != nil {
76
+ t .Errorf ("Expected body to be nil but got %v" , body )
83
77
}
84
78
}
85
79
86
- func TestClient_GetOperators (t * testing.T ) {
80
+
81
+ func TestClient_GetOperatorsById (t * testing.T ) {
87
82
teardown := setup ()
88
83
89
84
defer teardown ()
90
85
91
- mux .HandleFunc ("/operators " , func (rw http.ResponseWriter , req * http.Request ) {
86
+ mux .HandleFunc ("/" , func (rw http.ResponseWriter , req * http.Request ) {
92
87
rw .WriteHeader (http .StatusOK )
93
88
data := reloadly.Operators {
94
- TotalPages : 5 ,
95
- Size : 20 ,
89
+ Name : "testOperator" ,
96
90
}
97
91
98
92
json .NewEncoder (rw ).Encode (data )
99
93
100
94
})
101
95
102
- body , err := client .GetOperators ( )
96
+ body , err := client .GetOperatorsById ( 7 )
103
97
if err != nil {
104
98
t .Errorf ("Expected error to be nil but got %q" , err )
105
99
}
106
100
107
- if body .Size != 20 {
108
- t .Errorf ("Expected Size to be 20 but got %v" , body .Size )
101
+ if body .Name != "testOperator" {
102
+ t .Errorf ("Expected Size to be testOperator but got %v" , body .Name )
109
103
}
110
104
}
111
105
112
- func TestClient_GetOperatorsById (t * testing.T ) {
106
+ func TestClient_GetOperators (t * testing.T ) {
113
107
teardown := setup ()
114
108
115
109
defer teardown ()
116
110
117
- mux .HandleFunc ("/" , func (rw http.ResponseWriter , req * http.Request ) {
111
+ mux .HandleFunc ("/operators " , func (rw http.ResponseWriter , req * http.Request ) {
118
112
rw .WriteHeader (http .StatusInternalServerError )
119
-
120
113
})
121
114
122
- _ , err := client .GetOperators ()
115
+ body , err := client .GetOperators ()
116
+
123
117
if err == nil {
124
118
t .Errorf ("Expected error but got nil" )
125
119
}
120
+
121
+ if body != nil {
122
+ t .Errorf ("Expected body to be nil but got %v" , body )
123
+ }
124
+ }
125
+
126
+ func TestAddSuggestedAmounts (t * testing.T ) {
127
+ cases := [] struct {
128
+ SuggestedAmounts bool
129
+ ExpectedSuggestedAmounts bool
130
+ }{
131
+ {
132
+ SuggestedAmounts : false ,
133
+ ExpectedSuggestedAmounts : false ,
134
+ },
135
+ {
136
+ SuggestedAmounts : true ,
137
+ ExpectedSuggestedAmounts : true ,
138
+ },
139
+ }
140
+
141
+
142
+
143
+ for _ , c := range cases {
144
+ res := reloadly .AddSuggestedAmounts (c .SuggestedAmounts )
145
+ o := & reloadly.OperatorOpts {}
146
+ res (o )
147
+
148
+ if res != nil {
149
+ if c .ExpectedSuggestedAmounts != o .SuggestedAmounts {
150
+ t .Fatalf ("Expected SuggestedAmounts to be %t but got %t" , c .SuggestedAmounts , o .SuggestedAmounts )
151
+ }
152
+
153
+ }
154
+
155
+
156
+ }
157
+ }
158
+
159
+ func TestAddBundles (t * testing.T ) {
160
+ cases := [] struct {
161
+ IncludeBundles bool
162
+ ExpectedIncludeBundles bool
163
+ }{
164
+ {
165
+ IncludeBundles : false ,
166
+ ExpectedIncludeBundles : false ,
167
+ },
168
+ {
169
+ IncludeBundles : true ,
170
+ ExpectedIncludeBundles : true ,
171
+ },
172
+ }
173
+
174
+
175
+
176
+ for _ , c := range cases {
177
+ res := reloadly .AddBundles (c .IncludeBundles )
178
+ o := & reloadly.OperatorOpts {}
179
+ res (o )
180
+
181
+ if res != nil {
182
+ if c .ExpectedIncludeBundles != o .IncludeBundles {
183
+ t .Fatalf ("Expected SuggestedAmounts to be %t but got %t" , c .IncludeBundles , o .IncludeBundles )
184
+ }
185
+
186
+ }
187
+
188
+
189
+ }
190
+ }
191
+
192
+ func TestAddData (t * testing.T ) {
193
+ cases := [] struct {
194
+ IncludeData bool
195
+ ExpectedIncludeData bool
196
+ }{
197
+ {
198
+ IncludeData : false ,
199
+ ExpectedIncludeData : false ,
200
+ },
201
+ {
202
+ IncludeData : true ,
203
+ ExpectedIncludeData : true ,
204
+ },
205
+ }
206
+
207
+
208
+
209
+ for _ , c := range cases {
210
+ res := reloadly .AddData (c .IncludeData )
211
+ o := & reloadly.OperatorOpts {}
212
+ res (o )
213
+
214
+ if res != nil {
215
+ if c .IncludeData != o .IncludeData {
216
+ t .Fatalf ("Expected SuggestedAmounts to be %t but got %t" , c .IncludeData , o .IncludeData )
217
+ }
218
+
219
+ }
220
+
221
+
222
+ }
126
223
}
0 commit comments