@@ -166,6 +166,102 @@ func TestStub(t *testing.T) {
166
166
handler : addStub ,
167
167
expect : `Success add stub` ,
168
168
},
169
+ {
170
+ name : "add error stub with result code contains" ,
171
+ mock : func () * http.Request {
172
+ payload := `{
173
+ "service": "ErrorStabWithCode",
174
+ "method":"TestMethod",
175
+ "input":{
176
+ "contains":{
177
+ "key": "value",
178
+ "greetings": {
179
+ "hola": "mundo",
180
+ "merhaba": "dunya"
181
+ },
182
+ "cities": ["Istanbul", "Jakarta"]
183
+ }
184
+ },
185
+ "output":{
186
+ "error":"error msg",
187
+ "code": 3
188
+ }
189
+ }`
190
+ return httptest .NewRequest ("POST" , "/add" , bytes .NewReader ([]byte (payload )))
191
+ },
192
+ handler : addStub ,
193
+ expect : `Success add stub` ,
194
+ },
195
+ {
196
+ name : "find error stub with result code contains" ,
197
+ mock : func () * http.Request {
198
+ payload := `{
199
+ "service": "ErrorStabWithCode",
200
+ "method":"TestMethod",
201
+ "data":{
202
+ "key": "value",
203
+ "anotherKey": "anotherValue",
204
+ "greetings": {
205
+ "hola": "mundo",
206
+ "merhaba": "dunya",
207
+ "hello": "world"
208
+ },
209
+ "cities": ["Istanbul", "Jakarta", "Winterfell"]
210
+ }
211
+ }`
212
+ return httptest .NewRequest ("GET" , "/find" , bytes .NewReader ([]byte (payload )))
213
+ },
214
+ handler : handleFindStub ,
215
+ expect : "{\" data\" :null,\" error\" :\" error msg\" ,\" code\" :3}\n " ,
216
+ },
217
+
218
+ {
219
+ name : "add error stub without result code contains" ,
220
+ mock : func () * http.Request {
221
+ payload := `{
222
+ "service": "ErrorStab",
223
+ "method":"TestMethod",
224
+ "input":{
225
+ "contains":{
226
+ "key": "value",
227
+ "greetings": {
228
+ "hola": "mundo",
229
+ "merhaba": "dunya"
230
+ },
231
+ "cities": ["Istanbul", "Jakarta"]
232
+ }
233
+ },
234
+ "output":{
235
+ "error":"error msg"
236
+ }
237
+ }`
238
+ return httptest .NewRequest ("POST" , "/add" , bytes .NewReader ([]byte (payload )))
239
+ },
240
+ handler : addStub ,
241
+ expect : `Success add stub` ,
242
+ },
243
+ {
244
+ name : "find error stub without result code contains" ,
245
+ mock : func () * http.Request {
246
+ payload := `{
247
+ "service": "ErrorStab",
248
+ "method":"TestMethod",
249
+ "data":{
250
+ "key": "value",
251
+ "anotherKey": "anotherValue",
252
+ "greetings": {
253
+ "hola": "mundo",
254
+ "merhaba": "dunya",
255
+ "hello": "world"
256
+ },
257
+ "cities": ["Istanbul", "Jakarta", "Winterfell"]
258
+ }
259
+ }`
260
+ return httptest .NewRequest ("GET" , "/find" , bytes .NewReader ([]byte (payload )))
261
+ },
262
+ handler : handleFindStub ,
263
+ expect : "{\" data\" :null,\" error\" :\" error msg\" }\n " ,
264
+ },
169
265
{
170
266
name : "find nested stub contains" ,
171
267
mock : func () * http.Request {
0 commit comments