@pact-foundation/pact-core 13.7.6 → 13.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/build/Makefile +1 -1
- package/ffi/libpact_ffi.dylib +0 -0
- package/ffi/libpact_ffi.so +0 -0
- package/ffi/libpact_ffi.so.gz +0 -0
- package/ffi/osxaarch64/libpact_ffi.dylib +0 -0
- package/ffi/pact-cpp.h +715 -35
- package/ffi/pact.h +718 -35
- package/ffi/pact_ffi.dll +0 -0
- package/ffi/pact_ffi.dll.lib +0 -0
- package/package.json +1 -1
- package/src/ffi/index.d.ts +1 -1
- package/src/ffi/index.js +1 -1
- package/src/ffi/types.d.ts +2 -2
- package/src/verifier/argumentMapper/arguments.d.ts +4 -0
- package/src/verifier/argumentMapper/arguments.js +43 -27
- package/src/verifier/argumentMapper/arguments.js.map +1 -1
- package/src/verifier/argumentMapper/index.js +9 -5
- package/src/verifier/argumentMapper/index.js.map +1 -1
package/ffi/pact.h
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
#ifndef pact_ffi_h
|
|
8
8
|
#define pact_ffi_h
|
|
9
9
|
|
|
10
|
-
/* Generated with cbindgen:0.
|
|
10
|
+
/* Generated with cbindgen:0.24.3 */
|
|
11
11
|
|
|
12
12
|
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
|
|
13
13
|
|
|
@@ -133,6 +133,11 @@ typedef struct MismatchesIterator MismatchesIterator;
|
|
|
133
133
|
*/
|
|
134
134
|
typedef struct PactMessageIterator PactMessageIterator;
|
|
135
135
|
|
|
136
|
+
/**
|
|
137
|
+
* An iterator over synchronous HTTP request/response interactions in a pact.
|
|
138
|
+
*/
|
|
139
|
+
typedef struct PactSyncHttpIterator PactSyncHttpIterator;
|
|
140
|
+
|
|
136
141
|
/**
|
|
137
142
|
* An iterator over synchronous request/response messages in a pact.
|
|
138
143
|
*/
|
|
@@ -161,6 +166,11 @@ typedef struct ProviderStateIterator ProviderStateIterator;
|
|
|
161
166
|
*/
|
|
162
167
|
typedef struct ProviderStateParamIterator ProviderStateParamIterator;
|
|
163
168
|
|
|
169
|
+
/**
|
|
170
|
+
* V4 HTTP Interaction Type
|
|
171
|
+
*/
|
|
172
|
+
typedef struct SynchronousHttp SynchronousHttp;
|
|
173
|
+
|
|
164
174
|
/**
|
|
165
175
|
* Synchronous interactions as a request message to a sequence of response messages
|
|
166
176
|
*/
|
|
@@ -264,13 +274,14 @@ typedef uint16_t MessagePactHandle;
|
|
|
264
274
|
typedef uint32_t MessageHandle;
|
|
265
275
|
|
|
266
276
|
/**
|
|
267
|
-
*
|
|
277
|
+
* Returns the current library version
|
|
268
278
|
*/
|
|
269
279
|
const char *pactffi_version(void);
|
|
270
280
|
|
|
271
281
|
/**
|
|
272
282
|
* Initialise the mock server library, can provide an environment variable name to use to
|
|
273
|
-
* set the log levels.
|
|
283
|
+
* set the log levels. This function should only be called once, as it tries to install a global
|
|
284
|
+
* tracing subscriber.
|
|
274
285
|
*
|
|
275
286
|
* # Safety
|
|
276
287
|
*
|
|
@@ -279,7 +290,8 @@ const char *pactffi_version(void);
|
|
|
279
290
|
void pactffi_init(const char *log_env_var);
|
|
280
291
|
|
|
281
292
|
/**
|
|
282
|
-
* Initialises logging, and sets the log level explicitly.
|
|
293
|
+
* Initialises logging, and sets the log level explicitly. This function should only be called
|
|
294
|
+
* once, as it tries to install a global tracing subscriber.
|
|
283
295
|
*
|
|
284
296
|
* # Safety
|
|
285
297
|
*
|
|
@@ -430,7 +442,7 @@ int pactffi_log_to_file(const char *file_name, enum LevelFilter level_filter);
|
|
|
430
442
|
int pactffi_log_to_buffer(enum LevelFilter level_filter);
|
|
431
443
|
|
|
432
444
|
/**
|
|
433
|
-
* Initialize the
|
|
445
|
+
* Initialize the FFI logger with no sinks.
|
|
434
446
|
*
|
|
435
447
|
* This initialized logger does nothing until `pactffi_logger_apply` has been called.
|
|
436
448
|
*
|
|
@@ -451,7 +463,7 @@ void pactffi_logger_init(void);
|
|
|
451
463
|
*
|
|
452
464
|
* This logger does nothing until `pactffi_logger_apply` has been called.
|
|
453
465
|
*
|
|
454
|
-
*
|
|
466
|
+
* Types of sinks can be specified:
|
|
455
467
|
*
|
|
456
468
|
* - stdout (`pactffi_logger_attach_sink("stdout", LevelFilter_Info)`)
|
|
457
469
|
* - stderr (`pactffi_logger_attach_sink("stderr", LevelFilter_Debug)`)
|
|
@@ -478,22 +490,25 @@ void pactffi_logger_init(void);
|
|
|
478
490
|
* # Safety
|
|
479
491
|
*
|
|
480
492
|
* This function checks the validity of the passed-in sink specifier, and errors
|
|
481
|
-
* out if the specifier isn't valid UTF-8.
|
|
493
|
+
* out if the specifier isn't valid UTF-8. Passing in an invalid or NULL pointer will result in
|
|
494
|
+
* undefined behaviour.
|
|
482
495
|
*/
|
|
483
496
|
int pactffi_logger_attach_sink(const char *sink_specifier,
|
|
484
497
|
enum LevelFilter level_filter);
|
|
485
498
|
|
|
486
499
|
/**
|
|
487
|
-
* Apply the
|
|
500
|
+
* Apply the previously configured sinks and levels to the program. If no sinks have been setup,
|
|
501
|
+
* will set the log level to info and the target to standard out.
|
|
488
502
|
*
|
|
489
|
-
*
|
|
503
|
+
* This function will install a global tracing subscriber. Any attempts to modify the logger
|
|
504
|
+
* after the call to `logger_apply` will fail.
|
|
490
505
|
*/
|
|
491
506
|
int pactffi_logger_apply(void);
|
|
492
507
|
|
|
493
508
|
/**
|
|
494
509
|
* Fetch the in-memory logger buffer contents. This will only have any contents if the `buffer`
|
|
495
510
|
* sink has been configured to log to. The contents will be allocated on the heap and will need
|
|
496
|
-
* to be freed with `
|
|
511
|
+
* to be freed with `pactffi_string_delete`.
|
|
497
512
|
*
|
|
498
513
|
* Fetches the logs associated with the provided identifier, or uses the "global" one if the
|
|
499
514
|
* identifier is not specified (i.e. NULL).
|
|
@@ -610,6 +625,23 @@ void pactffi_message_delete(struct Message *message);
|
|
|
610
625
|
*/
|
|
611
626
|
const char *pactffi_message_get_contents(const struct Message *message);
|
|
612
627
|
|
|
628
|
+
/**
|
|
629
|
+
* Sets the contents of the message.
|
|
630
|
+
*
|
|
631
|
+
* # Safety
|
|
632
|
+
*
|
|
633
|
+
* The message contents and content type must either be NULL pointers, or point to valid
|
|
634
|
+
* UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined.
|
|
635
|
+
*
|
|
636
|
+
* # Error Handling
|
|
637
|
+
*
|
|
638
|
+
* If the contents is a NULL pointer, it will set the message contents as null. If the content
|
|
639
|
+
* type is a null pointer, or can't be parsed, it will set the content type as unknown.
|
|
640
|
+
*/
|
|
641
|
+
void pactffi_message_set_contents(struct Message *message,
|
|
642
|
+
const char *contents,
|
|
643
|
+
const char *content_type);
|
|
644
|
+
|
|
613
645
|
/**
|
|
614
646
|
* Get the length of the contents of a `Message`.
|
|
615
647
|
*
|
|
@@ -640,6 +672,24 @@ size_t pactffi_message_get_contents_length(const struct Message *message);
|
|
|
640
672
|
*/
|
|
641
673
|
const unsigned char *pactffi_message_get_contents_bin(const struct Message *message);
|
|
642
674
|
|
|
675
|
+
/**
|
|
676
|
+
* Sets the contents of the message as an array of bytes.
|
|
677
|
+
*
|
|
678
|
+
* # Safety
|
|
679
|
+
*
|
|
680
|
+
* The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned
|
|
681
|
+
* and consecutive. Otherwise behaviour is undefined.
|
|
682
|
+
*
|
|
683
|
+
* # Error Handling
|
|
684
|
+
*
|
|
685
|
+
* If the contents is a NULL pointer, it will set the message contents as null. If the content
|
|
686
|
+
* type is a null pointer, or can't be parsed, it will set the content type as unknown.
|
|
687
|
+
*/
|
|
688
|
+
void pactffi_message_set_contents_bin(struct Message *message,
|
|
689
|
+
const unsigned char *contents,
|
|
690
|
+
size_t len,
|
|
691
|
+
const char *content_type);
|
|
692
|
+
|
|
643
693
|
/**
|
|
644
694
|
* Get a copy of the description.
|
|
645
695
|
*
|
|
@@ -1084,6 +1134,8 @@ void pactffi_pact_message_iter_delete(struct PactMessageIterator *iter);
|
|
|
1084
1134
|
* iterator, they do not need to be deleted but will be cleaned up when the iterator is
|
|
1085
1135
|
* deleted.
|
|
1086
1136
|
*
|
|
1137
|
+
* Will return a NULL pointer when the iterator has advanced past the end of the list.
|
|
1138
|
+
*
|
|
1087
1139
|
* # Safety
|
|
1088
1140
|
*
|
|
1089
1141
|
* This function is safe.
|
|
@@ -1101,6 +1153,8 @@ struct Message *pactffi_pact_message_iter_next(struct PactMessageIterator *iter)
|
|
|
1101
1153
|
* iterator, they do not need to be deleted but will be cleaned up when the iterator is
|
|
1102
1154
|
* deleted.
|
|
1103
1155
|
*
|
|
1156
|
+
* Will return a NULL pointer when the iterator has advanced past the end of the list.
|
|
1157
|
+
*
|
|
1104
1158
|
* # Safety
|
|
1105
1159
|
*
|
|
1106
1160
|
* This function is safe.
|
|
@@ -1118,6 +1172,43 @@ struct SynchronousMessage *pactffi_pact_sync_message_iter_next(struct PactSyncMe
|
|
|
1118
1172
|
*/
|
|
1119
1173
|
void pactffi_pact_sync_message_iter_delete(struct PactSyncMessageIterator *iter);
|
|
1120
1174
|
|
|
1175
|
+
/**
|
|
1176
|
+
* Get the next synchronous HTTP request/response interaction from the pact. As the
|
|
1177
|
+
* interactions returned are owned by the iterator, they do not need to be deleted but
|
|
1178
|
+
* will be cleaned up when the iterator is deleted.
|
|
1179
|
+
*
|
|
1180
|
+
* Will return a NULL pointer when the iterator has advanced past the end of the list.
|
|
1181
|
+
*
|
|
1182
|
+
* # Safety
|
|
1183
|
+
*
|
|
1184
|
+
* This function is safe.
|
|
1185
|
+
*
|
|
1186
|
+
* Deleting an interaction returned by the iterator can lead to undefined behaviour.
|
|
1187
|
+
*
|
|
1188
|
+
* # Error Handling
|
|
1189
|
+
*
|
|
1190
|
+
* This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
|
|
1191
|
+
*/
|
|
1192
|
+
struct SynchronousHttp *pactffi_pact_sync_http_iter_next(struct PactSyncHttpIterator *iter);
|
|
1193
|
+
|
|
1194
|
+
/**
|
|
1195
|
+
* Free the iterator when you're done using it.
|
|
1196
|
+
*/
|
|
1197
|
+
void pactffi_pact_sync_http_iter_delete(struct PactSyncHttpIterator *iter);
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* Get a mutable pointer to a newly-created default message on the heap.
|
|
1201
|
+
*
|
|
1202
|
+
* # Safety
|
|
1203
|
+
*
|
|
1204
|
+
* This function is safe.
|
|
1205
|
+
*
|
|
1206
|
+
* # Error Handling
|
|
1207
|
+
*
|
|
1208
|
+
* Returns NULL on error.
|
|
1209
|
+
*/
|
|
1210
|
+
struct SynchronousMessage *pactffi_sync_message_new(void);
|
|
1211
|
+
|
|
1121
1212
|
/**
|
|
1122
1213
|
* Destroy the `Message` being pointed to.
|
|
1123
1214
|
*/
|
|
@@ -1141,6 +1232,27 @@ void pactffi_sync_message_delete(struct SynchronousMessage *message);
|
|
|
1141
1232
|
*/
|
|
1142
1233
|
const char *pactffi_sync_message_get_request_contents(const struct SynchronousMessage *message);
|
|
1143
1234
|
|
|
1235
|
+
/**
|
|
1236
|
+
* Sets the request contents of the message.
|
|
1237
|
+
*
|
|
1238
|
+
* * `message` - the message to set the request contents for
|
|
1239
|
+
* * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer.
|
|
1240
|
+
* * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
|
|
1241
|
+
*
|
|
1242
|
+
* # Safety
|
|
1243
|
+
*
|
|
1244
|
+
* The message contents and content type must either be NULL pointers, or point to valid
|
|
1245
|
+
* UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined.
|
|
1246
|
+
*
|
|
1247
|
+
* # Error Handling
|
|
1248
|
+
*
|
|
1249
|
+
* If the contents is a NULL pointer, it will set the message contents as null. If the content
|
|
1250
|
+
* type is a null pointer, or can't be parsed, it will set the content type as unknown.
|
|
1251
|
+
*/
|
|
1252
|
+
void pactffi_sync_message_set_request_contents(struct SynchronousMessage *message,
|
|
1253
|
+
const char *contents,
|
|
1254
|
+
const char *content_type);
|
|
1255
|
+
|
|
1144
1256
|
/**
|
|
1145
1257
|
* Get the length of the request contents of a `SynchronousMessage`.
|
|
1146
1258
|
*
|
|
@@ -1171,6 +1283,29 @@ size_t pactffi_sync_message_get_request_contents_length(const struct Synchronous
|
|
|
1171
1283
|
*/
|
|
1172
1284
|
const unsigned char *pactffi_sync_message_get_request_contents_bin(const struct SynchronousMessage *message);
|
|
1173
1285
|
|
|
1286
|
+
/**
|
|
1287
|
+
* Sets the request contents of the message as an array of bytes.
|
|
1288
|
+
*
|
|
1289
|
+
* * `message` - the message to set the request contents for
|
|
1290
|
+
* * `contents` - pointer to contents to copy from
|
|
1291
|
+
* * `len` - number of bytes to copy from the contents pointer
|
|
1292
|
+
* * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
|
|
1293
|
+
*
|
|
1294
|
+
* # Safety
|
|
1295
|
+
*
|
|
1296
|
+
* The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned
|
|
1297
|
+
* and consecutive. Otherwise behaviour is undefined.
|
|
1298
|
+
*
|
|
1299
|
+
* # Error Handling
|
|
1300
|
+
*
|
|
1301
|
+
* If the contents is a NULL pointer, it will set the message contents as null. If the content
|
|
1302
|
+
* type is a null pointer, or can't be parsed, it will set the content type as unknown.
|
|
1303
|
+
*/
|
|
1304
|
+
void pactffi_sync_message_set_request_contents_bin(struct SynchronousMessage *message,
|
|
1305
|
+
const unsigned char *contents,
|
|
1306
|
+
size_t len,
|
|
1307
|
+
const char *content_type);
|
|
1308
|
+
|
|
1174
1309
|
/**
|
|
1175
1310
|
* Get the number of response messages in the `SynchronousMessage`.
|
|
1176
1311
|
*
|
|
@@ -1204,6 +1339,30 @@ size_t pactffi_sync_message_get_number_responses(const struct SynchronousMessage
|
|
|
1204
1339
|
const char *pactffi_sync_message_get_response_contents(const struct SynchronousMessage *message,
|
|
1205
1340
|
size_t index);
|
|
1206
1341
|
|
|
1342
|
+
/**
|
|
1343
|
+
* Sets the response contents of the message. If index is greater than the number of responses
|
|
1344
|
+
* in the message, the responses will be padded with default values.
|
|
1345
|
+
*
|
|
1346
|
+
* * `message` - the message to set the response contents for
|
|
1347
|
+
* * `index` - index of the response to set. 0 is the first response.
|
|
1348
|
+
* * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer.
|
|
1349
|
+
* * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
|
|
1350
|
+
*
|
|
1351
|
+
* # Safety
|
|
1352
|
+
*
|
|
1353
|
+
* The message contents and content type must either be NULL pointers, or point to valid
|
|
1354
|
+
* UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined.
|
|
1355
|
+
*
|
|
1356
|
+
* # Error Handling
|
|
1357
|
+
*
|
|
1358
|
+
* If the contents is a NULL pointer, it will set the response contents as null. If the content
|
|
1359
|
+
* type is a null pointer, or can't be parsed, it will set the content type as unknown.
|
|
1360
|
+
*/
|
|
1361
|
+
void pactffi_sync_message_set_response_contents(struct SynchronousMessage *message,
|
|
1362
|
+
size_t index,
|
|
1363
|
+
const char *contents,
|
|
1364
|
+
const char *content_type);
|
|
1365
|
+
|
|
1207
1366
|
/**
|
|
1208
1367
|
* Get the length of the response contents of a `SynchronousMessage`.
|
|
1209
1368
|
*
|
|
@@ -1236,6 +1395,33 @@ size_t pactffi_sync_message_get_response_contents_length(const struct Synchronou
|
|
|
1236
1395
|
const unsigned char *pactffi_sync_message_get_response_contents_bin(const struct SynchronousMessage *message,
|
|
1237
1396
|
size_t index);
|
|
1238
1397
|
|
|
1398
|
+
/**
|
|
1399
|
+
* Sets the response contents of the message at the given index as an array of bytes. If index
|
|
1400
|
+
* is greater than the number of responses in the message, the responses will be padded with
|
|
1401
|
+
* default values.
|
|
1402
|
+
*
|
|
1403
|
+
* * `message` - the message to set the response contents for
|
|
1404
|
+
* * `index` - index of the response to set. 0 is the first response
|
|
1405
|
+
* * `contents` - pointer to contents to copy from
|
|
1406
|
+
* * `len` - number of bytes to copy
|
|
1407
|
+
* * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
|
|
1408
|
+
*
|
|
1409
|
+
* # Safety
|
|
1410
|
+
*
|
|
1411
|
+
* The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned
|
|
1412
|
+
* and consecutive. Otherwise behaviour is undefined.
|
|
1413
|
+
*
|
|
1414
|
+
* # Error Handling
|
|
1415
|
+
*
|
|
1416
|
+
* If the contents is a NULL pointer, it will set the message contents as null. If the content
|
|
1417
|
+
* type is a null pointer, or can't be parsed, it will set the content type as unknown.
|
|
1418
|
+
*/
|
|
1419
|
+
void pactffi_sync_message_set_response_contents_bin(struct SynchronousMessage *message,
|
|
1420
|
+
size_t index,
|
|
1421
|
+
const unsigned char *contents,
|
|
1422
|
+
size_t len,
|
|
1423
|
+
const char *content_type);
|
|
1424
|
+
|
|
1239
1425
|
/**
|
|
1240
1426
|
* Get a copy of the description.
|
|
1241
1427
|
*
|
|
@@ -1306,23 +1492,301 @@ const struct ProviderState *pactffi_sync_message_get_provider_state(const struct
|
|
|
1306
1492
|
*/
|
|
1307
1493
|
struct ProviderStateIterator *pactffi_sync_message_get_provider_state_iter(struct SynchronousMessage *message);
|
|
1308
1494
|
|
|
1495
|
+
/**
|
|
1496
|
+
* Get a mutable pointer to a newly-created default interaction on the heap.
|
|
1497
|
+
*
|
|
1498
|
+
* # Safety
|
|
1499
|
+
*
|
|
1500
|
+
* This function is safe.
|
|
1501
|
+
*
|
|
1502
|
+
* # Error Handling
|
|
1503
|
+
*
|
|
1504
|
+
* Returns NULL on error.
|
|
1505
|
+
*/
|
|
1506
|
+
struct SynchronousHttp *pactffi_sync_http_new(void);
|
|
1507
|
+
|
|
1508
|
+
/**
|
|
1509
|
+
* Destroy the `SynchronousHttp` interaction being pointed to.
|
|
1510
|
+
*/
|
|
1511
|
+
void pactffi_sync_http_delete(struct SynchronousHttp *interaction);
|
|
1512
|
+
|
|
1513
|
+
/**
|
|
1514
|
+
* Get the request contents of a `SynchronousHttp` interaction in string form.
|
|
1515
|
+
*
|
|
1516
|
+
* # Safety
|
|
1517
|
+
*
|
|
1518
|
+
* The returned string must be deleted with `pactffi_string_delete`.
|
|
1519
|
+
*
|
|
1520
|
+
* The returned string can outlive the interaction.
|
|
1521
|
+
*
|
|
1522
|
+
* # Error Handling
|
|
1523
|
+
*
|
|
1524
|
+
* If the interaction is NULL, returns NULL. If the body of the request
|
|
1525
|
+
* is missing, then this function also returns NULL. This means there's
|
|
1526
|
+
* no mechanism to differentiate with this function call alone between
|
|
1527
|
+
* a NULL body and a missing body.
|
|
1528
|
+
*/
|
|
1529
|
+
const char *pactffi_sync_http_get_request_contents(const struct SynchronousHttp *interaction);
|
|
1530
|
+
|
|
1531
|
+
/**
|
|
1532
|
+
* Sets the request contents of the interaction.
|
|
1533
|
+
*
|
|
1534
|
+
* * `interaction` - the interaction to set the request contents for
|
|
1535
|
+
* * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer.
|
|
1536
|
+
* * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
|
|
1537
|
+
*
|
|
1538
|
+
* # Safety
|
|
1539
|
+
*
|
|
1540
|
+
* The request contents and content type must either be NULL pointers, or point to valid
|
|
1541
|
+
* UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined.
|
|
1542
|
+
*
|
|
1543
|
+
* # Error Handling
|
|
1544
|
+
*
|
|
1545
|
+
* If the contents is a NULL pointer, it will set the request contents as null. If the content
|
|
1546
|
+
* type is a null pointer, or can't be parsed, it will set the content type as unknown.
|
|
1547
|
+
*/
|
|
1548
|
+
void pactffi_sync_http_set_request_contents(struct SynchronousHttp *interaction,
|
|
1549
|
+
const char *contents,
|
|
1550
|
+
const char *content_type);
|
|
1551
|
+
|
|
1552
|
+
/**
|
|
1553
|
+
* Get the length of the request contents of a `SynchronousHttp` interaction.
|
|
1554
|
+
*
|
|
1555
|
+
* # Safety
|
|
1556
|
+
*
|
|
1557
|
+
* This function is safe.
|
|
1558
|
+
*
|
|
1559
|
+
* # Error Handling
|
|
1560
|
+
*
|
|
1561
|
+
* If the interaction is NULL, returns 0. If the body of the request
|
|
1562
|
+
* is missing, then this function also returns 0.
|
|
1563
|
+
*/
|
|
1564
|
+
size_t pactffi_sync_http_get_request_contents_length(const struct SynchronousHttp *interaction);
|
|
1565
|
+
|
|
1566
|
+
/**
|
|
1567
|
+
* Get the request contents of a `SynchronousHttp` interaction as a pointer to an array of bytes.
|
|
1568
|
+
*
|
|
1569
|
+
* # Safety
|
|
1570
|
+
*
|
|
1571
|
+
* The number of bytes in the buffer will be returned by `pactffi_sync_http_get_request_contents_length`.
|
|
1572
|
+
* It is safe to use the pointer while the interaction is not deleted or changed. Using the pointer
|
|
1573
|
+
* after the interaction is mutated or deleted may lead to undefined behaviour.
|
|
1574
|
+
*
|
|
1575
|
+
* # Error Handling
|
|
1576
|
+
*
|
|
1577
|
+
* If the interaction is NULL, returns NULL. If the body of the request
|
|
1578
|
+
* is missing, then this function also returns NULL.
|
|
1579
|
+
*/
|
|
1580
|
+
const unsigned char *pactffi_sync_http_get_request_contents_bin(const struct SynchronousHttp *interaction);
|
|
1581
|
+
|
|
1582
|
+
/**
|
|
1583
|
+
* Sets the request contents of the interaction as an array of bytes.
|
|
1584
|
+
*
|
|
1585
|
+
* * `interaction` - the interaction to set the request contents for
|
|
1586
|
+
* * `contents` - pointer to contents to copy from
|
|
1587
|
+
* * `len` - number of bytes to copy from the contents pointer
|
|
1588
|
+
* * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
|
|
1589
|
+
*
|
|
1590
|
+
* # Safety
|
|
1591
|
+
*
|
|
1592
|
+
* The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned
|
|
1593
|
+
* and consecutive. Otherwise behaviour is undefined.
|
|
1594
|
+
*
|
|
1595
|
+
* # Error Handling
|
|
1596
|
+
*
|
|
1597
|
+
* If the contents is a NULL pointer, it will set the request contents as null. If the content
|
|
1598
|
+
* type is a null pointer, or can't be parsed, it will set the content type as unknown.
|
|
1599
|
+
*/
|
|
1600
|
+
void pactffi_sync_http_set_request_contents_bin(struct SynchronousHttp *interaction,
|
|
1601
|
+
const unsigned char *contents,
|
|
1602
|
+
size_t len,
|
|
1603
|
+
const char *content_type);
|
|
1604
|
+
|
|
1605
|
+
/**
|
|
1606
|
+
* Get the response contents of a `SynchronousHttp` interaction in string form.
|
|
1607
|
+
*
|
|
1608
|
+
* # Safety
|
|
1609
|
+
*
|
|
1610
|
+
* The returned string must be deleted with `pactffi_string_delete`.
|
|
1611
|
+
*
|
|
1612
|
+
* The returned string can outlive the interaction.
|
|
1613
|
+
*
|
|
1614
|
+
* # Error Handling
|
|
1615
|
+
*
|
|
1616
|
+
* If the interaction is NULL, returns NULL.
|
|
1617
|
+
*
|
|
1618
|
+
* If the body of the response is missing, then this function also returns NULL.
|
|
1619
|
+
* This means there's no mechanism to differentiate with this function call alone between
|
|
1620
|
+
* a NULL body and a missing body.
|
|
1621
|
+
*/
|
|
1622
|
+
const char *pactffi_sync_http_get_response_contents(const struct SynchronousHttp *interaction);
|
|
1623
|
+
|
|
1624
|
+
/**
|
|
1625
|
+
* Sets the response contents of the interaction.
|
|
1626
|
+
*
|
|
1627
|
+
* * `interaction` - the interaction to set the response contents for
|
|
1628
|
+
* * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer.
|
|
1629
|
+
* * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
|
|
1630
|
+
*
|
|
1631
|
+
* # Safety
|
|
1632
|
+
*
|
|
1633
|
+
* The response contents and content type must either be NULL pointers, or point to valid
|
|
1634
|
+
* UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined.
|
|
1635
|
+
*
|
|
1636
|
+
* # Error Handling
|
|
1637
|
+
*
|
|
1638
|
+
* If the contents is a NULL pointer, it will set the response contents as null. If the content
|
|
1639
|
+
* type is a null pointer, or can't be parsed, it will set the content type as unknown.
|
|
1640
|
+
*/
|
|
1641
|
+
void pactffi_sync_http_set_response_contents(struct SynchronousHttp *interaction,
|
|
1642
|
+
const char *contents,
|
|
1643
|
+
const char *content_type);
|
|
1644
|
+
|
|
1645
|
+
/**
|
|
1646
|
+
* Get the length of the response contents of a `SynchronousHttp` interaction.
|
|
1647
|
+
*
|
|
1648
|
+
* # Safety
|
|
1649
|
+
*
|
|
1650
|
+
* This function is safe.
|
|
1651
|
+
*
|
|
1652
|
+
* # Error Handling
|
|
1653
|
+
*
|
|
1654
|
+
* If the interaction is NULL or the index is not valid, returns 0. If the body of the response
|
|
1655
|
+
* is missing, then this function also returns 0.
|
|
1656
|
+
*/
|
|
1657
|
+
size_t pactffi_sync_http_get_response_contents_length(const struct SynchronousHttp *interaction);
|
|
1658
|
+
|
|
1659
|
+
/**
|
|
1660
|
+
* Get the response contents of a `SynchronousHttp` interaction as a pointer to an array of bytes.
|
|
1661
|
+
*
|
|
1662
|
+
* # Safety
|
|
1663
|
+
*
|
|
1664
|
+
* The number of bytes in the buffer will be returned by `pactffi_sync_http_get_response_contents_length`.
|
|
1665
|
+
* It is safe to use the pointer while the interaction is not deleted or changed. Using the pointer
|
|
1666
|
+
* after the interaction is mutated or deleted may lead to undefined behaviour.
|
|
1667
|
+
*
|
|
1668
|
+
* # Error Handling
|
|
1669
|
+
*
|
|
1670
|
+
* If the interaction is NULL, returns NULL. If the body of the response
|
|
1671
|
+
* is missing, then this function also returns NULL.
|
|
1672
|
+
*/
|
|
1673
|
+
const unsigned char *pactffi_sync_http_get_response_contents_bin(const struct SynchronousHttp *interaction);
|
|
1674
|
+
|
|
1675
|
+
/**
|
|
1676
|
+
* Sets the response contents of the `SynchronousHttp` interaction as an array of bytes.
|
|
1677
|
+
*
|
|
1678
|
+
* * `interaction` - the interaction to set the response contents for
|
|
1679
|
+
* * `contents` - pointer to contents to copy from
|
|
1680
|
+
* * `len` - number of bytes to copy
|
|
1681
|
+
* * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
|
|
1682
|
+
*
|
|
1683
|
+
* # Safety
|
|
1684
|
+
*
|
|
1685
|
+
* The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned
|
|
1686
|
+
* and consecutive. Otherwise behaviour is undefined.
|
|
1687
|
+
*
|
|
1688
|
+
* # Error Handling
|
|
1689
|
+
*
|
|
1690
|
+
* If the contents is a NULL pointer, it will set the response contents as null. If the content
|
|
1691
|
+
* type is a null pointer, or can't be parsed, it will set the content type as unknown.
|
|
1692
|
+
*/
|
|
1693
|
+
void pactffi_sync_http_set_response_contents_bin(struct SynchronousHttp *interaction,
|
|
1694
|
+
const unsigned char *contents,
|
|
1695
|
+
size_t len,
|
|
1696
|
+
const char *content_type);
|
|
1697
|
+
|
|
1698
|
+
/**
|
|
1699
|
+
* Get a copy of the description.
|
|
1700
|
+
*
|
|
1701
|
+
* # Safety
|
|
1702
|
+
*
|
|
1703
|
+
* The returned string must be deleted with `pactffi_string_delete`.
|
|
1704
|
+
*
|
|
1705
|
+
* Since it is a copy, the returned string may safely outlive
|
|
1706
|
+
* the `SynchronousHttp` interaction.
|
|
1707
|
+
*
|
|
1708
|
+
* # Errors
|
|
1709
|
+
*
|
|
1710
|
+
* On failure, this function will return a NULL pointer.
|
|
1711
|
+
*
|
|
1712
|
+
* This function may fail if the Rust string contains embedded
|
|
1713
|
+
* null ('\0') bytes.
|
|
1714
|
+
*/
|
|
1715
|
+
const char *pactffi_sync_http_get_description(const struct SynchronousHttp *interaction);
|
|
1716
|
+
|
|
1717
|
+
/**
|
|
1718
|
+
* Write the `description` field on the `SynchronousHttp`.
|
|
1719
|
+
*
|
|
1720
|
+
* # Safety
|
|
1721
|
+
*
|
|
1722
|
+
* `description` must contain valid UTF-8. Invalid UTF-8
|
|
1723
|
+
* will be replaced with U+FFFD REPLACEMENT CHARACTER.
|
|
1724
|
+
*
|
|
1725
|
+
* This function will only reallocate if the new string
|
|
1726
|
+
* does not fit in the existing buffer.
|
|
1727
|
+
*
|
|
1728
|
+
* # Error Handling
|
|
1729
|
+
*
|
|
1730
|
+
* Errors will be reported with a non-zero return value.
|
|
1731
|
+
*/
|
|
1732
|
+
int pactffi_sync_http_set_description(struct SynchronousHttp *interaction, const char *description);
|
|
1733
|
+
|
|
1734
|
+
/**
|
|
1735
|
+
* Get a copy of the provider state at the given index from this interaction.
|
|
1736
|
+
*
|
|
1737
|
+
* # Safety
|
|
1738
|
+
*
|
|
1739
|
+
* The returned structure must be deleted with `provider_state_delete`.
|
|
1740
|
+
*
|
|
1741
|
+
* Since it is a copy, the returned structure may safely outlive
|
|
1742
|
+
* the `SynchronousHttp`.
|
|
1743
|
+
*
|
|
1744
|
+
* # Error Handling
|
|
1745
|
+
*
|
|
1746
|
+
* On failure, this function will return a variant other than Success.
|
|
1747
|
+
*
|
|
1748
|
+
* This function may fail if the index requested is out of bounds,
|
|
1749
|
+
* or if any of the Rust strings contain embedded null ('\0') bytes.
|
|
1750
|
+
*/
|
|
1751
|
+
const struct ProviderState *pactffi_sync_http_get_provider_state(const struct SynchronousHttp *interaction,
|
|
1752
|
+
unsigned int index);
|
|
1753
|
+
|
|
1754
|
+
/**
|
|
1755
|
+
* Get an iterator over provider states.
|
|
1756
|
+
*
|
|
1757
|
+
* # Safety
|
|
1758
|
+
*
|
|
1759
|
+
* The underlying data must not change during iteration.
|
|
1760
|
+
*
|
|
1761
|
+
* # Error Handling
|
|
1762
|
+
*
|
|
1763
|
+
* Returns NULL if an error occurs.
|
|
1764
|
+
*/
|
|
1765
|
+
struct ProviderStateIterator *pactffi_sync_http_get_provider_state_iter(struct SynchronousHttp *interaction);
|
|
1766
|
+
|
|
1309
1767
|
/**
|
|
1310
1768
|
* Delete a string previously returned by this FFI.
|
|
1311
1769
|
*
|
|
1312
1770
|
* It is explicitly allowed to pass a null pointer to this function;
|
|
1313
1771
|
* in that case the function will do nothing.
|
|
1772
|
+
*
|
|
1773
|
+
* # Safety
|
|
1774
|
+
* Passing an invalid pointer, or one that was not returned by a FFI function can result in
|
|
1775
|
+
* undefined behaviour.
|
|
1314
1776
|
*/
|
|
1315
1777
|
void pactffi_string_delete(char *string);
|
|
1316
1778
|
|
|
1317
1779
|
/**
|
|
1318
|
-
* External interface to create a mock server. A pointer to the pact JSON as a C
|
|
1319
|
-
* as well as the port for the mock server to run on. A value of 0 for the
|
|
1320
|
-
* port being allocated by the operating system. The port of the mock server is returned.
|
|
1780
|
+
* [DEPRECATED] External interface to create a HTTP mock server. A pointer to the pact JSON as a NULL-terminated C
|
|
1781
|
+
* string is passed in, as well as the port for the mock server to run on. A value of 0 for the
|
|
1782
|
+
* port will result in a port being allocated by the operating system. The port of the mock server is returned.
|
|
1321
1783
|
*
|
|
1322
1784
|
* * `pact_str` - Pact JSON
|
|
1323
1785
|
* * `addr_str` - Address to bind to in the form name:port (i.e. 127.0.0.1:0)
|
|
1324
1786
|
* * `tls` - boolean flag to indicate of the mock server should use TLS (using a self-signed certificate)
|
|
1325
1787
|
*
|
|
1788
|
+
* This function is deprecated and replaced with `pactffi_create_mock_server_for_transport`.
|
|
1789
|
+
*
|
|
1326
1790
|
* # Errors
|
|
1327
1791
|
*
|
|
1328
1792
|
* Errors are returned as negative values.
|
|
@@ -1345,30 +1809,32 @@ int32_t pactffi_create_mock_server(const char *pact_str,
|
|
|
1345
1809
|
* Fetch the CA Certificate used to generate the self-signed certificate for the TLS mock server.
|
|
1346
1810
|
*
|
|
1347
1811
|
* **NOTE:** The string for the result is allocated on the heap, and will have to be freed
|
|
1348
|
-
* by the caller using
|
|
1812
|
+
* by the caller using pactffi_string_delete.
|
|
1349
1813
|
*
|
|
1350
1814
|
* # Errors
|
|
1351
1815
|
*
|
|
1352
|
-
* An empty string indicates an error reading the pem file
|
|
1816
|
+
* An empty string indicates an error reading the pem file.
|
|
1353
1817
|
*/
|
|
1354
1818
|
char *pactffi_get_tls_ca_certificate(void);
|
|
1355
1819
|
|
|
1356
1820
|
/**
|
|
1357
|
-
* External interface to create a mock server. A Pact handle is passed in,
|
|
1821
|
+
* [DEPRECATED] External interface to create a HTTP mock server. A Pact handle is passed in,
|
|
1358
1822
|
* as well as the port for the mock server to run on. A value of 0 for the port will result in a
|
|
1359
1823
|
* port being allocated by the operating system. The port of the mock server is returned.
|
|
1360
1824
|
*
|
|
1361
|
-
* * `pact` - Handle to a Pact model
|
|
1362
|
-
* * `addr_str` - Address to bind to in the form name:port (i.e. 127.0.0.1:0)
|
|
1825
|
+
* * `pact` - Handle to a Pact model created with created with `pactffi_new_pact`.
|
|
1826
|
+
* * `addr_str` - Address to bind to in the form name:port (i.e. 127.0.0.1:0). Must be a valid UTF-8 NULL-terminated string.
|
|
1363
1827
|
* * `tls` - boolean flag to indicate of the mock server should use TLS (using a self-signed certificate)
|
|
1364
1828
|
*
|
|
1829
|
+
* This function is deprecated and replaced with `pactffi_create_mock_server_for_transport`.
|
|
1830
|
+
*
|
|
1365
1831
|
* # Errors
|
|
1366
1832
|
*
|
|
1367
1833
|
* Errors are returned as negative values.
|
|
1368
1834
|
*
|
|
1369
1835
|
* | Error | Description |
|
|
1370
1836
|
* |-------|-------------|
|
|
1371
|
-
* | -1 | An invalid handle was received |
|
|
1837
|
+
* | -1 | An invalid handle was received. Handles should be created with `pactffi_new_pact` |
|
|
1372
1838
|
* | -3 | The mock server could not be started |
|
|
1373
1839
|
* | -4 | The method panicked |
|
|
1374
1840
|
* | -5 | The address is not valid |
|
|
@@ -1379,6 +1845,44 @@ int32_t pactffi_create_mock_server_for_pact(PactHandle pact,
|
|
|
1379
1845
|
const char *addr_str,
|
|
1380
1846
|
bool tls);
|
|
1381
1847
|
|
|
1848
|
+
/**
|
|
1849
|
+
* Create a mock server for the provided Pact handle and transport. If the transport is not
|
|
1850
|
+
* provided (it is a NULL pointer or an empty string), will default to an HTTP transport. The
|
|
1851
|
+
* address is the interface bind to, and will default to the loopback adapter if not specified.
|
|
1852
|
+
* Specifying a value of zero for the port will result in the operating system allocating the port.
|
|
1853
|
+
*
|
|
1854
|
+
* Parameters:
|
|
1855
|
+
* * `pact` - Handle to a Pact model created with created with `pactffi_new_pact`.
|
|
1856
|
+
* * `addr` - Address to bind to (i.e. `127.0.0.1` or `[::1]`). Must be a valid UTF-8 NULL-terminated string, or NULL or empty, in which case the loopback adapter is used.
|
|
1857
|
+
* * `port` - Port number to bind to. A value of zero will result in the operating system allocating an available port.
|
|
1858
|
+
* * `transport` - The transport to use (i.e. http, https, grpc). Must be a valid UTF-8 NULL-terminated string, or NULL or empty, in which case http will be used.
|
|
1859
|
+
* * `transport_config` - (OPTIONAL) Configuration for the transport as a valid JSON string. Set to NULL or empty if not required.
|
|
1860
|
+
*
|
|
1861
|
+
* The port of the mock server is returned.
|
|
1862
|
+
*
|
|
1863
|
+
* # Safety
|
|
1864
|
+
* NULL pointers or empty strings can be passed in for the address, transport and transport_config,
|
|
1865
|
+
* in which case a default value will be used. Passing in an invalid pointer will result in undefined behaviour.
|
|
1866
|
+
*
|
|
1867
|
+
* # Errors
|
|
1868
|
+
*
|
|
1869
|
+
* Errors are returned as negative values.
|
|
1870
|
+
*
|
|
1871
|
+
* | Error | Description |
|
|
1872
|
+
* |-------|-------------|
|
|
1873
|
+
* | -1 | An invalid handle was received. Handles should be created with `pactffi_new_pact` |
|
|
1874
|
+
* | -2 | transport_config is not valid JSON |
|
|
1875
|
+
* | -3 | The mock server could not be started |
|
|
1876
|
+
* | -4 | The method panicked |
|
|
1877
|
+
* | -5 | The address is not valid |
|
|
1878
|
+
*
|
|
1879
|
+
*/
|
|
1880
|
+
int32_t pactffi_create_mock_server_for_transport(PactHandle pact,
|
|
1881
|
+
const char *addr,
|
|
1882
|
+
uint16_t port,
|
|
1883
|
+
const char *transport,
|
|
1884
|
+
const char *transport_config);
|
|
1885
|
+
|
|
1382
1886
|
/**
|
|
1383
1887
|
* External interface to check if a mock server has matched all its requests. The port number is
|
|
1384
1888
|
* passed in, and if all requests have been matched, true is returned. False is returned if there
|
|
@@ -1445,41 +1949,46 @@ const char *pactffi_mock_server_logs(int32_t mock_server_port);
|
|
|
1445
1949
|
|
|
1446
1950
|
/**
|
|
1447
1951
|
* Generates a datetime value from the provided format string, using the current system date and time
|
|
1448
|
-
* NOTE: The memory for the returned string needs to be freed with the
|
|
1952
|
+
* NOTE: The memory for the returned string needs to be freed with the `pactffi_string_delete` function
|
|
1449
1953
|
*
|
|
1450
1954
|
* # Safety
|
|
1451
1955
|
*
|
|
1452
|
-
*
|
|
1956
|
+
* If the format string pointer is NULL or has invalid UTF-8 characters, an error result will be
|
|
1957
|
+
* returned. If the format string pointer is not a valid pointer or is not a NULL-terminated string,
|
|
1958
|
+
* this will lead to undefined behaviour.
|
|
1453
1959
|
*/
|
|
1454
1960
|
struct StringResult pactffi_generate_datetime_string(const char *format);
|
|
1455
1961
|
|
|
1456
1962
|
/**
|
|
1457
|
-
* Checks that the example string matches the given regex
|
|
1963
|
+
* Checks that the example string matches the given regex.
|
|
1458
1964
|
*
|
|
1459
1965
|
* # Safety
|
|
1460
1966
|
*
|
|
1461
|
-
*
|
|
1967
|
+
* Both the regex and example pointers must be valid pointers to NULL-terminated strings. Invalid
|
|
1968
|
+
* pointers will result in undefined behaviour.
|
|
1462
1969
|
*/
|
|
1463
1970
|
bool pactffi_check_regex(const char *regex, const char *example);
|
|
1464
1971
|
|
|
1465
1972
|
/**
|
|
1466
1973
|
* Generates an example string based on the provided regex.
|
|
1467
|
-
* NOTE: The memory for the returned string needs to be freed with the
|
|
1974
|
+
* NOTE: The memory for the returned string needs to be freed with the `pactffi_string_delete` function.
|
|
1468
1975
|
*
|
|
1469
1976
|
* # Safety
|
|
1470
1977
|
*
|
|
1471
|
-
*
|
|
1978
|
+
* The regex pointer must be a valid pointer to a NULL-terminated string. Invalid pointers will
|
|
1979
|
+
* result in undefined behaviour.
|
|
1472
1980
|
*/
|
|
1473
1981
|
struct StringResult pactffi_generate_regex_value(const char *regex);
|
|
1474
1982
|
|
|
1475
1983
|
/**
|
|
1476
1984
|
* [DEPRECATED] Frees the memory allocated to a string by another function
|
|
1477
1985
|
*
|
|
1478
|
-
* This function is deprecated. Use pactffi_string_delete instead.
|
|
1986
|
+
* This function is deprecated. Use `pactffi_string_delete` instead.
|
|
1479
1987
|
*
|
|
1480
1988
|
* # Safety
|
|
1481
1989
|
*
|
|
1482
|
-
*
|
|
1990
|
+
* The string pointer can be NULL (which is a no-op), but if it is not a valid pointer the call
|
|
1991
|
+
* will result in undefined behaviour.
|
|
1483
1992
|
*/
|
|
1484
1993
|
void pactffi_free_string(char *s);
|
|
1485
1994
|
|
|
@@ -1549,7 +2058,7 @@ bool pactffi_given(InteractionHandle interaction, const char *description);
|
|
|
1549
2058
|
*
|
|
1550
2059
|
* * `1` - Function panicked. Error message will be available by calling `pactffi_get_error_message`.
|
|
1551
2060
|
* * `2` - Handle was not valid.
|
|
1552
|
-
* * `3` - Mock server was already started and the
|
|
2061
|
+
* * `3` - Mock server was already started and the integration can not be modified.
|
|
1553
2062
|
* * `4` - Not a V4 interaction.
|
|
1554
2063
|
*/
|
|
1555
2064
|
unsigned int pactffi_interaction_test_name(InteractionHandle interaction,
|
|
@@ -1574,8 +2083,18 @@ bool pactffi_given_with_param(InteractionHandle interaction,
|
|
|
1574
2083
|
*
|
|
1575
2084
|
* * `method` - The request method. Defaults to GET.
|
|
1576
2085
|
* * `path` - The request path. Defaults to `/`.
|
|
2086
|
+
*
|
|
2087
|
+
* To include matching rules for the path (only regex really makes sense to use), include the
|
|
2088
|
+
* matching rule JSON format with the value as a single JSON document. I.e.
|
|
2089
|
+
*
|
|
2090
|
+
* ```c
|
|
2091
|
+
* const char* value = "{\"value\":\"/path/to/100\", \"pact:matcher:type\":\"regex\", \"regex\":\"\\/path\\/to\\/\\\\d+\"}";
|
|
2092
|
+
* pactffi_with_request(handle, "GET", value);
|
|
2093
|
+
*
|
|
1577
2094
|
*/
|
|
1578
|
-
bool pactffi_with_request(InteractionHandle interaction,
|
|
2095
|
+
bool pactffi_with_request(InteractionHandle interaction,
|
|
2096
|
+
const char *method,
|
|
2097
|
+
const char *path);
|
|
1579
2098
|
|
|
1580
2099
|
/**
|
|
1581
2100
|
* Configures a query parameter for the Interaction. Returns false if the interaction or Pact can't be
|
|
@@ -1584,15 +2103,57 @@ bool pactffi_with_request(InteractionHandle interaction, const char *method, con
|
|
|
1584
2103
|
* * `name` - the query parameter name.
|
|
1585
2104
|
* * `value` - the query parameter value.
|
|
1586
2105
|
* * `index` - the index of the value (starts at 0). You can use this to create a query parameter with multiple values
|
|
2106
|
+
*
|
|
2107
|
+
* **DEPRECATED:** Use `pactffi_with_query_parameter_v2`, which deals with multiple values correctly
|
|
1587
2108
|
*/
|
|
1588
2109
|
bool pactffi_with_query_parameter(InteractionHandle interaction,
|
|
1589
2110
|
const char *name,
|
|
1590
2111
|
size_t index,
|
|
1591
2112
|
const char *value);
|
|
1592
2113
|
|
|
2114
|
+
/**
|
|
2115
|
+
* Configures a query parameter for the Interaction. Returns false if the interaction or Pact can't be
|
|
2116
|
+
* modified (i.e. the mock server for it has already started)
|
|
2117
|
+
*
|
|
2118
|
+
* * `name` - the query parameter name.
|
|
2119
|
+
* * `value` - the query parameter value. Either a simple string or a JSON document.
|
|
2120
|
+
* * `index` - the index of the value (starts at 0). You can use this to create a query parameter with multiple values
|
|
2121
|
+
*
|
|
2122
|
+
* To setup a query parameter with multiple values, you can either call this function multiple times
|
|
2123
|
+
* with a different index value, i.e. to create `id=2&id=3`
|
|
2124
|
+
*
|
|
2125
|
+
* ```c
|
|
2126
|
+
* pactffi_with_query_parameter_v2(handle, "id", 0, "2");
|
|
2127
|
+
* pactffi_with_query_parameter_v2(handle, "id", 1, "3");
|
|
2128
|
+
* ```
|
|
2129
|
+
*
|
|
2130
|
+
* Or you can call it once with a JSON value that contains multiple values:
|
|
2131
|
+
*
|
|
2132
|
+
* ```c
|
|
2133
|
+
* const char* value = "{\"value\": [\"2\",\"3\"]}";
|
|
2134
|
+
* pactffi_with_query_parameter_v2(handle, "id", 0, value);
|
|
2135
|
+
* ```
|
|
2136
|
+
*
|
|
2137
|
+
* To include matching rules for the query parameter, include the matching rule JSON format with
|
|
2138
|
+
* the value as a single JSON document. I.e.
|
|
2139
|
+
*
|
|
2140
|
+
* ```c
|
|
2141
|
+
* const char* value = "{\"value\":\"2\", \"pact:matcher:type\":\"regex\", \"regex\":\"\\\\d+\"}";
|
|
2142
|
+
* pactffi_with_query_parameter_v2(handle, "id", 0, value);
|
|
2143
|
+
* ```
|
|
2144
|
+
*
|
|
2145
|
+
* # Safety
|
|
2146
|
+
* The name and value parameters must be valid pointers to NULL terminated strings.
|
|
2147
|
+
* ```
|
|
2148
|
+
*/
|
|
2149
|
+
bool pactffi_with_query_parameter_v2(InteractionHandle interaction,
|
|
2150
|
+
const char *name,
|
|
2151
|
+
size_t index,
|
|
2152
|
+
const char *value);
|
|
2153
|
+
|
|
1593
2154
|
/**
|
|
1594
2155
|
* Sets the specification version for a given Pact model. Returns false if the interaction or Pact can't be
|
|
1595
|
-
* modified (i.e. the mock server for it has already started) or the version is invalid
|
|
2156
|
+
* modified (i.e. the mock server for it has already started) or the version is invalid.
|
|
1596
2157
|
*
|
|
1597
2158
|
* * `pact` - Handle to a Pact model
|
|
1598
2159
|
* * `version` - the spec version to use
|
|
@@ -1622,6 +2183,8 @@ bool pactffi_with_pact_metadata(PactHandle pact,
|
|
|
1622
2183
|
* * `name` - the header name.
|
|
1623
2184
|
* * `value` - the header value.
|
|
1624
2185
|
* * `index` - the index of the value (starts at 0). You can use this to create a header with multiple values
|
|
2186
|
+
*
|
|
2187
|
+
* **DEPRECATED:** Use `pactffi_with_header_v2`, which deals with multiple values correctly
|
|
1625
2188
|
*/
|
|
1626
2189
|
bool pactffi_with_header(InteractionHandle interaction,
|
|
1627
2190
|
enum InteractionPart part,
|
|
@@ -1629,6 +2192,47 @@ bool pactffi_with_header(InteractionHandle interaction,
|
|
|
1629
2192
|
size_t index,
|
|
1630
2193
|
const char *value);
|
|
1631
2194
|
|
|
2195
|
+
/**
|
|
2196
|
+
* Configures a header for the Interaction. Returns false if the interaction or Pact can't be
|
|
2197
|
+
* modified (i.e. the mock server for it has already started)
|
|
2198
|
+
*
|
|
2199
|
+
* * `part` - The part of the interaction to add the header to (Request or Response).
|
|
2200
|
+
* * `name` - the header name.
|
|
2201
|
+
* * `value` - the header value.
|
|
2202
|
+
* * `index` - the index of the value (starts at 0). You can use this to create a header with multiple values
|
|
2203
|
+
*
|
|
2204
|
+
* To setup a header with multiple values, you can either call this function multiple times
|
|
2205
|
+
* with a different index value, i.e. to create `x-id=2, 3`
|
|
2206
|
+
*
|
|
2207
|
+
* ```c
|
|
2208
|
+
* pactffi_with_header_v2(handle, InteractionPart::Request, "x-id", 0, "2");
|
|
2209
|
+
* pactffi_with_header_v2(handle, InteractionPart::Request, "x-id", 1, "3");
|
|
2210
|
+
* ```
|
|
2211
|
+
*
|
|
2212
|
+
* Or you can call it once with a JSON value that contains multiple values:
|
|
2213
|
+
*
|
|
2214
|
+
* ```c
|
|
2215
|
+
* const char* value = "{\"value\": [\"2\",\"3\"]}";
|
|
2216
|
+
* pactffi_with_header_v2(handle, InteractionPart::Request, "x-id", 0, value);
|
|
2217
|
+
* ```
|
|
2218
|
+
*
|
|
2219
|
+
* To include matching rules for the header, include the matching rule JSON format with
|
|
2220
|
+
* the value as a single JSON document. I.e.
|
|
2221
|
+
*
|
|
2222
|
+
* ```c
|
|
2223
|
+
* const char* value = "{\"value\":\"2\", \"pact:matcher:type\":\"regex\", \"regex\":\"\\\\d+\"}";
|
|
2224
|
+
* pactffi_with_header_v2(handle, InteractionPart::Request, "id", 0, value);
|
|
2225
|
+
* ```
|
|
2226
|
+
*
|
|
2227
|
+
* # Safety
|
|
2228
|
+
* The name and value parameters must be valid pointers to NULL terminated strings.
|
|
2229
|
+
*/
|
|
2230
|
+
bool pactffi_with_header_v2(InteractionHandle interaction,
|
|
2231
|
+
enum InteractionPart part,
|
|
2232
|
+
const char *name,
|
|
2233
|
+
size_t index,
|
|
2234
|
+
const char *value);
|
|
2235
|
+
|
|
1632
2236
|
/**
|
|
1633
2237
|
* Configures the response for the Interaction. Returns false if the interaction or Pact can't be
|
|
1634
2238
|
* modified (i.e. the mock server for it has already started)
|
|
@@ -1645,6 +2249,22 @@ bool pactffi_response_status(InteractionHandle interaction, unsigned short statu
|
|
|
1645
2249
|
* * `content_type` - The content type of the body. Defaults to `text/plain`. Will be ignored if a content type
|
|
1646
2250
|
* header is already set.
|
|
1647
2251
|
* * `body` - The body contents. For JSON payloads, matching rules can be embedded in the body.
|
|
2252
|
+
*
|
|
2253
|
+
* For HTTP and async message interactions, this will overwrite the body. With asynchronous messages, the
|
|
2254
|
+
* part parameter will be ignored. With synchronous messages, the request contents will be overwritten,
|
|
2255
|
+
* while a new response will be appended to the message.
|
|
2256
|
+
*
|
|
2257
|
+
* # Safety
|
|
2258
|
+
*
|
|
2259
|
+
* The interaction contents and content type must either be NULL pointers, or point to valid
|
|
2260
|
+
* UTF-8 encoded NULL-terminated strings. Otherwise, behaviour is undefined.
|
|
2261
|
+
*
|
|
2262
|
+
* # Error Handling
|
|
2263
|
+
*
|
|
2264
|
+
* If the contents is a NULL pointer, it will set the body contents as null. If the content
|
|
2265
|
+
* type is a null pointer, or can't be parsed, it will set the content type as TEXT.
|
|
2266
|
+
* Returns false if the interaction or Pact can't be modified (i.e. the mock server for it has
|
|
2267
|
+
* already started) or an error has occurred.
|
|
1648
2268
|
*/
|
|
1649
2269
|
bool pactffi_with_body(InteractionHandle interaction,
|
|
1650
2270
|
enum InteractionPart part,
|
|
@@ -1661,6 +2281,22 @@ bool pactffi_with_body(InteractionHandle interaction,
|
|
|
1661
2281
|
* * `content_type` - Expected content type.
|
|
1662
2282
|
* * `body` - example body contents in bytes
|
|
1663
2283
|
* * `size` - number of bytes in the body
|
|
2284
|
+
*
|
|
2285
|
+
* For HTTP and async message interactions, this will overwrite the body. With asynchronous messages, the
|
|
2286
|
+
* part parameter will be ignored. With synchronous messages, the request contents will be overwritten,
|
|
2287
|
+
* while a new response will be appended to the message.
|
|
2288
|
+
*
|
|
2289
|
+
* # Safety
|
|
2290
|
+
*
|
|
2291
|
+
* The content type must be a valid UTF-8 encoded NULL-terminated string. The body pointer must
|
|
2292
|
+
* be valid for reads of `size` bytes, and it must be properly aligned and consecutive.
|
|
2293
|
+
*
|
|
2294
|
+
* # Error Handling
|
|
2295
|
+
*
|
|
2296
|
+
* If the body is a NULL pointer, it will set the body contents as null. If the content
|
|
2297
|
+
* type is a null pointer, or can't be parsed, it will return false.
|
|
2298
|
+
* Returns false if the interaction or Pact can't be modified (i.e. the mock server for it has
|
|
2299
|
+
* already started) or an error has occurred.
|
|
1664
2300
|
*/
|
|
1665
2301
|
bool pactffi_with_binary_file(InteractionHandle interaction,
|
|
1666
2302
|
enum InteractionPart part,
|
|
@@ -1671,13 +2307,27 @@ bool pactffi_with_binary_file(InteractionHandle interaction,
|
|
|
1671
2307
|
/**
|
|
1672
2308
|
* Adds a binary file as the body as a MIME multipart with the expected content type and example contents. Will use
|
|
1673
2309
|
* a mime type matcher to match the body. Returns an error if the interaction or Pact can't be
|
|
1674
|
-
* modified (i.e. the mock server for it has already started)
|
|
2310
|
+
* modified (i.e. the mock server for it has already started) or an error occurs.
|
|
1675
2311
|
*
|
|
1676
2312
|
* * `interaction` - Interaction handle to set the body for.
|
|
1677
2313
|
* * `part` - Request or response part.
|
|
1678
2314
|
* * `content_type` - Expected content type of the file.
|
|
1679
2315
|
* * `file` - path to the example file
|
|
1680
2316
|
* * `part_name` - name for the mime part
|
|
2317
|
+
*
|
|
2318
|
+
* # Safety
|
|
2319
|
+
*
|
|
2320
|
+
* The content type, file path and part name must be valid pointers to UTF-8 encoded NULL-terminated strings.
|
|
2321
|
+
* Passing invalid pointers or pointers to strings that are not NULL terminated will lead to undefined
|
|
2322
|
+
* behaviour.
|
|
2323
|
+
*
|
|
2324
|
+
* # Error Handling
|
|
2325
|
+
*
|
|
2326
|
+
* If the file path is a NULL pointer, it will set the body contents as as an empty mime-part.
|
|
2327
|
+
* If the file path does not point to a valid file, or is not able to be read, it will return an
|
|
2328
|
+
* error result. If the content type is a null pointer, or can't be parsed, it will return an error result.
|
|
2329
|
+
* Returns an error if the interaction or Pact can't be modified (i.e. the mock server for it has
|
|
2330
|
+
* already started), the interaction is not an HTTP interaction or some other error occurs.
|
|
1681
2331
|
*/
|
|
1682
2332
|
struct StringResult pactffi_with_multipart_file(InteractionHandle interaction,
|
|
1683
2333
|
enum InteractionPart part,
|
|
@@ -1719,6 +2369,23 @@ struct PactMessageIterator *pactffi_pact_handle_get_message_iter(PactHandle pact
|
|
|
1719
2369
|
*/
|
|
1720
2370
|
struct PactSyncMessageIterator *pactffi_pact_handle_get_sync_message_iter(PactHandle pact);
|
|
1721
2371
|
|
|
2372
|
+
/**
|
|
2373
|
+
* Get an iterator over all the synchronous HTTP request/response interactions of the Pact.
|
|
2374
|
+
* The returned iterator needs to be freed with `pactffi_pact_sync_http_iter_delete`.
|
|
2375
|
+
*
|
|
2376
|
+
* # Safety
|
|
2377
|
+
*
|
|
2378
|
+
* The iterator contains a copy of the Pact, so it is always safe to use.
|
|
2379
|
+
*
|
|
2380
|
+
* # Error Handling
|
|
2381
|
+
*
|
|
2382
|
+
* On failure, this function will return a NULL pointer.
|
|
2383
|
+
*
|
|
2384
|
+
* This function may fail if any of the Rust strings contain embedded
|
|
2385
|
+
* null ('\0') bytes.
|
|
2386
|
+
*/
|
|
2387
|
+
struct PactSyncHttpIterator *pactffi_pact_handle_get_sync_http_iter(PactHandle pact);
|
|
2388
|
+
|
|
1722
2389
|
/**
|
|
1723
2390
|
* Creates a new Pact Message model and returns a handle to it.
|
|
1724
2391
|
*
|
|
@@ -1926,7 +2593,7 @@ int32_t pactffi_verify(const char *args);
|
|
|
1926
2593
|
* Get a Handle to a newly created verifier. You should call `pactffi_verifier_shutdown` when
|
|
1927
2594
|
* done with the verifier to free all allocated resources.
|
|
1928
2595
|
*
|
|
1929
|
-
* This function is deprecated. Use `pactffi_verifier_new_for_application` which allows the
|
|
2596
|
+
* Deprecated: This function is deprecated. Use `pactffi_verifier_new_for_application` which allows the
|
|
1930
2597
|
* calling application/framework name and version to be specified.
|
|
1931
2598
|
*
|
|
1932
2599
|
* # Safety
|
|
@@ -2025,6 +2692,20 @@ int pactffi_verifier_set_verification_options(struct VerifierHandle *handle,
|
|
|
2025
2692
|
unsigned char disable_ssl_verification,
|
|
2026
2693
|
unsigned long request_timeout);
|
|
2027
2694
|
|
|
2695
|
+
/**
|
|
2696
|
+
* Enables or disables coloured output using ANSI escape codes in the verifier output. By default,
|
|
2697
|
+
* coloured output is enabled.
|
|
2698
|
+
*
|
|
2699
|
+
* `coloured_output` is a boolean value. Set it to greater than zero to turn the option on.
|
|
2700
|
+
*
|
|
2701
|
+
* # Safety
|
|
2702
|
+
*
|
|
2703
|
+
* This function is safe as long as the handle pointer points to a valid handle.
|
|
2704
|
+
*
|
|
2705
|
+
*/
|
|
2706
|
+
int pactffi_verifier_set_coloured_output(struct VerifierHandle *handle,
|
|
2707
|
+
unsigned char coloured_output);
|
|
2708
|
+
|
|
2028
2709
|
/**
|
|
2029
2710
|
* Set the options used when publishing verification results to the Pact Broker
|
|
2030
2711
|
*
|
|
@@ -2278,12 +2959,13 @@ const char *pactffi_verifier_json(const struct VerifierHandle *handle);
|
|
|
2278
2959
|
* Returns zero on success, and a positive integer value on failure.
|
|
2279
2960
|
*
|
|
2280
2961
|
* Note that plugins run as separate processes, so will need to be cleaned up afterwards by
|
|
2281
|
-
* calling `pactffi_cleanup_plugins` otherwise you have plugin processes left running.
|
|
2962
|
+
* calling `pactffi_cleanup_plugins` otherwise you will have plugin processes left running.
|
|
2282
2963
|
*
|
|
2283
2964
|
* # Safety
|
|
2284
2965
|
*
|
|
2285
2966
|
* `plugin_name` must be a valid pointer to a NULL terminated string. `plugin_version` may be null,
|
|
2286
|
-
* and if not NULL must also be a valid pointer to a NULL terminated string.
|
|
2967
|
+
* and if not NULL must also be a valid pointer to a NULL terminated string. Invalid
|
|
2968
|
+
* pointers will result in undefined behaviour.
|
|
2287
2969
|
*
|
|
2288
2970
|
* # Errors
|
|
2289
2971
|
*
|
|
@@ -2317,7 +2999,8 @@ void pactffi_cleanup_plugins(PactHandle pact);
|
|
|
2317
2999
|
*
|
|
2318
3000
|
* # Safety
|
|
2319
3001
|
*
|
|
2320
|
-
* `content_type` and `contents` must be a valid pointers to NULL terminated strings.
|
|
3002
|
+
* `content_type` and `contents` must be a valid pointers to NULL terminated strings. Invalid
|
|
3003
|
+
* pointers will result in undefined behaviour.
|
|
2321
3004
|
*
|
|
2322
3005
|
* # Errors
|
|
2323
3006
|
*
|