forked from lamoda/gonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gonkey.json
594 lines (593 loc) · 19.5 KB
/
gonkey.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
{
"$id": "https://raw.githubusercontent.com/lamoda/gonkey/master/gonkey.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Gonkey test automation tool",
"description": "Gonkey described here https://github.com/lamoda/gonkey",
"anyOf": [
{ "$ref": "#/$defs/gonkeyTest" },
{
"type": "array",
"items": { "$ref": "#/$defs/gonkeyTest" }
}
],
"$defs": {
"gonkeyTest": {
"type": "object",
"properties": {
"name":{
"type": "string",
"description": "test name"
},
"description":{
"type": "string",
"description": "test description"
},
"method": {
"type": "string",
"description": "HTTP request type",
"enum": [
"GET",
"POST",
"HEAD",
"PUT",
"DELETE",
"OPTIONS",
"TRACE",
"PATCH",
"CONNECT"
]
},
"path":{
"type": "string",
"description": "HTTP request path"
},
"query":{
"type": "string",
"description": "HTTP request query"
},
"headers":{
"$ref": "#/$defs/headers"
},
"cookies":{
"type":"object",
"description": "map of HTTP request cookies",
"additionalProperties": { "type": "string" }
},
"fixtures":{
"type": "array",
"description": "a list of strings, containing paths to database fixtures",
"items": {"type":"string"}
},
"comparisonParams":{
"type":"object",
"description": "Boolean switches to conrol response checks",
"properties": {
"ignoreValues": { "type": "boolean", "description": "Ignore response body JSON values, validate only parameters names" },
"disallowExtraFields": { "type": "boolean", "description": "Disallow extra JSON parameters in response body" },
"ignoreArraysOrdering": { "type": "boolean", "description": "Ignore JSON arrays elements ordering in response body" },
"ignoreDbOrdering ": { "type": "boolean", "description": "Toggles ignore ordering in DB response" }
}
},
"status": {
"type": "string",
"description": "Test status",
"anyOf": [
{
"const": "focus",
"title": "run only this specific test, and mark all other tests with unset status as skipped"
},
{
"const": "broken",
"title": "do not run test, only mark it as broken"
},
{
"const": "skipped",
"title": "do not run test, skip it"
}
]
},
"mocks":{
"type":"object",
"description": "map of service mocks",
"additionalProperties": {"$ref": "#/$defs/mock"}
},
"beforeScript": {
"type":"object",
"description": "script, that executes after mocks setup and before the HTTP-request is sent",
"properties": {
"path": {
"type": "string",
"description": "string with a path to the script file."
},
"timeout ": {
"type": "integer",
"description": "time in seconds, until stopping the script on timeout. The default value is 3"
}
},
"required": ["path"]
},
"afterRequestScript": {
"type":"object",
"description": "script, that executes after the HTTP-request was sent",
"properties": {
"path": {
"type": "string",
"description": "string with a path to the script file."
},
"timeout ": {
"type": "integer",
"description": "time in seconds, until stopping the script on timeout. The default value is 3"
}
},
"required": ["path"]
},
"dbQuery":{
"$ref": "#/$defs/dbQuery"
},
"dbResponse":{
"$ref": "#/$defs/dbResponse"
},
"dbChecks":{
"type": "array",
"description": "a list of db checks, containing any amount of needed queries, executed after test case",
"items": {
"type":"object",
"properties":{
"dbQuery": {"$ref": "#/$defs/dbQuery"},
"dbResponse": {"$ref": "#/$defs/dbResponse"}
}
}
},
"variables":{
"type":"object",
"description": "map of strings that substituted in placeholders. example of placeholder: {{ $my_variable }}"
},
"request":{
"type":"string",
"description": "string that contains HTTP request body"
},
"response":{
"type":"object",
"description": "numeric HTTP response code (i.e. 200:) with desired response body"
},
"cases":{
"type": "array",
"description": "a list of cases, containing parameters to substitute into variables",
"items": {
"type":"object",
"properties":{
"requestArgs": {"$ref": "#/$defs/requestArgs"},
"responseArgs": {"$ref": "#/$defs/responseArgs"},
"dbQueryArgs": {"$ref": "#/$defs/dbQueryArgs"},
"dbResponseArgs": {"$ref": "#/$defs/requestArgs"}
}
}
}
}
},
"statusCode": {
"type": "integer",
"description": "HTTP-code of the response, the default value is 200"
},
"dbQuery":{
"type": "string",
"description": "a string that contains an SQL query"
},
"dbResponse":{
"type": "array",
"description": "a list of strings, containing JSON objects that the DB request should return",
"items": {"type":"string"}
},
"dbQueryArgs":{
"type":"object",
"description": "map of database request parametrization arguments"
},
"dbResponseArgs":{
"type":"object",
"description": "map of database response parametrization arguments"
},
"requestArgs":{
"type":"object",
"description": "map of HTTP request parametrization arguments"
},
"responseArgs":{
"type":"object",
"description": "numeric HTTP response code (i.e. 200:) with map of parametrization arguments"
},
"headers":{
"type":"object",
"description": "map of HTTP request headers",
"additionalProperties": { "type": "string" }
},
"mock":{
"type": "object",
"required": ["strategy"],
"properties": {
"strategy": {
"type": "string",
"description": "mock strategy",
"anyOf": [
{
"const": "nop",
"title": "Empty strategy. All requests are served with 204 No Content and empty body. No parameters."
},
{
"const": "file",
"title": "Returns a response read from a file."
},
{
"const": "constant",
"title": "Returns a defined response."
},
{
"const": "template",
"title": "This strategy gives ability to use incoming request data into mock response. Implemented with package text/template. Automatically preload incoming request into variable named request"
},
{
"const": "uriVary",
"title": "Uses different response strategies, depending on a path of a requested resource."
},
{
"const": "methodVary",
"title": "Uses various response strategies, depending on the request method."
},
{
"const": "sequence",
"title": "With this strategy for each consequent request you will get a reply defined by a consequent nested strategy."
},
{
"const": "dropRequest",
"title": "The strategy that by default drops the connection on any request. Used to emulate the network problems."
}
]
},
"calls": {
"type": "integer",
"description": "how many times each mock or mock resource must be called"
},
"requestConstraints": {
"description": "list of mock request constraints",
"type": "array",
"items": {
"$ref": "#/$defs/requestConstraint"
}
}
},
"allOf": [
{
"if": {
"properties": { "strategy": { "const": "file" } }
},
"then": {
"properties": {
"filename": {
"type": "string",
"description": "name of the file that contains the response body"
},
"statusCode": {
"$ref": "#/$defs/statusCode"
},
"headers":{
"$ref": "#/$defs/headers"
}
},
"required": ["filename"]
}
},
{
"if": {
"properties": { "strategy": { "const": "constant" } }
},
"then": {
"properties": {
"body": {
"type": "string",
"description": "sets the response body"
},
"statusCode": {
"$ref": "#/$defs/statusCode"
},
"headers":{
"$ref": "#/$defs/headers"
}
},
"required": ["body"]
}
},
{
"if": {
"properties": { "strategy": { "const": "template" } }
},
"then": {
"properties": {
"body": {
"type": "string",
"description": "sets the response body, must be valid text/template string"
},
"statusCode": {
"$ref": "#/$defs/statusCode"
},
"headers":{
"$ref": "#/$defs/headers"
}
},
"required": ["body"]
}
},
{
"if": {
"properties": { "strategy": { "const": "uriVary" } }
},
"then": {
"properties": {
"uris": {
"description": "a map of resources, each resource can be configured as a separate mock-service using any available request constraints and response strategies",
"$ref": "#/$defs/gonkeyTest/properties/mocks"
},
"basePath ":{
"type": "string",
"description": "common base route for all resources, empty by default"
}
},
"required": ["uris"]
}
},
{
"if": {
"properties": { "strategy": { "const": "methodVary" } }
},
"then": {
"properties": {
"methods": {
"description": "a map of methods (GET, POST, etc), each method can be configured as a separate mock-service using any available request constraints and response strategies",
"$ref": "#/$defs/gonkeyTest/properties/mocks"
}
},
"required": ["methods"]
}
},
{
"if": {
"properties": { "strategy": { "const": "sequence" } }
},
"then": {
"properties": {
"sequence": {
"description": "list of nested mock strategies",
"type": "array",
"items": {
"$ref": "#/$defs/mock"
}
}
},
"required": ["sequence"]
}
}
]
},
"requestConstraint":{
"type": "object",
"required": ["kind"],
"properties": {
"kind": {
"type": "string",
"description": "request constraint type",
"anyOf": [
{
"const": "nop",
"title": "Empty constraint. Always successful. No parameters."
},
{
"const": "bodyMatchesJSON",
"title": "Checks that the request body is JSON, and it corresponds to the JSON defined in the body parameter."
},
{
"const": "bodyJSONFieldMatchesJSON",
"title": "When request body is JSON, checks that value of particular JSON-field is string-packed JSON that matches to JSON defined in value parameter"
},
{
"const": "pathMatches",
"title": "Checks that the request path corresponds to the expected one."
},
{
"const": "queryMatches",
"title": "Checks that the GET request parameters correspond to the ones defined in the query parameter."
},
{
"const": "queryMatchesRegexp",
"title": "Checks that the GET request parameters correspond regexp pattern."
},
{
"const": "methodIs",
"title": "Checks that the request method corresponds to the expected one."
},
{
"const": "methodIsGET",
"title": "Checks that the request method corresponds to GET"
},
{
"const": "methodIsPOST",
"title": "Checks that the request method corresponds to POST"
},
{
"const": "headerIs",
"title": "Checks that the request has the defined header and (optional) that its value either equals the pre-defined one or falls under the definition of a regular expression."
},
{
"const": "bodyMatchesText",
"title": "Checks that the request has the defined body text, or it falls under the definition of a regular expression."
},
{
"const": "bodyMatchesXML",
"title": "Checks that the request body is XML, and it matches to the XML defined in the body parameter."
}
]
}
},
"allOf": [
{
"if": {
"properties": { "kind": { "const": "bodyMatchesJSON" } }
},
"then": {
"properties": {
"body": {
"type": "string",
"description": "expected JSON. All keys on all levels defined in this parameter must be present in the request body."
},
"comparisonParams":{
"type":"object",
"description": "Boolean switches to conrol json checks",
"properties": {
"ignoreValues": { "type": "boolean", "description": "Ignore response body JSON values, validate only parameters names" },
"disallowExtraFields": { "type": "boolean", "description": "Disallow extra JSON parameters" },
"ignoreArraysOrdering": { "type": "boolean", "description": "Ignore JSON arrays elements ordering" }
}
}
},
"required": ["body"]
}
},
{
"if": {
"properties": { "kind": { "const": "bodyJSONFieldMatchesJSON" } }
},
"then": {
"properties": {
"path": {
"type": "string",
"description": "path to string field, containing JSON to check"
},
"value": {
"type": "string",
"description": "expected JSON"
},
"comparisonParams":{
"type":"object",
"description": "Boolean switches to conrol json checks",
"properties": {
"ignoreValues": { "type": "boolean", "description": "Ignore response body JSON values, validate only parameters names" },
"disallowExtraFields": { "type": "boolean", "description": "Disallow extra JSON parameters" },
"ignoreArraysOrdering": { "type": "boolean", "description": "Ignore JSON arrays elements ordering" }
}
}
},
"required": ["path","value"]
}
},
{
"if": {
"properties": { "kind": { "const": "pathMatches" } }
},
"then": {
"properties": {
"path": {
"type": "string",
"description": "a string with the expected request path value"
},
"regexp": {
"type": "string",
"description": "a regular expression to check the path value against"
}
}
}
},
{
"if": {
"properties": { "kind": { "const": "queryMatches" } }
},
"then": {
"properties": {
"expectedQuery": {
"type": "string",
"description": "a list of parameters to compare the parameter string to. The order of parameters is not important"
}
},
"required": ["expectedQuery"]
}
},
{
"if": {
"properties": { "kind": { "const": "queryMatchesRegexp" } }
},
"then": {
"properties": {
"expectedQuery": {
"type": "string",
"description": "a list of parameters to compare the parameter string to. The order of parameters is not important"
}
},
"required": ["expectedQuery"]
}
},
{
"if": {
"properties": { "kind": { "const": "methodIs" } }
},
"then": {
"properties": {
"method": {
"type": "string",
"description": "string to compare the request method to"
}
},
"required": ["method"]
}
},
{
"if": {
"properties": { "kind": { "const": "headerIs" } }
},
"then": {
"properties": {
"header": {
"type": "string",
"description": "name of the header that is expected with the request"
},
"value": {
"type": "string",
"description": "a string with the expected request header value"
},
"regexp": {
"type": "string",
"description": "a regular expression to check the header value against"
}
},
"required": ["header"]
}
},
{
"if": {
"properties": { "kind": { "const": "bodyMatchesText" } }
},
"then": {
"properties": {
"body": {
"type": "string",
"description": "a string with the expected request body value"
},
"regexp": {
"type": "string",
"description": "a regular expression to check the body value against"
}
}
}
},
{
"if": {
"properties": { "kind": { "const": "bodyMatchesXML" } }
},
"then": {
"properties": {
"body": {
"type": "string",
"description": "a string with the expected request body value"
}
},
"required": ["body"]
}
}
]
}
}
}