@pact-foundation/pact-core 13.5.1 → 13.6.0
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 +24 -0
- package/binding.gyp +141 -0
- package/build/Makefile +334 -0
- package/build/binding.Makefile +6 -0
- package/build/copy_release_artifacts.target.mk +47 -0
- package/build/pact.target.mk +174 -0
- package/build/set_osx_install_name.target.mk +18 -0
- package/ffi/{v0.0.3-libpact_ffi-osx-aarch64-apple-darwin.dylib → libpact_ffi.dylib} +0 -0
- package/ffi/{v0.0.3-libpact_ffi-linux-x86_64.so → libpact_ffi.so} +0 -0
- package/ffi/libpact_ffi.so.gz +0 -0
- package/ffi/{v0.0.3-libpact_ffi-osx-x86_64.dylib → osxaarch64/libpact_ffi.dylib} +0 -0
- package/ffi/pact-cpp.h +2344 -0
- package/ffi/{v0.0.3-pact.h → pact.h} +667 -119
- package/ffi/{v0.0.3-pact_ffi-windows-x86_64.dll → pact_ffi.dll} +0 -0
- package/ffi/pact_ffi.dll.lib +0 -0
- package/native/addon.cc +68 -0
- package/native/consumer.cc +1570 -0
- package/native/consumer.h +124 -0
- package/native/ffi.cc +148 -0
- package/native/ffi.h +18 -0
- package/native/plugin.cc +6 -0
- package/native/plugin.h +7 -0
- package/native/provider.cc +815 -0
- package/native/provider.h +38 -0
- package/package.json +12 -9
- package/src/consumer/checkErrors.d.ts +7 -0
- package/src/consumer/checkErrors.js +41 -0
- package/src/consumer/checkErrors.js.map +1 -0
- package/src/consumer/index.d.ts +5 -0
- package/src/consumer/index.js +222 -0
- package/src/consumer/index.js.map +1 -0
- package/src/consumer/types.d.ts +132 -0
- package/src/{ffi/internals → consumer}/types.js +0 -0
- package/src/{ffi/internals → consumer}/types.js.map +0 -0
- package/src/ffi/index.d.ts +4 -3
- package/src/ffi/index.js +6 -9
- package/src/ffi/index.js.map +1 -1
- package/src/ffi/internals/index.d.ts +0 -2
- package/src/ffi/internals/index.js +1 -11
- package/src/ffi/internals/index.js.map +1 -1
- package/src/ffi/types.d.ts +100 -0
- package/src/ffi/types.js +70 -0
- package/src/ffi/types.js.map +1 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
- package/src/index.js.map +1 -1
- package/src/logger/index.d.ts +5 -2
- package/src/logger/index.js +15 -2
- package/src/logger/index.js.map +1 -1
- package/src/verifier/argumentMapper/arguments.js +8 -0
- package/src/verifier/argumentMapper/arguments.js.map +1 -1
- package/src/verifier/index.js +1 -7
- package/src/verifier/index.js.map +1 -1
- package/src/verifier/nativeVerifier.js +74 -15
- package/src/verifier/nativeVerifier.js.map +1 -1
- package/src/verifier/types.d.ts +10 -2
- package/test.js +52 -0
- package/src/ffi/declarations.d.ts +0 -136
- package/src/ffi/declarations.js +0 -92
- package/src/ffi/declarations.js.map +0 -1
- package/src/ffi/internals/types.d.ts +0 -23
package/ffi/pact-cpp.h
ADDED
|
@@ -0,0 +1,2344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
* @brief "An FFI interface to the pact libraries, enabling cross-language use of Pact's core functionality."
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
#ifndef pact_ffi_h
|
|
8
|
+
#define pact_ffi_h
|
|
9
|
+
|
|
10
|
+
/* Generated with cbindgen:0.20.0 */
|
|
11
|
+
|
|
12
|
+
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
|
|
13
|
+
|
|
14
|
+
#include <cstdarg>
|
|
15
|
+
#include <cstdint>
|
|
16
|
+
#include <cstdlib>
|
|
17
|
+
#include <ostream>
|
|
18
|
+
#include <new>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Request or Response enum
|
|
22
|
+
*/
|
|
23
|
+
enum class InteractionPart {
|
|
24
|
+
/**
|
|
25
|
+
* Request part
|
|
26
|
+
*/
|
|
27
|
+
InteractionPart_Request,
|
|
28
|
+
/**
|
|
29
|
+
* Response part
|
|
30
|
+
*/
|
|
31
|
+
InteractionPart_Response,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* An enum representing the log level to use.
|
|
36
|
+
*
|
|
37
|
+
* This enum is passed to `log_attach_sink`, which defines where to direct
|
|
38
|
+
* log output at the specified level or lower.
|
|
39
|
+
*/
|
|
40
|
+
enum class LevelFilter {
|
|
41
|
+
LevelFilter_Off,
|
|
42
|
+
LevelFilter_Error,
|
|
43
|
+
LevelFilter_Warn,
|
|
44
|
+
LevelFilter_Info,
|
|
45
|
+
LevelFilter_Debug,
|
|
46
|
+
LevelFilter_Trace,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Enum defining the pact specification versions supported by the library
|
|
51
|
+
*/
|
|
52
|
+
enum class PactSpecification {
|
|
53
|
+
/**
|
|
54
|
+
* Unknown or unsupported specification version
|
|
55
|
+
*/
|
|
56
|
+
PactSpecification_Unknown,
|
|
57
|
+
/**
|
|
58
|
+
* First version of the pact specification (<https://github.com/pact-foundation/pact-specification/tree/version-1>)
|
|
59
|
+
*/
|
|
60
|
+
PactSpecification_V1,
|
|
61
|
+
/**
|
|
62
|
+
* Second version of the pact specification (<https://github.com/pact-foundation/pact-specification/tree/version-1.1>)
|
|
63
|
+
*/
|
|
64
|
+
PactSpecification_V1_1,
|
|
65
|
+
/**
|
|
66
|
+
* Version two of the pact specification (<https://github.com/pact-foundation/pact-specification/tree/version-2>)
|
|
67
|
+
*/
|
|
68
|
+
PactSpecification_V2,
|
|
69
|
+
/**
|
|
70
|
+
* Version three of the pact specification (<https://github.com/pact-foundation/pact-specification/tree/version-3>)
|
|
71
|
+
*/
|
|
72
|
+
PactSpecification_V3,
|
|
73
|
+
/**
|
|
74
|
+
* Version four of the pact specification (<https://github.com/pact-foundation/pact-specification/tree/version-4>)
|
|
75
|
+
*/
|
|
76
|
+
PactSpecification_V4,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Struct that defines the consumer of the pact.
|
|
81
|
+
*/
|
|
82
|
+
struct Consumer;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Struct that defines a message.
|
|
86
|
+
*/
|
|
87
|
+
struct Message;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* An iterator that enables FFI iteration over metadata by putting all the keys on the heap
|
|
91
|
+
* and tracking which one we're currently at.
|
|
92
|
+
*
|
|
93
|
+
* This assumes no mutation of the underlying metadata happens while the iterator is live.
|
|
94
|
+
*/
|
|
95
|
+
struct MessageMetadataIterator;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Struct that represents a pact between the consumer and provider of a service.
|
|
99
|
+
* It contains a list of Messages instead of Interactions, but is otherwise
|
|
100
|
+
* identical to `struct Pact`.
|
|
101
|
+
*/
|
|
102
|
+
struct MessagePact;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* An iterator over messages in a message pact.
|
|
106
|
+
*/
|
|
107
|
+
struct MessagePactMessageIterator;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* An iterator that enables FFI iteration over metadata by putting all the keys on the heap
|
|
111
|
+
* and tracking which one we're currently at.
|
|
112
|
+
*
|
|
113
|
+
* This assumes no mutation of the underlying metadata happens while the iterator is live.
|
|
114
|
+
*/
|
|
115
|
+
struct MessagePactMetadataIterator;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Enum that defines the different types of mismatches that can occur.
|
|
119
|
+
*/
|
|
120
|
+
struct Mismatch;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A collection of mismatches from a matching comparison.
|
|
124
|
+
*/
|
|
125
|
+
struct Mismatches;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* An iterator over mismatches.
|
|
129
|
+
*/
|
|
130
|
+
struct MismatchesIterator;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* An iterator over messages in a pact.
|
|
134
|
+
*/
|
|
135
|
+
struct PactMessageIterator;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* An iterator over synchronous request/response messages in a pact.
|
|
139
|
+
*/
|
|
140
|
+
struct PactSyncMessageIterator;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Struct that defines a provider of a pact.
|
|
144
|
+
*/
|
|
145
|
+
struct Provider;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Struct that encapsulates all the info about a provider state
|
|
149
|
+
*/
|
|
150
|
+
struct ProviderState;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Iterator over individual provider states.
|
|
154
|
+
*/
|
|
155
|
+
struct ProviderStateIterator;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* An iterator that enables FFI iteration over provider state params by putting all the keys on the heap
|
|
159
|
+
* and tracking which one we're currently at.
|
|
160
|
+
*
|
|
161
|
+
* This assumes no mutation of the underlying provider state happens while the iterator is live.
|
|
162
|
+
*/
|
|
163
|
+
struct ProviderStateParamIterator;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Synchronous interactions as a request message to a sequence of response messages
|
|
167
|
+
*/
|
|
168
|
+
struct SynchronousMessage;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Wraps a Pact verifier
|
|
172
|
+
*/
|
|
173
|
+
struct VerifierHandle;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* A single key-value pair exported to the C-side.
|
|
177
|
+
*/
|
|
178
|
+
struct MessageMetadataPair {
|
|
179
|
+
/**
|
|
180
|
+
* The metadata key.
|
|
181
|
+
*/
|
|
182
|
+
const char *key;
|
|
183
|
+
/**
|
|
184
|
+
* The metadata value.
|
|
185
|
+
*/
|
|
186
|
+
const char *value;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* A triple, containing the outer key, inner key, and value, exported to the C-side.
|
|
191
|
+
*/
|
|
192
|
+
struct MessagePactMetadataTriple {
|
|
193
|
+
/**
|
|
194
|
+
* The outer key of the `MessagePact` metadata.
|
|
195
|
+
*/
|
|
196
|
+
const char *outer_key;
|
|
197
|
+
/**
|
|
198
|
+
* The inner key of the `MessagePact` metadata.
|
|
199
|
+
*/
|
|
200
|
+
const char *inner_key;
|
|
201
|
+
/**
|
|
202
|
+
* The value of the `MessagePact` metadata.
|
|
203
|
+
*/
|
|
204
|
+
const char *value;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* A single key-value pair exported to the C-side.
|
|
209
|
+
*/
|
|
210
|
+
struct ProviderStateParamPair {
|
|
211
|
+
/**
|
|
212
|
+
* The key of the `ProviderState` parameter.
|
|
213
|
+
*/
|
|
214
|
+
const char *key;
|
|
215
|
+
/**
|
|
216
|
+
* The value of the `ProviderState` parameter.
|
|
217
|
+
*/
|
|
218
|
+
const char *value;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Wraps a Pact model struct
|
|
223
|
+
*/
|
|
224
|
+
using PactHandle = uint16_t;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Result of wrapping a string value
|
|
228
|
+
*/
|
|
229
|
+
struct StringResult {
|
|
230
|
+
enum class Tag {
|
|
231
|
+
/**
|
|
232
|
+
* Was generated OK
|
|
233
|
+
*/
|
|
234
|
+
StringResult_Ok,
|
|
235
|
+
/**
|
|
236
|
+
* There was an error generating the string
|
|
237
|
+
*/
|
|
238
|
+
StringResult_Failed,
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
struct StringResult_Ok_Body {
|
|
242
|
+
char *_0;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
struct StringResult_Failed_Body {
|
|
246
|
+
char *_0;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
Tag tag;
|
|
250
|
+
union {
|
|
251
|
+
StringResult_Ok_Body ok;
|
|
252
|
+
StringResult_Failed_Body failed;
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Wraps a Pact model struct
|
|
258
|
+
*/
|
|
259
|
+
using InteractionHandle = uint32_t;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Wraps a Pact model struct
|
|
263
|
+
*/
|
|
264
|
+
using MessagePactHandle = uint16_t;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Wraps a Pact model struct
|
|
268
|
+
*/
|
|
269
|
+
using MessageHandle = uint32_t;
|
|
270
|
+
|
|
271
|
+
extern "C" {
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Get the current library version
|
|
275
|
+
*/
|
|
276
|
+
const char *pactffi_version();
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Initialise the mock server library, can provide an environment variable name to use to
|
|
280
|
+
* set the log levels.
|
|
281
|
+
*
|
|
282
|
+
* # Safety
|
|
283
|
+
*
|
|
284
|
+
* log_env_var must be a valid NULL terminated UTF-8 string.
|
|
285
|
+
*/
|
|
286
|
+
void pactffi_init(const char *log_env_var);
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Initialises logging, and sets the log level explicitly.
|
|
290
|
+
*
|
|
291
|
+
* # Safety
|
|
292
|
+
*
|
|
293
|
+
* Exported functions are inherently unsafe.
|
|
294
|
+
*/
|
|
295
|
+
void pactffi_init_with_log_level(const char *level);
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Enable ANSI coloured output on Windows. On non-Windows platforms, this function is a no-op.
|
|
299
|
+
*
|
|
300
|
+
* # Safety
|
|
301
|
+
*
|
|
302
|
+
* This function is safe.
|
|
303
|
+
*/
|
|
304
|
+
void pactffi_enable_ansi_support();
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Log using the shared core logging facility.
|
|
308
|
+
*
|
|
309
|
+
* This is useful for callers to have a single set of logs.
|
|
310
|
+
*
|
|
311
|
+
* * `source` - String. The source of the log, such as the class or caller framework to
|
|
312
|
+
* disambiguate log lines from the rust logging (e.g. pact_go)
|
|
313
|
+
* * `log_level` - String. One of TRACE, DEBUG, INFO, WARN, ERROR
|
|
314
|
+
* * `message` - Message to log
|
|
315
|
+
*
|
|
316
|
+
* # Safety
|
|
317
|
+
* This function will fail if any of the pointers passed to it are invalid.
|
|
318
|
+
*/
|
|
319
|
+
void pactffi_log_message(const char *source, const char *log_level, const char *message);
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Match a pair of messages, producing a collection of mismatches,
|
|
323
|
+
* which is empty if the two messages matched.
|
|
324
|
+
*/
|
|
325
|
+
const Mismatches *pactffi_match_message(const Message *msg_1, const Message *msg_2);
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Get an iterator over mismatches.
|
|
329
|
+
*/
|
|
330
|
+
MismatchesIterator *pactffi_mismatches_get_iter(const Mismatches *mismatches);
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Delete mismatches
|
|
334
|
+
*/
|
|
335
|
+
void pactffi_mismatches_delete(const Mismatches *mismatches);
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Get the next mismatch from a mismatches iterator.
|
|
339
|
+
*
|
|
340
|
+
* Returns a null pointer if no mismatches remain.
|
|
341
|
+
*/
|
|
342
|
+
const Mismatch *pactffi_mismatches_iter_next(MismatchesIterator *iter);
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Delete a mismatches iterator when you're done with it.
|
|
346
|
+
*/
|
|
347
|
+
void pactffi_mismatches_iter_delete(MismatchesIterator *iter);
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Get a JSON representation of the mismatch.
|
|
351
|
+
*/
|
|
352
|
+
const char *pactffi_mismatch_to_json(const Mismatch *mismatch);
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Get the type of a mismatch.
|
|
356
|
+
*/
|
|
357
|
+
const char *pactffi_mismatch_type(const Mismatch *mismatch);
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Get a summary of a mismatch.
|
|
361
|
+
*/
|
|
362
|
+
const char *pactffi_mismatch_summary(const Mismatch *mismatch);
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Get a description of a mismatch.
|
|
366
|
+
*/
|
|
367
|
+
const char *pactffi_mismatch_description(const Mismatch *mismatch);
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Get an ANSI-compatible description of a mismatch.
|
|
371
|
+
*/
|
|
372
|
+
const char *pactffi_mismatch_ansi_description(const Mismatch *mismatch);
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Provide the error message from `LAST_ERROR` to the calling C code.
|
|
376
|
+
*
|
|
377
|
+
* This function should be called after any other function in the pact_matching FFI
|
|
378
|
+
* indicates a failure with its own error message, if the caller wants to get more context
|
|
379
|
+
* on why the error happened.
|
|
380
|
+
*
|
|
381
|
+
* Do note that this error-reporting mechanism only reports the top-level error message,
|
|
382
|
+
* not any source information embedded in the original Rust error type. If you want more
|
|
383
|
+
* detailed information for debugging purposes, use the logging interface.
|
|
384
|
+
*
|
|
385
|
+
* # Params
|
|
386
|
+
*
|
|
387
|
+
* * `buffer`: a pointer to an array of `char` of sufficient length to hold the error message.
|
|
388
|
+
* * `length`: an int providing the length of the `buffer`.
|
|
389
|
+
*
|
|
390
|
+
* # Return Codes
|
|
391
|
+
*
|
|
392
|
+
* * The number of bytes written to the provided buffer, which may be zero if there is no last error.
|
|
393
|
+
* * `-1` if the provided buffer is a null pointer.
|
|
394
|
+
* * `-2` if the provided buffer length is too small for the error message.
|
|
395
|
+
* * `-3` if the write failed for some other reason.
|
|
396
|
+
* * `-4` if the error message had an interior NULL
|
|
397
|
+
*
|
|
398
|
+
* # Notes
|
|
399
|
+
*
|
|
400
|
+
* Note that this function zeroes out any excess in the provided buffer.
|
|
401
|
+
*
|
|
402
|
+
* # Error Handling
|
|
403
|
+
*
|
|
404
|
+
* The return code must be checked for one of the negative number error codes before the buffer
|
|
405
|
+
* is used. If an error code is present, the buffer may not be in a usable state.
|
|
406
|
+
*
|
|
407
|
+
* If the buffer is longer than needed for the error message, the excess space will be zeroed
|
|
408
|
+
* as a safety mechanism. This is slightly less efficient than leaving the contents of the buffer
|
|
409
|
+
* alone, but the difference is expected to be negligible in practice.
|
|
410
|
+
*/
|
|
411
|
+
int pactffi_get_error_message(char *buffer,
|
|
412
|
+
int length);
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Convenience function to direct all logging to stdout.
|
|
416
|
+
*/
|
|
417
|
+
int pactffi_log_to_stdout(LevelFilter level_filter);
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Convenience function to direct all logging to stderr.
|
|
421
|
+
*/
|
|
422
|
+
int pactffi_log_to_stderr(LevelFilter level_filter);
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Convenience function to direct all logging to a file.
|
|
426
|
+
*
|
|
427
|
+
* # Safety
|
|
428
|
+
* This function will fail if the file_name pointer is invalid or does not point to a NULL
|
|
429
|
+
* terminated string.
|
|
430
|
+
*/
|
|
431
|
+
int pactffi_log_to_file(const char *file_name, LevelFilter level_filter);
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Convenience function to direct all logging to a task local memory buffer.
|
|
435
|
+
*/
|
|
436
|
+
int pactffi_log_to_buffer(LevelFilter level_filter);
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Initialize the thread-local logger with no sinks.
|
|
440
|
+
*
|
|
441
|
+
* This initialized logger does nothing until `pactffi_logger_apply` has been called.
|
|
442
|
+
*
|
|
443
|
+
* # Usage
|
|
444
|
+
*
|
|
445
|
+
* ```c
|
|
446
|
+
* pactffi_logger_init();
|
|
447
|
+
* ```
|
|
448
|
+
*
|
|
449
|
+
* # Safety
|
|
450
|
+
*
|
|
451
|
+
* This function is always safe to call.
|
|
452
|
+
*/
|
|
453
|
+
void pactffi_logger_init();
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Attach an additional sink to the thread-local logger.
|
|
457
|
+
*
|
|
458
|
+
* This logger does nothing until `pactffi_logger_apply` has been called.
|
|
459
|
+
*
|
|
460
|
+
* Three types of sinks can be specified:
|
|
461
|
+
*
|
|
462
|
+
* - stdout (`pactffi_logger_attach_sink("stdout", LevelFilter_Info)`)
|
|
463
|
+
* - stderr (`pactffi_logger_attach_sink("stderr", LevelFilter_Debug)`)
|
|
464
|
+
* - file w/ file path (`pactffi_logger_attach_sink("file /some/file/path", LevelFilter_Trace)`)
|
|
465
|
+
* - buffer (`pactffi_logger_attach_sink("buffer", LevelFilter_Debug)`)
|
|
466
|
+
*
|
|
467
|
+
* # Usage
|
|
468
|
+
*
|
|
469
|
+
* ```c
|
|
470
|
+
* int result = pactffi_logger_attach_sink("file /some/file/path", LogLevel_Filter);
|
|
471
|
+
* ```
|
|
472
|
+
*
|
|
473
|
+
* # Error Handling
|
|
474
|
+
*
|
|
475
|
+
* The return error codes are as follows:
|
|
476
|
+
*
|
|
477
|
+
* - `-1`: Can't set logger (applying the logger failed, perhaps because one is applied already).
|
|
478
|
+
* - `-2`: No logger has been initialized (call `pactffi_logger_init` before any other log function).
|
|
479
|
+
* - `-3`: The sink specifier was not UTF-8 encoded.
|
|
480
|
+
* - `-4`: The sink type specified is not a known type (known types: "stdout", "stderr", or "file /some/path").
|
|
481
|
+
* - `-5`: No file path was specified in a file-type sink specification.
|
|
482
|
+
* - `-6`: Opening a sink to the specified file path failed (check permissions).
|
|
483
|
+
*
|
|
484
|
+
* # Safety
|
|
485
|
+
*
|
|
486
|
+
* This function checks the validity of the passed-in sink specifier, and errors
|
|
487
|
+
* out if the specifier isn't valid UTF-8.
|
|
488
|
+
*/
|
|
489
|
+
int pactffi_logger_attach_sink(const char *sink_specifier,
|
|
490
|
+
LevelFilter level_filter);
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Apply the thread-local logger to the program.
|
|
494
|
+
*
|
|
495
|
+
* Any attempts to modify the logger after the call to `logger_apply` will fail.
|
|
496
|
+
*/
|
|
497
|
+
int pactffi_logger_apply();
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Fetch the in-memory logger buffer contents. This will only have any contents if the `buffer`
|
|
501
|
+
* sink has been configured to log to. The contents will be allocated on the heap and will need
|
|
502
|
+
* to be freed with `string_delete`.
|
|
503
|
+
*
|
|
504
|
+
* Fetches the logs associated with the provided identifier, or uses the "global" one if the
|
|
505
|
+
* identifier is not specified (i.e. NULL).
|
|
506
|
+
*
|
|
507
|
+
* Returns a NULL pointer if the buffer can't be fetched. This can occur is there is not
|
|
508
|
+
* sufficient memory to make a copy of the contents or the buffer contains non-UTF-8 characters.
|
|
509
|
+
*
|
|
510
|
+
* # Safety
|
|
511
|
+
*
|
|
512
|
+
* This function will fail if the log_id pointer is invalid or does not point to a NULL
|
|
513
|
+
* terminated string.
|
|
514
|
+
*/
|
|
515
|
+
const char *pactffi_fetch_log_buffer(const char *log_id);
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Get a copy of this consumer's name.
|
|
519
|
+
*
|
|
520
|
+
* The copy must be deleted with `pactffi_string_delete`.
|
|
521
|
+
*
|
|
522
|
+
* # Usage
|
|
523
|
+
*
|
|
524
|
+
* ```c
|
|
525
|
+
* // Assuming `file_name` and `json_str` are already defined.
|
|
526
|
+
*
|
|
527
|
+
* MessagePact *message_pact = pactffi_message_pact_new_from_json(file_name, json_str);
|
|
528
|
+
* if (message_pact == NULLPTR) {
|
|
529
|
+
* // handle error.
|
|
530
|
+
* }
|
|
531
|
+
*
|
|
532
|
+
* Consumer *consumer = pactffi_message_pact_get_consumer(message_pact);
|
|
533
|
+
* if (consumer == NULLPTR) {
|
|
534
|
+
* // handle error.
|
|
535
|
+
* }
|
|
536
|
+
*
|
|
537
|
+
* char *name = pactffi_consumer_get_name(consumer);
|
|
538
|
+
* if (name == NULL) {
|
|
539
|
+
* // handle error.
|
|
540
|
+
* }
|
|
541
|
+
*
|
|
542
|
+
* printf("%s\n", name);
|
|
543
|
+
*
|
|
544
|
+
* pactffi_string_delete(name);
|
|
545
|
+
* ```
|
|
546
|
+
*
|
|
547
|
+
* # Errors
|
|
548
|
+
*
|
|
549
|
+
* This function will fail if it is passed a NULL pointer,
|
|
550
|
+
* or the Rust string contains an embedded NULL byte.
|
|
551
|
+
* In the case of error, a NULL pointer will be returned.
|
|
552
|
+
*/
|
|
553
|
+
const char *pactffi_consumer_get_name(const Consumer *consumer);
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Get a mutable pointer to a newly-created default message on the heap.
|
|
557
|
+
*
|
|
558
|
+
* # Safety
|
|
559
|
+
*
|
|
560
|
+
* This function is safe.
|
|
561
|
+
*
|
|
562
|
+
* # Error Handling
|
|
563
|
+
*
|
|
564
|
+
* Returns NULL on error.
|
|
565
|
+
*/
|
|
566
|
+
Message *pactffi_message_new();
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Constructs a `Message` from the JSON string
|
|
570
|
+
*
|
|
571
|
+
* # Safety
|
|
572
|
+
*
|
|
573
|
+
* This function is safe.
|
|
574
|
+
*
|
|
575
|
+
* # Error Handling
|
|
576
|
+
*
|
|
577
|
+
* If the JSON string is invalid or not UTF-8 encoded, returns a NULL.
|
|
578
|
+
*/
|
|
579
|
+
Message *pactffi_message_new_from_json(unsigned int index,
|
|
580
|
+
const char *json_str,
|
|
581
|
+
PactSpecification spec_version);
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Constructs a `Message` from a body with a given content-type.
|
|
585
|
+
*
|
|
586
|
+
* # Safety
|
|
587
|
+
*
|
|
588
|
+
* This function is safe.
|
|
589
|
+
*
|
|
590
|
+
* # Error Handling
|
|
591
|
+
*
|
|
592
|
+
* If the body or content type are invalid or not UTF-8 encoded, returns NULL.
|
|
593
|
+
*/
|
|
594
|
+
Message *pactffi_message_new_from_body(const char *body, const char *content_type);
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Destroy the `Message` being pointed to.
|
|
598
|
+
*/
|
|
599
|
+
void pactffi_message_delete(Message *message);
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Get the contents of a `Message` in string form.
|
|
603
|
+
*
|
|
604
|
+
* # Safety
|
|
605
|
+
*
|
|
606
|
+
* The returned string must be deleted with `pactffi_string_delete`.
|
|
607
|
+
*
|
|
608
|
+
* The returned string can outlive the message.
|
|
609
|
+
*
|
|
610
|
+
* # Error Handling
|
|
611
|
+
*
|
|
612
|
+
* If the message is NULL, returns NULL. If the body of the message
|
|
613
|
+
* is missing, then this function also returns NULL. This means there's
|
|
614
|
+
* no mechanism to differentiate with this function call alone between
|
|
615
|
+
* a NULL message and a missing message body.
|
|
616
|
+
*/
|
|
617
|
+
const char *pactffi_message_get_contents(const Message *message);
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Get the length of the contents of a `Message`.
|
|
621
|
+
*
|
|
622
|
+
* # Safety
|
|
623
|
+
*
|
|
624
|
+
* This function is safe.
|
|
625
|
+
*
|
|
626
|
+
* # Error Handling
|
|
627
|
+
*
|
|
628
|
+
* If the message is NULL, returns 0. If the body of the message
|
|
629
|
+
* is missing, then this function also returns 0.
|
|
630
|
+
*/
|
|
631
|
+
size_t pactffi_message_get_contents_length(const Message *message);
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Get the contents of a `Message` as a pointer to an array of bytes.
|
|
635
|
+
*
|
|
636
|
+
* # Safety
|
|
637
|
+
*
|
|
638
|
+
* The number of bytes in the buffer will be returned by `pactffi_message_get_contents_length`.
|
|
639
|
+
* It is safe to use the pointer while the message is not deleted or changed. Using the pointer
|
|
640
|
+
* after the message is mutated or deleted may lead to undefined behaviour.
|
|
641
|
+
*
|
|
642
|
+
* # Error Handling
|
|
643
|
+
*
|
|
644
|
+
* If the message is NULL, returns NULL. If the body of the message
|
|
645
|
+
* is missing, then this function also returns NULL.
|
|
646
|
+
*/
|
|
647
|
+
const unsigned char *pactffi_message_get_contents_bin(const Message *message);
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Get a copy of the description.
|
|
651
|
+
*
|
|
652
|
+
* # Safety
|
|
653
|
+
*
|
|
654
|
+
* The returned string must be deleted with `pactffi_string_delete`.
|
|
655
|
+
*
|
|
656
|
+
* Since it is a copy, the returned string may safely outlive
|
|
657
|
+
* the `Message`.
|
|
658
|
+
*
|
|
659
|
+
* # Errors
|
|
660
|
+
*
|
|
661
|
+
* On failure, this function will return a NULL pointer.
|
|
662
|
+
*
|
|
663
|
+
* This function may fail if the Rust string contains embedded
|
|
664
|
+
* null ('\0') bytes.
|
|
665
|
+
*/
|
|
666
|
+
const char *pactffi_message_get_description(const Message *message);
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Write the `description` field on the `Message`.
|
|
670
|
+
*
|
|
671
|
+
* # Safety
|
|
672
|
+
*
|
|
673
|
+
* `description` must contain valid UTF-8. Invalid UTF-8
|
|
674
|
+
* will be replaced with U+FFFD REPLACEMENT CHARACTER.
|
|
675
|
+
*
|
|
676
|
+
* This function will only reallocate if the new string
|
|
677
|
+
* does not fit in the existing buffer.
|
|
678
|
+
*
|
|
679
|
+
* # Error Handling
|
|
680
|
+
*
|
|
681
|
+
* Errors will be reported with a non-zero return value.
|
|
682
|
+
*/
|
|
683
|
+
int pactffi_message_set_description(Message *message, const char *description);
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Get a copy of the provider state at the given index from this message.
|
|
687
|
+
*
|
|
688
|
+
* # Safety
|
|
689
|
+
*
|
|
690
|
+
* The returned structure must be deleted with `provider_state_delete`.
|
|
691
|
+
*
|
|
692
|
+
* Since it is a copy, the returned structure may safely outlive
|
|
693
|
+
* the `Message`.
|
|
694
|
+
*
|
|
695
|
+
* # Error Handling
|
|
696
|
+
*
|
|
697
|
+
* On failure, this function will return a variant other than Success.
|
|
698
|
+
*
|
|
699
|
+
* This function may fail if the index requested is out of bounds,
|
|
700
|
+
* or if any of the Rust strings contain embedded null ('\0') bytes.
|
|
701
|
+
*/
|
|
702
|
+
const ProviderState *pactffi_message_get_provider_state(const Message *message, unsigned int index);
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* Get an iterator over provider states.
|
|
706
|
+
*
|
|
707
|
+
* # Safety
|
|
708
|
+
*
|
|
709
|
+
* The underlying data must not change during iteration.
|
|
710
|
+
*
|
|
711
|
+
* # Error Handling
|
|
712
|
+
*
|
|
713
|
+
* Returns NULL if an error occurs.
|
|
714
|
+
*/
|
|
715
|
+
ProviderStateIterator *pactffi_message_get_provider_state_iter(Message *message);
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Get the next value from the iterator.
|
|
719
|
+
*
|
|
720
|
+
* # Safety
|
|
721
|
+
*
|
|
722
|
+
* The underlying data must not change during iteration.
|
|
723
|
+
*
|
|
724
|
+
* If a previous call panicked, then the internal mutex will have been poisoned and this
|
|
725
|
+
* function will return NULL.
|
|
726
|
+
*
|
|
727
|
+
* # Error Handling
|
|
728
|
+
*
|
|
729
|
+
* Returns NULL if an error occurs.
|
|
730
|
+
*/
|
|
731
|
+
ProviderState *pactffi_provider_state_iter_next(ProviderStateIterator *iter);
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Delete the iterator.
|
|
735
|
+
*/
|
|
736
|
+
void pactffi_provider_state_iter_delete(ProviderStateIterator *iter);
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Get a copy of the metadata value indexed by `key`.
|
|
740
|
+
*
|
|
741
|
+
* # Safety
|
|
742
|
+
*
|
|
743
|
+
* The returned string must be deleted with `pactffi_string_delete`.
|
|
744
|
+
*
|
|
745
|
+
* Since it is a copy, the returned string may safely outlive
|
|
746
|
+
* the `Message`.
|
|
747
|
+
*
|
|
748
|
+
* The returned pointer will be NULL if the metadata does not contain
|
|
749
|
+
* the given key, or if an error occurred.
|
|
750
|
+
*
|
|
751
|
+
* # Error Handling
|
|
752
|
+
*
|
|
753
|
+
* On failure, this function will return a NULL pointer.
|
|
754
|
+
*
|
|
755
|
+
* This function may fail if the provided `key` string contains
|
|
756
|
+
* invalid UTF-8, or if the Rust string contains embedded null ('\0')
|
|
757
|
+
* bytes.
|
|
758
|
+
*/
|
|
759
|
+
const char *pactffi_message_find_metadata(const Message *message, const char *key);
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Insert the (`key`, `value`) pair into this Message's
|
|
763
|
+
* `metadata` HashMap.
|
|
764
|
+
*
|
|
765
|
+
* # Safety
|
|
766
|
+
*
|
|
767
|
+
* This function returns an enum indicating the result;
|
|
768
|
+
* see the comments on HashMapInsertStatus for details.
|
|
769
|
+
*
|
|
770
|
+
* # Error Handling
|
|
771
|
+
*
|
|
772
|
+
* This function may fail if the provided `key` or `value` strings
|
|
773
|
+
* contain invalid UTF-8.
|
|
774
|
+
*/
|
|
775
|
+
int pactffi_message_insert_metadata(Message *message, const char *key, const char *value);
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Get an iterator over the metadata of a message.
|
|
779
|
+
*
|
|
780
|
+
* # Safety
|
|
781
|
+
*
|
|
782
|
+
* This iterator carries a pointer to the message, and must
|
|
783
|
+
* not outlive the message.
|
|
784
|
+
*
|
|
785
|
+
* The message metadata also must not be modified during iteration. If it is,
|
|
786
|
+
* the old iterator must be deleted and a new iterator created.
|
|
787
|
+
*
|
|
788
|
+
* # Error Handling
|
|
789
|
+
*
|
|
790
|
+
* On failure, this function will return a NULL pointer.
|
|
791
|
+
*
|
|
792
|
+
* This function may fail if any of the Rust strings contain
|
|
793
|
+
* embedded null ('\0') bytes.
|
|
794
|
+
*/
|
|
795
|
+
MessageMetadataIterator *pactffi_message_get_metadata_iter(Message *message);
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Get the next key and value out of the iterator, if possible
|
|
799
|
+
*
|
|
800
|
+
* # Safety
|
|
801
|
+
*
|
|
802
|
+
* The underlying data must not change during iteration.
|
|
803
|
+
*
|
|
804
|
+
* # Error Handling
|
|
805
|
+
*
|
|
806
|
+
* If no further data is present, returns NULL.
|
|
807
|
+
*/
|
|
808
|
+
MessageMetadataPair *pactffi_message_metadata_iter_next(MessageMetadataIterator *iter);
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Free the metadata iterator when you're done using it.
|
|
812
|
+
*/
|
|
813
|
+
void pactffi_message_metadata_iter_delete(MessageMetadataIterator *iter);
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* Free a pair of key and value returned from `message_metadata_iter_next`.
|
|
817
|
+
*/
|
|
818
|
+
void pactffi_message_metadata_pair_delete(MessageMetadataPair *pair);
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Construct a new `MessagePact` from the JSON string.
|
|
822
|
+
* The provided file name is used when generating error messages.
|
|
823
|
+
*
|
|
824
|
+
* # Safety
|
|
825
|
+
*
|
|
826
|
+
* The `file_name` and `json_str` parameters must both be valid UTF-8
|
|
827
|
+
* encoded strings.
|
|
828
|
+
*
|
|
829
|
+
* # Error Handling
|
|
830
|
+
*
|
|
831
|
+
* On error, this function will return a null pointer.
|
|
832
|
+
*/
|
|
833
|
+
MessagePact *pactffi_message_pact_new_from_json(const char *file_name, const char *json_str);
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* Delete the `MessagePact` being pointed to.
|
|
837
|
+
*/
|
|
838
|
+
void pactffi_message_pact_delete(MessagePact *message_pact);
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Get a pointer to the Consumer struct inside the MessagePact.
|
|
842
|
+
* This is a mutable borrow: The caller may mutate the Consumer
|
|
843
|
+
* through this pointer.
|
|
844
|
+
*
|
|
845
|
+
* # Safety
|
|
846
|
+
*
|
|
847
|
+
* This function is safe.
|
|
848
|
+
*
|
|
849
|
+
* # Error Handling
|
|
850
|
+
*
|
|
851
|
+
* This function will only fail if it is passed a NULL pointer.
|
|
852
|
+
* In the case of error, a NULL pointer will be returned.
|
|
853
|
+
*/
|
|
854
|
+
Consumer *pactffi_message_pact_get_consumer(MessagePact *message_pact);
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* Get a pointer to the Provider struct inside the MessagePact.
|
|
858
|
+
* This is a mutable borrow: The caller may mutate the Provider
|
|
859
|
+
* through this pointer.
|
|
860
|
+
*
|
|
861
|
+
* # Safety
|
|
862
|
+
*
|
|
863
|
+
* This function is safe.
|
|
864
|
+
*
|
|
865
|
+
* # Error Handling
|
|
866
|
+
*
|
|
867
|
+
* This function will only fail if it is passed a NULL pointer.
|
|
868
|
+
* In the case of error, a NULL pointer will be returned.
|
|
869
|
+
*/
|
|
870
|
+
Provider *pactffi_message_pact_get_provider(MessagePact *message_pact);
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Get an iterator over the messages of a message pact.
|
|
874
|
+
*
|
|
875
|
+
* # Safety
|
|
876
|
+
*
|
|
877
|
+
* This iterator carries a pointer to the message pact, and must
|
|
878
|
+
* not outlive the message pact.
|
|
879
|
+
*
|
|
880
|
+
* The message pact messages also must not be modified during iteration.
|
|
881
|
+
* If they are, the old iterator must be deleted and a new iterator created.
|
|
882
|
+
*
|
|
883
|
+
* # Error Handling
|
|
884
|
+
*
|
|
885
|
+
* On failure, this function will return a NULL pointer.
|
|
886
|
+
*
|
|
887
|
+
* This function may fail if any of the Rust strings contain embedded
|
|
888
|
+
* null ('\0') bytes.
|
|
889
|
+
*/
|
|
890
|
+
MessagePactMessageIterator *pactffi_message_pact_get_message_iter(MessagePact *message_pact);
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* Get the next message from the message pact.
|
|
894
|
+
*
|
|
895
|
+
* # Safety
|
|
896
|
+
*
|
|
897
|
+
* This function is safe.
|
|
898
|
+
*
|
|
899
|
+
* # Error Handling
|
|
900
|
+
*
|
|
901
|
+
* This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
|
|
902
|
+
*/
|
|
903
|
+
Message *pactffi_message_pact_message_iter_next(MessagePactMessageIterator *iter);
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* Delete the iterator.
|
|
907
|
+
*/
|
|
908
|
+
void pactffi_message_pact_message_iter_delete(MessagePactMessageIterator *iter);
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* Get a copy of the metadata value indexed by `key1` and `key2`.
|
|
912
|
+
*
|
|
913
|
+
* # Safety
|
|
914
|
+
*
|
|
915
|
+
* Since it is a copy, the returned string may safely outlive
|
|
916
|
+
* the `Message`.
|
|
917
|
+
*
|
|
918
|
+
* The returned string must be deleted with `pactffi_string_delete`.
|
|
919
|
+
*
|
|
920
|
+
* The returned pointer will be NULL if the metadata does not contain
|
|
921
|
+
* the given key, or if an error occurred.
|
|
922
|
+
*
|
|
923
|
+
* # Error Handling
|
|
924
|
+
*
|
|
925
|
+
* On failure, this function will return a NULL pointer.
|
|
926
|
+
*
|
|
927
|
+
* This function may fail if the provided `key1` or `key2` strings contains
|
|
928
|
+
* invalid UTF-8, or if the Rust string contains embedded null ('\0')
|
|
929
|
+
* bytes.
|
|
930
|
+
*/
|
|
931
|
+
const char *pactffi_message_pact_find_metadata(const MessagePact *message_pact,
|
|
932
|
+
const char *key1,
|
|
933
|
+
const char *key2);
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* Get an iterator over the metadata of a message pact.
|
|
937
|
+
*
|
|
938
|
+
* # Safety
|
|
939
|
+
*
|
|
940
|
+
* This iterator carries a pointer to the message pact, and must
|
|
941
|
+
* not outlive the message pact.
|
|
942
|
+
*
|
|
943
|
+
* The message pact metadata also must not be modified during iteration. If it is,
|
|
944
|
+
* the old iterator must be deleted and a new iterator created.
|
|
945
|
+
*
|
|
946
|
+
* # Error Handling
|
|
947
|
+
*
|
|
948
|
+
* On failure, this function will return a NULL pointer.
|
|
949
|
+
*
|
|
950
|
+
* This function may fail if any of the Rust strings contain
|
|
951
|
+
* embedded null ('\0') bytes.
|
|
952
|
+
*/
|
|
953
|
+
MessagePactMetadataIterator *pactffi_message_pact_get_metadata_iter(MessagePact *message_pact);
|
|
954
|
+
|
|
955
|
+
/**
|
|
956
|
+
* Get the next triple out of the iterator, if possible
|
|
957
|
+
*
|
|
958
|
+
* # Safety
|
|
959
|
+
*
|
|
960
|
+
* This operation is invalid if the underlying data has been changed during iteration.
|
|
961
|
+
*
|
|
962
|
+
* # Error Handling
|
|
963
|
+
*
|
|
964
|
+
* Returns null if no next element is present.
|
|
965
|
+
*/
|
|
966
|
+
MessagePactMetadataTriple *pactffi_message_pact_metadata_iter_next(MessagePactMetadataIterator *iter);
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
* Free the metadata iterator when you're done using it.
|
|
970
|
+
*/
|
|
971
|
+
void pactffi_message_pact_metadata_iter_delete(MessagePactMetadataIterator *iter);
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* Free a triple returned from `pactffi_message_pact_metadata_iter_next`.
|
|
975
|
+
*/
|
|
976
|
+
void pactffi_message_pact_metadata_triple_delete(MessagePactMetadataTriple *triple);
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* Get a copy of this provider's name.
|
|
980
|
+
*
|
|
981
|
+
* The copy must be deleted with `pactffi_string_delete`.
|
|
982
|
+
*
|
|
983
|
+
* # Usage
|
|
984
|
+
*
|
|
985
|
+
* ```c
|
|
986
|
+
* // Assuming `file_name` and `json_str` are already defined.
|
|
987
|
+
*
|
|
988
|
+
* MessagePact *message_pact = pactffi_message_pact_new_from_json(file_name, json_str);
|
|
989
|
+
* if (message_pact == NULLPTR) {
|
|
990
|
+
* // handle error.
|
|
991
|
+
* }
|
|
992
|
+
*
|
|
993
|
+
* Provider *provider = pactffi_message_pact_get_provider(message_pact);
|
|
994
|
+
* if (provider == NULLPTR) {
|
|
995
|
+
* // handle error.
|
|
996
|
+
* }
|
|
997
|
+
*
|
|
998
|
+
* char *name = pactffi_provider_get_name(provider);
|
|
999
|
+
* if (name == NULL) {
|
|
1000
|
+
* // handle error.
|
|
1001
|
+
* }
|
|
1002
|
+
*
|
|
1003
|
+
* printf("%s\n", name);
|
|
1004
|
+
*
|
|
1005
|
+
* pactffi_string_delete(name);
|
|
1006
|
+
* ```
|
|
1007
|
+
*
|
|
1008
|
+
* # Errors
|
|
1009
|
+
*
|
|
1010
|
+
* This function will fail if it is passed a NULL pointer,
|
|
1011
|
+
* or the Rust string contains an embedded NULL byte.
|
|
1012
|
+
* In the case of error, a NULL pointer will be returned.
|
|
1013
|
+
*/
|
|
1014
|
+
const char *pactffi_provider_get_name(const Provider *provider);
|
|
1015
|
+
|
|
1016
|
+
/**
|
|
1017
|
+
* Get the name of the provider state as a string, which needs to be deleted with `pactffi_string_delete`.
|
|
1018
|
+
*
|
|
1019
|
+
* # Safety
|
|
1020
|
+
*
|
|
1021
|
+
* This function is safe.
|
|
1022
|
+
*
|
|
1023
|
+
* # Error Handling
|
|
1024
|
+
*
|
|
1025
|
+
* If the provider_state param is NULL, this returns NULL.
|
|
1026
|
+
*/
|
|
1027
|
+
const char *pactffi_provider_state_get_name(const ProviderState *provider_state);
|
|
1028
|
+
|
|
1029
|
+
/**
|
|
1030
|
+
* Get an iterator over the params of a provider state.
|
|
1031
|
+
*
|
|
1032
|
+
* # Safety
|
|
1033
|
+
*
|
|
1034
|
+
* This iterator carries a pointer to the provider state, and must
|
|
1035
|
+
* not outlive the provider state.
|
|
1036
|
+
*
|
|
1037
|
+
* The provider state params also must not be modified during iteration. If it is,
|
|
1038
|
+
* the old iterator must be deleted and a new iterator created.
|
|
1039
|
+
*
|
|
1040
|
+
* # Errors
|
|
1041
|
+
*
|
|
1042
|
+
* On failure, this function will return a NULL pointer.
|
|
1043
|
+
*
|
|
1044
|
+
* This function may fail if any of the Rust strings contain
|
|
1045
|
+
* embedded null ('\0') bytes.
|
|
1046
|
+
*/
|
|
1047
|
+
ProviderStateParamIterator *pactffi_provider_state_get_param_iter(ProviderState *provider_state);
|
|
1048
|
+
|
|
1049
|
+
/**
|
|
1050
|
+
* Get the next key and value out of the iterator, if possible
|
|
1051
|
+
*
|
|
1052
|
+
* Returns a pointer to a heap allocated array of 2 elements, the pointer to the
|
|
1053
|
+
* key string on the heap, and the pointer to the value string on the heap.
|
|
1054
|
+
*
|
|
1055
|
+
* # Safety
|
|
1056
|
+
*
|
|
1057
|
+
* The underlying data must not be modified during iteration.
|
|
1058
|
+
*
|
|
1059
|
+
* The user needs to free both the contained strings and the array.
|
|
1060
|
+
*
|
|
1061
|
+
* # Error Handling
|
|
1062
|
+
*
|
|
1063
|
+
* Returns NULL if there's no further elements or the iterator is NULL.
|
|
1064
|
+
*/
|
|
1065
|
+
ProviderStateParamPair *pactffi_provider_state_param_iter_next(ProviderStateParamIterator *iter);
|
|
1066
|
+
|
|
1067
|
+
/**
|
|
1068
|
+
* Free the provider state when you're done using it.
|
|
1069
|
+
*/
|
|
1070
|
+
void pactffi_provider_state_delete(ProviderState *provider_state);
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
* Free the provider state param iterator when you're done using it.
|
|
1074
|
+
*/
|
|
1075
|
+
void pactffi_provider_state_param_iter_delete(ProviderStateParamIterator *iter);
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* Free a pair of key and value returned from `pactffi_provider_state_param_iter_next`.
|
|
1079
|
+
*/
|
|
1080
|
+
void pactffi_provider_state_param_pair_delete(ProviderStateParamPair *pair);
|
|
1081
|
+
|
|
1082
|
+
/**
|
|
1083
|
+
* Free the iterator when you're done using it.
|
|
1084
|
+
*/
|
|
1085
|
+
void pactffi_pact_message_iter_delete(PactMessageIterator *iter);
|
|
1086
|
+
|
|
1087
|
+
/**
|
|
1088
|
+
* Get the next message from the message pact. As the messages returned are owned by the
|
|
1089
|
+
* iterator, they do not need to be deleted but will be cleaned up when the iterator is
|
|
1090
|
+
* deleted.
|
|
1091
|
+
*
|
|
1092
|
+
* # Safety
|
|
1093
|
+
*
|
|
1094
|
+
* This function is safe.
|
|
1095
|
+
*
|
|
1096
|
+
* Deleting a message returned by the iterator can lead to undefined behaviour.
|
|
1097
|
+
*
|
|
1098
|
+
* # Error Handling
|
|
1099
|
+
*
|
|
1100
|
+
* This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
|
|
1101
|
+
*/
|
|
1102
|
+
Message *pactffi_pact_message_iter_next(PactMessageIterator *iter);
|
|
1103
|
+
|
|
1104
|
+
/**
|
|
1105
|
+
* Get the next synchronous request/response message from the pact. As the messages returned are owned by the
|
|
1106
|
+
* iterator, they do not need to be deleted but will be cleaned up when the iterator is
|
|
1107
|
+
* deleted.
|
|
1108
|
+
*
|
|
1109
|
+
* # Safety
|
|
1110
|
+
*
|
|
1111
|
+
* This function is safe.
|
|
1112
|
+
*
|
|
1113
|
+
* Deleting a message returned by the iterator can lead to undefined behaviour.
|
|
1114
|
+
*
|
|
1115
|
+
* # Error Handling
|
|
1116
|
+
*
|
|
1117
|
+
* This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
|
|
1118
|
+
*/
|
|
1119
|
+
SynchronousMessage *pactffi_pact_sync_message_iter_next(PactSyncMessageIterator *iter);
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* Free the iterator when you're done using it.
|
|
1123
|
+
*/
|
|
1124
|
+
void pactffi_pact_sync_message_iter_delete(PactSyncMessageIterator *iter);
|
|
1125
|
+
|
|
1126
|
+
/**
|
|
1127
|
+
* Destroy the `Message` being pointed to.
|
|
1128
|
+
*/
|
|
1129
|
+
void pactffi_sync_message_delete(SynchronousMessage *message);
|
|
1130
|
+
|
|
1131
|
+
/**
|
|
1132
|
+
* Get the request contents of a `SynchronousMessage` in string form.
|
|
1133
|
+
*
|
|
1134
|
+
* # Safety
|
|
1135
|
+
*
|
|
1136
|
+
* The returned string must be deleted with `pactffi_string_delete`.
|
|
1137
|
+
*
|
|
1138
|
+
* The returned string can outlive the message.
|
|
1139
|
+
*
|
|
1140
|
+
* # Error Handling
|
|
1141
|
+
*
|
|
1142
|
+
* If the message is NULL, returns NULL. If the body of the request message
|
|
1143
|
+
* is missing, then this function also returns NULL. This means there's
|
|
1144
|
+
* no mechanism to differentiate with this function call alone between
|
|
1145
|
+
* a NULL message and a missing message body.
|
|
1146
|
+
*/
|
|
1147
|
+
const char *pactffi_sync_message_get_request_contents(const SynchronousMessage *message);
|
|
1148
|
+
|
|
1149
|
+
/**
|
|
1150
|
+
* Get the length of the request contents of a `SynchronousMessage`.
|
|
1151
|
+
*
|
|
1152
|
+
* # Safety
|
|
1153
|
+
*
|
|
1154
|
+
* This function is safe.
|
|
1155
|
+
*
|
|
1156
|
+
* # Error Handling
|
|
1157
|
+
*
|
|
1158
|
+
* If the message is NULL, returns 0. If the body of the request
|
|
1159
|
+
* is missing, then this function also returns 0.
|
|
1160
|
+
*/
|
|
1161
|
+
size_t pactffi_sync_message_get_request_contents_length(const SynchronousMessage *message);
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* Get the request contents of a `SynchronousMessage` as a pointer to an array of bytes.
|
|
1165
|
+
*
|
|
1166
|
+
* # Safety
|
|
1167
|
+
*
|
|
1168
|
+
* The number of bytes in the buffer will be returned by `pactffi_sync_message_get_request_contents_length`.
|
|
1169
|
+
* It is safe to use the pointer while the message is not deleted or changed. Using the pointer
|
|
1170
|
+
* after the message is mutated or deleted may lead to undefined behaviour.
|
|
1171
|
+
*
|
|
1172
|
+
* # Error Handling
|
|
1173
|
+
*
|
|
1174
|
+
* If the message is NULL, returns NULL. If the body of the message
|
|
1175
|
+
* is missing, then this function also returns NULL.
|
|
1176
|
+
*/
|
|
1177
|
+
const unsigned char *pactffi_sync_message_get_request_contents_bin(const SynchronousMessage *message);
|
|
1178
|
+
|
|
1179
|
+
/**
|
|
1180
|
+
* Get the number of response messages in the `SynchronousMessage`.
|
|
1181
|
+
*
|
|
1182
|
+
* # Safety
|
|
1183
|
+
*
|
|
1184
|
+
* The message pointer must point to a valid SynchronousMessage.
|
|
1185
|
+
*
|
|
1186
|
+
* # Error Handling
|
|
1187
|
+
*
|
|
1188
|
+
* If the message is NULL, returns 0.
|
|
1189
|
+
*/
|
|
1190
|
+
size_t pactffi_sync_message_get_number_responses(const SynchronousMessage *message);
|
|
1191
|
+
|
|
1192
|
+
/**
|
|
1193
|
+
* Get the response contents of a `SynchronousMessage` in string form.
|
|
1194
|
+
*
|
|
1195
|
+
* # Safety
|
|
1196
|
+
*
|
|
1197
|
+
* The returned string must be deleted with `pactffi_string_delete`.
|
|
1198
|
+
*
|
|
1199
|
+
* The returned string can outlive the message.
|
|
1200
|
+
*
|
|
1201
|
+
* # Error Handling
|
|
1202
|
+
*
|
|
1203
|
+
* If the message is NULL or the index is not valid, returns NULL.
|
|
1204
|
+
*
|
|
1205
|
+
* If the body of the response message is missing, then this function also returns NULL.
|
|
1206
|
+
* This means there's no mechanism to differentiate with this function call alone between
|
|
1207
|
+
* a NULL message and a missing message body.
|
|
1208
|
+
*/
|
|
1209
|
+
const char *pactffi_sync_message_get_response_contents(const SynchronousMessage *message,
|
|
1210
|
+
size_t index);
|
|
1211
|
+
|
|
1212
|
+
/**
|
|
1213
|
+
* Get the length of the response contents of a `SynchronousMessage`.
|
|
1214
|
+
*
|
|
1215
|
+
* # Safety
|
|
1216
|
+
*
|
|
1217
|
+
* This function is safe.
|
|
1218
|
+
*
|
|
1219
|
+
* # Error Handling
|
|
1220
|
+
*
|
|
1221
|
+
* If the message is NULL or the index is not valid, returns 0. If the body of the request
|
|
1222
|
+
* is missing, then this function also returns 0.
|
|
1223
|
+
*/
|
|
1224
|
+
size_t pactffi_sync_message_get_response_contents_length(const SynchronousMessage *message,
|
|
1225
|
+
size_t index);
|
|
1226
|
+
|
|
1227
|
+
/**
|
|
1228
|
+
* Get the response contents of a `SynchronousMessage` as a pointer to an array of bytes.
|
|
1229
|
+
*
|
|
1230
|
+
* # Safety
|
|
1231
|
+
*
|
|
1232
|
+
* The number of bytes in the buffer will be returned by `pactffi_sync_message_get_response_contents_length`.
|
|
1233
|
+
* It is safe to use the pointer while the message is not deleted or changed. Using the pointer
|
|
1234
|
+
* after the message is mutated or deleted may lead to undefined behaviour.
|
|
1235
|
+
*
|
|
1236
|
+
* # Error Handling
|
|
1237
|
+
*
|
|
1238
|
+
* If the message is NULL or the index is not valid, returns NULL. If the body of the message
|
|
1239
|
+
* is missing, then this function also returns NULL.
|
|
1240
|
+
*/
|
|
1241
|
+
const unsigned char *pactffi_sync_message_get_response_contents_bin(const SynchronousMessage *message,
|
|
1242
|
+
size_t index);
|
|
1243
|
+
|
|
1244
|
+
/**
|
|
1245
|
+
* Get a copy of the description.
|
|
1246
|
+
*
|
|
1247
|
+
* # Safety
|
|
1248
|
+
*
|
|
1249
|
+
* The returned string must be deleted with `pactffi_string_delete`.
|
|
1250
|
+
*
|
|
1251
|
+
* Since it is a copy, the returned string may safely outlive
|
|
1252
|
+
* the `SynchronousMessage`.
|
|
1253
|
+
*
|
|
1254
|
+
* # Errors
|
|
1255
|
+
*
|
|
1256
|
+
* On failure, this function will return a NULL pointer.
|
|
1257
|
+
*
|
|
1258
|
+
* This function may fail if the Rust string contains embedded
|
|
1259
|
+
* null ('\0') bytes.
|
|
1260
|
+
*/
|
|
1261
|
+
const char *pactffi_sync_message_get_description(const SynchronousMessage *message);
|
|
1262
|
+
|
|
1263
|
+
/**
|
|
1264
|
+
* Write the `description` field on the `SynchronousMessage`.
|
|
1265
|
+
*
|
|
1266
|
+
* # Safety
|
|
1267
|
+
*
|
|
1268
|
+
* `description` must contain valid UTF-8. Invalid UTF-8
|
|
1269
|
+
* will be replaced with U+FFFD REPLACEMENT CHARACTER.
|
|
1270
|
+
*
|
|
1271
|
+
* This function will only reallocate if the new string
|
|
1272
|
+
* does not fit in the existing buffer.
|
|
1273
|
+
*
|
|
1274
|
+
* # Error Handling
|
|
1275
|
+
*
|
|
1276
|
+
* Errors will be reported with a non-zero return value.
|
|
1277
|
+
*/
|
|
1278
|
+
int pactffi_sync_message_set_description(SynchronousMessage *message, const char *description);
|
|
1279
|
+
|
|
1280
|
+
/**
|
|
1281
|
+
* Get a copy of the provider state at the given index from this message.
|
|
1282
|
+
*
|
|
1283
|
+
* # Safety
|
|
1284
|
+
*
|
|
1285
|
+
* The returned structure must be deleted with `provider_state_delete`.
|
|
1286
|
+
*
|
|
1287
|
+
* Since it is a copy, the returned structure may safely outlive
|
|
1288
|
+
* the `SynchronousMessage`.
|
|
1289
|
+
*
|
|
1290
|
+
* # Error Handling
|
|
1291
|
+
*
|
|
1292
|
+
* On failure, this function will return a variant other than Success.
|
|
1293
|
+
*
|
|
1294
|
+
* This function may fail if the index requested is out of bounds,
|
|
1295
|
+
* or if any of the Rust strings contain embedded null ('\0') bytes.
|
|
1296
|
+
*/
|
|
1297
|
+
const ProviderState *pactffi_sync_message_get_provider_state(const SynchronousMessage *message,
|
|
1298
|
+
unsigned int index);
|
|
1299
|
+
|
|
1300
|
+
/**
|
|
1301
|
+
* Get an iterator over provider states.
|
|
1302
|
+
*
|
|
1303
|
+
* # Safety
|
|
1304
|
+
*
|
|
1305
|
+
* The underlying data must not change during iteration.
|
|
1306
|
+
*
|
|
1307
|
+
* # Error Handling
|
|
1308
|
+
*
|
|
1309
|
+
* Returns NULL if an error occurs.
|
|
1310
|
+
*/
|
|
1311
|
+
ProviderStateIterator *pactffi_sync_message_get_provider_state_iter(SynchronousMessage *message);
|
|
1312
|
+
|
|
1313
|
+
/**
|
|
1314
|
+
* Delete a string previously returned by this FFI.
|
|
1315
|
+
*
|
|
1316
|
+
* It is explicitly allowed to pass a null pointer to this function;
|
|
1317
|
+
* in that case the function will do nothing.
|
|
1318
|
+
*/
|
|
1319
|
+
void pactffi_string_delete(char *string);
|
|
1320
|
+
|
|
1321
|
+
/**
|
|
1322
|
+
* External interface to create a mock server. A pointer to the pact JSON as a C string is passed in,
|
|
1323
|
+
* as well as the port for the mock server to run on. A value of 0 for the port will result in a
|
|
1324
|
+
* port being allocated by the operating system. The port of the mock server is returned.
|
|
1325
|
+
*
|
|
1326
|
+
* * `pact_str` - Pact JSON
|
|
1327
|
+
* * `addr_str` - Address to bind to in the form name:port (i.e. 127.0.0.1:0)
|
|
1328
|
+
* * `tls` - boolean flag to indicate of the mock server should use TLS (using a self-signed certificate)
|
|
1329
|
+
*
|
|
1330
|
+
* # Errors
|
|
1331
|
+
*
|
|
1332
|
+
* Errors are returned as negative values.
|
|
1333
|
+
*
|
|
1334
|
+
* | Error | Description |
|
|
1335
|
+
* |-------|-------------|
|
|
1336
|
+
* | -1 | A null pointer was received |
|
|
1337
|
+
* | -2 | The pact JSON could not be parsed |
|
|
1338
|
+
* | -3 | The mock server could not be started |
|
|
1339
|
+
* | -4 | The method panicked |
|
|
1340
|
+
* | -5 | The address is not valid |
|
|
1341
|
+
* | -6 | Could not create the TLS configuration with the self-signed certificate |
|
|
1342
|
+
*
|
|
1343
|
+
*/
|
|
1344
|
+
int32_t pactffi_create_mock_server(const char *pact_str,
|
|
1345
|
+
const char *addr_str,
|
|
1346
|
+
bool tls);
|
|
1347
|
+
|
|
1348
|
+
/**
|
|
1349
|
+
* Fetch the CA Certificate used to generate the self-signed certificate for the TLS mock server.
|
|
1350
|
+
*
|
|
1351
|
+
* **NOTE:** The string for the result is allocated on the heap, and will have to be freed
|
|
1352
|
+
* by the caller using free_string
|
|
1353
|
+
*
|
|
1354
|
+
* # Errors
|
|
1355
|
+
*
|
|
1356
|
+
* An empty string indicates an error reading the pem file
|
|
1357
|
+
*/
|
|
1358
|
+
char *pactffi_get_tls_ca_certificate();
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* External interface to create a mock server. A Pact handle is passed in,
|
|
1362
|
+
* as well as the port for the mock server to run on. A value of 0 for the port will result in a
|
|
1363
|
+
* port being allocated by the operating system. The port of the mock server is returned.
|
|
1364
|
+
*
|
|
1365
|
+
* * `pact` - Handle to a Pact model
|
|
1366
|
+
* * `addr_str` - Address to bind to in the form name:port (i.e. 127.0.0.1:0)
|
|
1367
|
+
* * `tls` - boolean flag to indicate of the mock server should use TLS (using a self-signed certificate)
|
|
1368
|
+
*
|
|
1369
|
+
* # Errors
|
|
1370
|
+
*
|
|
1371
|
+
* Errors are returned as negative values.
|
|
1372
|
+
*
|
|
1373
|
+
* | Error | Description |
|
|
1374
|
+
* |-------|-------------|
|
|
1375
|
+
* | -1 | An invalid handle was received |
|
|
1376
|
+
* | -3 | The mock server could not be started |
|
|
1377
|
+
* | -4 | The method panicked |
|
|
1378
|
+
* | -5 | The address is not valid |
|
|
1379
|
+
* | -6 | Could not create the TLS configuration with the self-signed certificate |
|
|
1380
|
+
*
|
|
1381
|
+
*/
|
|
1382
|
+
int32_t pactffi_create_mock_server_for_pact(PactHandle pact,
|
|
1383
|
+
const char *addr_str,
|
|
1384
|
+
bool tls);
|
|
1385
|
+
|
|
1386
|
+
/**
|
|
1387
|
+
* External interface to check if a mock server has matched all its requests. The port number is
|
|
1388
|
+
* passed in, and if all requests have been matched, true is returned. False is returned if there
|
|
1389
|
+
* is no mock server on the given port, or if any request has not been successfully matched, or
|
|
1390
|
+
* the method panics.
|
|
1391
|
+
*/
|
|
1392
|
+
bool pactffi_mock_server_matched(int32_t mock_server_port);
|
|
1393
|
+
|
|
1394
|
+
/**
|
|
1395
|
+
* External interface to get all the mismatches from a mock server. The port number of the mock
|
|
1396
|
+
* server is passed in, and a pointer to a C string with the mismatches in JSON format is
|
|
1397
|
+
* returned.
|
|
1398
|
+
*
|
|
1399
|
+
* **NOTE:** The JSON string for the result is allocated on the heap, and will have to be freed
|
|
1400
|
+
* once the code using the mock server is complete. The [`cleanup_mock_server`](fn.cleanup_mock_server.html) function is
|
|
1401
|
+
* provided for this purpose.
|
|
1402
|
+
*
|
|
1403
|
+
* # Errors
|
|
1404
|
+
*
|
|
1405
|
+
* If there is no mock server with the provided port number, or the function panics, a NULL
|
|
1406
|
+
* pointer will be returned. Don't try to dereference it, it will not end well for you.
|
|
1407
|
+
*
|
|
1408
|
+
*/
|
|
1409
|
+
char *pactffi_mock_server_mismatches(int32_t mock_server_port);
|
|
1410
|
+
|
|
1411
|
+
/**
|
|
1412
|
+
* External interface to cleanup a mock server. This function will try terminate the mock server
|
|
1413
|
+
* with the given port number and cleanup any memory allocated for it. Returns true, unless a
|
|
1414
|
+
* mock server with the given port number does not exist, or the function panics.
|
|
1415
|
+
*/
|
|
1416
|
+
bool pactffi_cleanup_mock_server(int32_t mock_server_port);
|
|
1417
|
+
|
|
1418
|
+
/**
|
|
1419
|
+
* External interface to trigger a mock server to write out its pact file. This function should
|
|
1420
|
+
* be called if all the consumer tests have passed. The directory to write the file to is passed
|
|
1421
|
+
* as the second parameter. If a NULL pointer is passed, the current working directory is used.
|
|
1422
|
+
*
|
|
1423
|
+
* If overwrite is true, the file will be overwritten with the contents of the current pact.
|
|
1424
|
+
* Otherwise, it will be merged with any existing pact file.
|
|
1425
|
+
*
|
|
1426
|
+
* Returns 0 if the pact file was successfully written. Returns a positive code if the file can
|
|
1427
|
+
* not be written, or there is no mock server running on that port or the function panics.
|
|
1428
|
+
*
|
|
1429
|
+
* # Errors
|
|
1430
|
+
*
|
|
1431
|
+
* Errors are returned as positive values.
|
|
1432
|
+
*
|
|
1433
|
+
* | Error | Description |
|
|
1434
|
+
* |-------|-------------|
|
|
1435
|
+
* | 1 | A general panic was caught |
|
|
1436
|
+
* | 2 | The pact file was not able to be written |
|
|
1437
|
+
* | 3 | A mock server with the provided port was not found |
|
|
1438
|
+
*/
|
|
1439
|
+
int32_t pactffi_write_pact_file(int32_t mock_server_port, const char *directory, bool overwrite);
|
|
1440
|
+
|
|
1441
|
+
/**
|
|
1442
|
+
* Fetch the logs for the mock server. This needs the memory buffer log sink to be setup before
|
|
1443
|
+
* the mock server is started. Returned string will be freed with the `cleanup_mock_server`
|
|
1444
|
+
* function call.
|
|
1445
|
+
*
|
|
1446
|
+
* Will return a NULL pointer if the logs for the mock server can not be retrieved.
|
|
1447
|
+
*/
|
|
1448
|
+
const char *pactffi_mock_server_logs(int32_t mock_server_port);
|
|
1449
|
+
|
|
1450
|
+
/**
|
|
1451
|
+
* Generates a datetime value from the provided format string, using the current system date and time
|
|
1452
|
+
* NOTE: The memory for the returned string needs to be freed with the free_string function
|
|
1453
|
+
*
|
|
1454
|
+
* # Safety
|
|
1455
|
+
*
|
|
1456
|
+
* Exported functions are inherently unsafe.
|
|
1457
|
+
*/
|
|
1458
|
+
StringResult pactffi_generate_datetime_string(const char *format);
|
|
1459
|
+
|
|
1460
|
+
/**
|
|
1461
|
+
* Checks that the example string matches the given regex
|
|
1462
|
+
*
|
|
1463
|
+
* # Safety
|
|
1464
|
+
*
|
|
1465
|
+
* Exported functions are inherently unsafe.
|
|
1466
|
+
*/
|
|
1467
|
+
bool pactffi_check_regex(const char *regex, const char *example);
|
|
1468
|
+
|
|
1469
|
+
/**
|
|
1470
|
+
* Generates an example string based on the provided regex.
|
|
1471
|
+
* NOTE: The memory for the returned string needs to be freed with the free_string function
|
|
1472
|
+
*
|
|
1473
|
+
* # Safety
|
|
1474
|
+
*
|
|
1475
|
+
* Exported functions are inherently unsafe.
|
|
1476
|
+
*/
|
|
1477
|
+
StringResult pactffi_generate_regex_value(const char *regex);
|
|
1478
|
+
|
|
1479
|
+
/**
|
|
1480
|
+
* [DEPRECATED] Frees the memory allocated to a string by another function
|
|
1481
|
+
*
|
|
1482
|
+
* This function is deprecated. Use pactffi_string_delete instead.
|
|
1483
|
+
*
|
|
1484
|
+
* # Safety
|
|
1485
|
+
*
|
|
1486
|
+
* Exported functions are inherently unsafe.
|
|
1487
|
+
*/
|
|
1488
|
+
void pactffi_free_string(char *s);
|
|
1489
|
+
|
|
1490
|
+
/**
|
|
1491
|
+
* Creates a new Pact model and returns a handle to it.
|
|
1492
|
+
*
|
|
1493
|
+
* * `consumer_name` - The name of the consumer for the pact.
|
|
1494
|
+
* * `provider_name` - The name of the provider for the pact.
|
|
1495
|
+
*
|
|
1496
|
+
* Returns a new `PactHandle`. The handle will need to be freed with the `pactffi_free_pact_handle`
|
|
1497
|
+
* method to release its resources.
|
|
1498
|
+
*/
|
|
1499
|
+
PactHandle pactffi_new_pact(const char *consumer_name, const char *provider_name);
|
|
1500
|
+
|
|
1501
|
+
/**
|
|
1502
|
+
* Creates a new HTTP Interaction and returns a handle to it.
|
|
1503
|
+
*
|
|
1504
|
+
* * `description` - The interaction description. It needs to be unique for each interaction.
|
|
1505
|
+
*
|
|
1506
|
+
* Returns a new `InteractionHandle`.
|
|
1507
|
+
*/
|
|
1508
|
+
InteractionHandle pactffi_new_interaction(PactHandle pact, const char *description);
|
|
1509
|
+
|
|
1510
|
+
/**
|
|
1511
|
+
* Creates a new message interaction and return a handle to it
|
|
1512
|
+
* * `description` - The interaction description. It needs to be unique for each interaction.
|
|
1513
|
+
*
|
|
1514
|
+
* Returns a new `InteractionHandle`.
|
|
1515
|
+
*/
|
|
1516
|
+
InteractionHandle pactffi_new_message_interaction(PactHandle pact, const char *description);
|
|
1517
|
+
|
|
1518
|
+
/**
|
|
1519
|
+
* Creates a new synchronous message interaction (request/response) and return a handle to it
|
|
1520
|
+
* * `description` - The interaction description. It needs to be unique for each interaction.
|
|
1521
|
+
*
|
|
1522
|
+
* Returns a new `InteractionHandle`.
|
|
1523
|
+
*/
|
|
1524
|
+
InteractionHandle pactffi_new_sync_message_interaction(PactHandle pact, const char *description);
|
|
1525
|
+
|
|
1526
|
+
/**
|
|
1527
|
+
* Sets the description for the Interaction. Returns false if the interaction or Pact can't be
|
|
1528
|
+
* modified (i.e. the mock server for it has already started)
|
|
1529
|
+
*
|
|
1530
|
+
* * `description` - The interaction description. It needs to be unique for each interaction.
|
|
1531
|
+
*/
|
|
1532
|
+
bool pactffi_upon_receiving(InteractionHandle interaction, const char *description);
|
|
1533
|
+
|
|
1534
|
+
/**
|
|
1535
|
+
* Adds a provider state to the Interaction. Returns false if the interaction or Pact can't be
|
|
1536
|
+
* modified (i.e. the mock server for it has already started)
|
|
1537
|
+
*
|
|
1538
|
+
* * `description` - The provider state description. It needs to be unique.
|
|
1539
|
+
*/
|
|
1540
|
+
bool pactffi_given(InteractionHandle interaction, const char *description);
|
|
1541
|
+
|
|
1542
|
+
/**
|
|
1543
|
+
* Sets the test name annotation for the interaction. This allows capturing the name of
|
|
1544
|
+
* the test as metadata. This can only be used with V4 interactions.
|
|
1545
|
+
*
|
|
1546
|
+
* # Safety
|
|
1547
|
+
*
|
|
1548
|
+
* The test name parameter must be a valid pointer to a NULL terminated string.
|
|
1549
|
+
*
|
|
1550
|
+
* # Error Handling
|
|
1551
|
+
*
|
|
1552
|
+
* If the test name can not be set, this will return a positive value.
|
|
1553
|
+
*
|
|
1554
|
+
* * `1` - Function panicked. Error message will be available by calling `pactffi_get_error_message`.
|
|
1555
|
+
* * `2` - Handle was not valid.
|
|
1556
|
+
* * `3` - Mock server was already started and the interation can not be modified.
|
|
1557
|
+
* * `4` - Not a V4 interaction.
|
|
1558
|
+
*/
|
|
1559
|
+
unsigned int pactffi_interaction_test_name(InteractionHandle interaction,
|
|
1560
|
+
const char *test_name);
|
|
1561
|
+
|
|
1562
|
+
/**
|
|
1563
|
+
* Adds a provider state to the Interaction with a parameter key and value. Returns false if the interaction or Pact can't be
|
|
1564
|
+
* modified (i.e. the mock server for it has already started)
|
|
1565
|
+
*
|
|
1566
|
+
* * `description` - The provider state description. It needs to be unique.
|
|
1567
|
+
* * `name` - Parameter name.
|
|
1568
|
+
* * `value` - Parameter value.
|
|
1569
|
+
*/
|
|
1570
|
+
bool pactffi_given_with_param(InteractionHandle interaction,
|
|
1571
|
+
const char *description,
|
|
1572
|
+
const char *name,
|
|
1573
|
+
const char *value);
|
|
1574
|
+
|
|
1575
|
+
/**
|
|
1576
|
+
* Configures the request for the Interaction. Returns false if the interaction or Pact can't be
|
|
1577
|
+
* modified (i.e. the mock server for it has already started)
|
|
1578
|
+
*
|
|
1579
|
+
* * `method` - The request method. Defaults to GET.
|
|
1580
|
+
* * `path` - The request path. Defaults to `/`.
|
|
1581
|
+
*/
|
|
1582
|
+
bool pactffi_with_request(InteractionHandle interaction, const char *method, const char *path);
|
|
1583
|
+
|
|
1584
|
+
/**
|
|
1585
|
+
* Configures a query parameter for the Interaction. Returns false if the interaction or Pact can't be
|
|
1586
|
+
* modified (i.e. the mock server for it has already started)
|
|
1587
|
+
*
|
|
1588
|
+
* * `name` - the query parameter name.
|
|
1589
|
+
* * `value` - the query parameter value.
|
|
1590
|
+
* * `index` - the index of the value (starts at 0). You can use this to create a query parameter with multiple values
|
|
1591
|
+
*/
|
|
1592
|
+
bool pactffi_with_query_parameter(InteractionHandle interaction,
|
|
1593
|
+
const char *name,
|
|
1594
|
+
size_t index,
|
|
1595
|
+
const char *value);
|
|
1596
|
+
|
|
1597
|
+
/**
|
|
1598
|
+
* Sets the specification version for a given Pact model. Returns false if the interaction or Pact can't be
|
|
1599
|
+
* modified (i.e. the mock server for it has already started) or the version is invalid
|
|
1600
|
+
*
|
|
1601
|
+
* * `pact` - Handle to a Pact model
|
|
1602
|
+
* * `version` - the spec version to use
|
|
1603
|
+
*/
|
|
1604
|
+
bool pactffi_with_specification(PactHandle pact,
|
|
1605
|
+
PactSpecification version);
|
|
1606
|
+
|
|
1607
|
+
/**
|
|
1608
|
+
* Sets the additional metadata on the Pact file. Common uses are to add the client library details such as the name and version
|
|
1609
|
+
* Returns false if the interaction or Pact can't be modified (i.e. the mock server for it has already started)
|
|
1610
|
+
*
|
|
1611
|
+
* * `pact` - Handle to a Pact model
|
|
1612
|
+
* * `namespace` - the top level metadat key to set any key values on
|
|
1613
|
+
* * `name` - the key to set
|
|
1614
|
+
* * `value` - the value to set
|
|
1615
|
+
*/
|
|
1616
|
+
bool pactffi_with_pact_metadata(PactHandle pact,
|
|
1617
|
+
const char *namespace_,
|
|
1618
|
+
const char *name,
|
|
1619
|
+
const char *value);
|
|
1620
|
+
|
|
1621
|
+
/**
|
|
1622
|
+
* Configures a header for the Interaction. Returns false if the interaction or Pact can't be
|
|
1623
|
+
* modified (i.e. the mock server for it has already started)
|
|
1624
|
+
*
|
|
1625
|
+
* * `part` - The part of the interaction to add the header to (Request or Response).
|
|
1626
|
+
* * `name` - the header name.
|
|
1627
|
+
* * `value` - the header value.
|
|
1628
|
+
* * `index` - the index of the value (starts at 0). You can use this to create a header with multiple values
|
|
1629
|
+
*/
|
|
1630
|
+
bool pactffi_with_header(InteractionHandle interaction,
|
|
1631
|
+
InteractionPart part,
|
|
1632
|
+
const char *name,
|
|
1633
|
+
size_t index,
|
|
1634
|
+
const char *value);
|
|
1635
|
+
|
|
1636
|
+
/**
|
|
1637
|
+
* Configures the response for the Interaction. Returns false if the interaction or Pact can't be
|
|
1638
|
+
* modified (i.e. the mock server for it has already started)
|
|
1639
|
+
*
|
|
1640
|
+
* * `status` - the response status. Defaults to 200.
|
|
1641
|
+
*/
|
|
1642
|
+
bool pactffi_response_status(InteractionHandle interaction, unsigned short status);
|
|
1643
|
+
|
|
1644
|
+
/**
|
|
1645
|
+
* Adds the body for the interaction. Returns false if the interaction or Pact can't be
|
|
1646
|
+
* modified (i.e. the mock server for it has already started)
|
|
1647
|
+
*
|
|
1648
|
+
* * `part` - The part of the interaction to add the body to (Request or Response).
|
|
1649
|
+
* * `content_type` - The content type of the body. Defaults to `text/plain`. Will be ignored if a content type
|
|
1650
|
+
* header is already set.
|
|
1651
|
+
* * `body` - The body contents. For JSON payloads, matching rules can be embedded in the body.
|
|
1652
|
+
*/
|
|
1653
|
+
bool pactffi_with_body(InteractionHandle interaction,
|
|
1654
|
+
InteractionPart part,
|
|
1655
|
+
const char *content_type,
|
|
1656
|
+
const char *body);
|
|
1657
|
+
|
|
1658
|
+
/**
|
|
1659
|
+
* Adds a binary file as the body with the expected content type and example contents. Will use
|
|
1660
|
+
* a mime type matcher to match the body. Returns false if the interaction or Pact can't be
|
|
1661
|
+
* modified (i.e. the mock server for it has already started)
|
|
1662
|
+
*
|
|
1663
|
+
* * `interaction` - Interaction handle to set the body for.
|
|
1664
|
+
* * `part` - Request or response part.
|
|
1665
|
+
* * `content_type` - Expected content type.
|
|
1666
|
+
* * `body` - example body contents in bytes
|
|
1667
|
+
* * `size` - number of bytes in the body
|
|
1668
|
+
*/
|
|
1669
|
+
bool pactffi_with_binary_file(InteractionHandle interaction,
|
|
1670
|
+
InteractionPart part,
|
|
1671
|
+
const char *content_type,
|
|
1672
|
+
const uint8_t *body,
|
|
1673
|
+
size_t size);
|
|
1674
|
+
|
|
1675
|
+
/**
|
|
1676
|
+
* Adds a binary file as the body as a MIME multipart with the expected content type and example contents. Will use
|
|
1677
|
+
* a mime type matcher to match the body. Returns an error if the interaction or Pact can't be
|
|
1678
|
+
* modified (i.e. the mock server for it has already started)
|
|
1679
|
+
*
|
|
1680
|
+
* * `interaction` - Interaction handle to set the body for.
|
|
1681
|
+
* * `part` - Request or response part.
|
|
1682
|
+
* * `content_type` - Expected content type of the file.
|
|
1683
|
+
* * `file` - path to the example file
|
|
1684
|
+
* * `part_name` - name for the mime part
|
|
1685
|
+
*/
|
|
1686
|
+
StringResult pactffi_with_multipart_file(InteractionHandle interaction,
|
|
1687
|
+
InteractionPart part,
|
|
1688
|
+
const char *content_type,
|
|
1689
|
+
const char *file,
|
|
1690
|
+
const char *part_name);
|
|
1691
|
+
|
|
1692
|
+
/**
|
|
1693
|
+
* Get an iterator over all the messages of the Pact. The returned iterator needs to be
|
|
1694
|
+
* freed with `pactffi_pact_message_iter_delete`.
|
|
1695
|
+
*
|
|
1696
|
+
* # Safety
|
|
1697
|
+
*
|
|
1698
|
+
* The iterator contains a copy of the Pact, so it is always safe to use.
|
|
1699
|
+
*
|
|
1700
|
+
* # Error Handling
|
|
1701
|
+
*
|
|
1702
|
+
* On failure, this function will return a NULL pointer.
|
|
1703
|
+
*
|
|
1704
|
+
* This function may fail if any of the Rust strings contain embedded
|
|
1705
|
+
* null ('\0') bytes.
|
|
1706
|
+
*/
|
|
1707
|
+
PactMessageIterator *pactffi_pact_handle_get_message_iter(PactHandle pact);
|
|
1708
|
+
|
|
1709
|
+
/**
|
|
1710
|
+
* Get an iterator over all the synchronous request/response messages of the Pact.
|
|
1711
|
+
* The returned iterator needs to be freed with `pactffi_pact_sync_message_iter_delete`.
|
|
1712
|
+
*
|
|
1713
|
+
* # Safety
|
|
1714
|
+
*
|
|
1715
|
+
* The iterator contains a copy of the Pact, so it is always safe to use.
|
|
1716
|
+
*
|
|
1717
|
+
* # Error Handling
|
|
1718
|
+
*
|
|
1719
|
+
* On failure, this function will return a NULL pointer.
|
|
1720
|
+
*
|
|
1721
|
+
* This function may fail if any of the Rust strings contain embedded
|
|
1722
|
+
* null ('\0') bytes.
|
|
1723
|
+
*/
|
|
1724
|
+
PactSyncMessageIterator *pactffi_pact_handle_get_sync_message_iter(PactHandle pact);
|
|
1725
|
+
|
|
1726
|
+
/**
|
|
1727
|
+
* Creates a new Pact Message model and returns a handle to it.
|
|
1728
|
+
*
|
|
1729
|
+
* * `consumer_name` - The name of the consumer for the pact.
|
|
1730
|
+
* * `provider_name` - The name of the provider for the pact.
|
|
1731
|
+
*
|
|
1732
|
+
* Returns a new `MessagePactHandle`. The handle will need to be freed with the `pactffi_free_message_pact_handle`
|
|
1733
|
+
* function to release its resources.
|
|
1734
|
+
*/
|
|
1735
|
+
MessagePactHandle pactffi_new_message_pact(const char *consumer_name,
|
|
1736
|
+
const char *provider_name);
|
|
1737
|
+
|
|
1738
|
+
/**
|
|
1739
|
+
* Creates a new Message and returns a handle to it.
|
|
1740
|
+
*
|
|
1741
|
+
* * `description` - The message description. It needs to be unique for each Message.
|
|
1742
|
+
*
|
|
1743
|
+
* Returns a new `MessageHandle`.
|
|
1744
|
+
*/
|
|
1745
|
+
MessageHandle pactffi_new_message(MessagePactHandle pact, const char *description);
|
|
1746
|
+
|
|
1747
|
+
/**
|
|
1748
|
+
* Sets the description for the Message.
|
|
1749
|
+
*
|
|
1750
|
+
* * `description` - The message description. It needs to be unique for each message.
|
|
1751
|
+
*/
|
|
1752
|
+
void pactffi_message_expects_to_receive(MessageHandle message, const char *description);
|
|
1753
|
+
|
|
1754
|
+
/**
|
|
1755
|
+
* Adds a provider state to the Interaction.
|
|
1756
|
+
*
|
|
1757
|
+
* * `description` - The provider state description. It needs to be unique for each message
|
|
1758
|
+
*/
|
|
1759
|
+
void pactffi_message_given(MessageHandle message, const char *description);
|
|
1760
|
+
|
|
1761
|
+
/**
|
|
1762
|
+
* Adds a provider state to the Message with a parameter key and value.
|
|
1763
|
+
*
|
|
1764
|
+
* * `description` - The provider state description. It needs to be unique.
|
|
1765
|
+
* * `name` - Parameter name.
|
|
1766
|
+
* * `value` - Parameter value.
|
|
1767
|
+
*/
|
|
1768
|
+
void pactffi_message_given_with_param(MessageHandle message,
|
|
1769
|
+
const char *description,
|
|
1770
|
+
const char *name,
|
|
1771
|
+
const char *value);
|
|
1772
|
+
|
|
1773
|
+
/**
|
|
1774
|
+
* Adds the contents of the Message.
|
|
1775
|
+
*
|
|
1776
|
+
* Accepts JSON, binary and other payload types. Binary data will be base64 encoded when serialised.
|
|
1777
|
+
*
|
|
1778
|
+
* Note: For text bodies (plain text, JSON or XML), you can pass in a C string (NULL terminated)
|
|
1779
|
+
* and the size of the body is not required (it will be ignored). For binary bodies, you need to
|
|
1780
|
+
* specify the number of bytes in the body.
|
|
1781
|
+
*
|
|
1782
|
+
* * `content_type` - The content type of the body. Defaults to `text/plain`, supports JSON structures with matchers and binary data.
|
|
1783
|
+
* * `body` - The body contents as bytes. For text payloads (JSON, XML, etc.), a C string can be used and matching rules can be embedded in the body.
|
|
1784
|
+
* * `content_type` - Expected content type (e.g. application/json, application/octet-stream)
|
|
1785
|
+
* * `size` - number of bytes in the message body to read. This is not required for text bodies (JSON, XML, etc.).
|
|
1786
|
+
*/
|
|
1787
|
+
void pactffi_message_with_contents(MessageHandle message_handle,
|
|
1788
|
+
const char *content_type,
|
|
1789
|
+
const uint8_t *body,
|
|
1790
|
+
size_t size);
|
|
1791
|
+
|
|
1792
|
+
/**
|
|
1793
|
+
* Adds expected metadata to the Message
|
|
1794
|
+
*
|
|
1795
|
+
* * `key` - metadata key
|
|
1796
|
+
* * `value` - metadata value.
|
|
1797
|
+
*/
|
|
1798
|
+
void pactffi_message_with_metadata(MessageHandle message_handle,
|
|
1799
|
+
const char *key,
|
|
1800
|
+
const char *value);
|
|
1801
|
+
|
|
1802
|
+
/**
|
|
1803
|
+
* Reifies the given message
|
|
1804
|
+
*
|
|
1805
|
+
* Reification is the process of stripping away any matchers, and returning the original contents.
|
|
1806
|
+
* NOTE: the returned string needs to be deallocated with the `free_string` function
|
|
1807
|
+
*/
|
|
1808
|
+
const char *pactffi_message_reify(MessageHandle message_handle);
|
|
1809
|
+
|
|
1810
|
+
/**
|
|
1811
|
+
* External interface to write out the message pact file. This function should
|
|
1812
|
+
* be called if all the consumer tests have passed. The directory to write the file to is passed
|
|
1813
|
+
* as the second parameter. If a NULL pointer is passed, the current working directory is used.
|
|
1814
|
+
*
|
|
1815
|
+
* If overwrite is true, the file will be overwritten with the contents of the current pact.
|
|
1816
|
+
* Otherwise, it will be merged with any existing pact file.
|
|
1817
|
+
*
|
|
1818
|
+
* Returns 0 if the pact file was successfully written. Returns a positive code if the file can
|
|
1819
|
+
* not be written, or there is no mock server running on that port or the function panics.
|
|
1820
|
+
*
|
|
1821
|
+
* # Errors
|
|
1822
|
+
*
|
|
1823
|
+
* Errors are returned as positive values.
|
|
1824
|
+
*
|
|
1825
|
+
* | Error | Description |
|
|
1826
|
+
* |-------|-------------|
|
|
1827
|
+
* | 1 | The pact file was not able to be written |
|
|
1828
|
+
* | 2 | The message pact for the given handle was not found |
|
|
1829
|
+
*/
|
|
1830
|
+
int32_t pactffi_write_message_pact_file(MessagePactHandle pact,
|
|
1831
|
+
const char *directory,
|
|
1832
|
+
bool overwrite);
|
|
1833
|
+
|
|
1834
|
+
/**
|
|
1835
|
+
* Sets the additional metadata on the Pact file. Common uses are to add the client library details such as the name and version
|
|
1836
|
+
*
|
|
1837
|
+
* * `pact` - Handle to a Pact model
|
|
1838
|
+
* * `namespace` - the top level metadat key to set any key values on
|
|
1839
|
+
* * `name` - the key to set
|
|
1840
|
+
* * `value` - the value to set
|
|
1841
|
+
*/
|
|
1842
|
+
void pactffi_with_message_pact_metadata(MessagePactHandle pact,
|
|
1843
|
+
const char *namespace_,
|
|
1844
|
+
const char *name,
|
|
1845
|
+
const char *value);
|
|
1846
|
+
|
|
1847
|
+
/**
|
|
1848
|
+
* External interface to write out the pact file. This function should
|
|
1849
|
+
* be called if all the consumer tests have passed. The directory to write the file to is passed
|
|
1850
|
+
* as the second parameter. If a NULL pointer is passed, the current working directory is used.
|
|
1851
|
+
*
|
|
1852
|
+
* If overwrite is true, the file will be overwritten with the contents of the current pact.
|
|
1853
|
+
* Otherwise, it will be merged with any existing pact file.
|
|
1854
|
+
*
|
|
1855
|
+
* Returns 0 if the pact file was successfully written. Returns a positive code if the file can
|
|
1856
|
+
* not be written or the function panics.
|
|
1857
|
+
*
|
|
1858
|
+
* # Safety
|
|
1859
|
+
*
|
|
1860
|
+
* The directory parameter must either be NULL or point to a valid NULL terminated string.
|
|
1861
|
+
*
|
|
1862
|
+
* # Errors
|
|
1863
|
+
*
|
|
1864
|
+
* Errors are returned as positive values.
|
|
1865
|
+
*
|
|
1866
|
+
* | Error | Description |
|
|
1867
|
+
* |-------|-------------|
|
|
1868
|
+
* | 1 | The function panicked. |
|
|
1869
|
+
* | 2 | The pact file was not able to be written. |
|
|
1870
|
+
* | 3 | The pact for the given handle was not found. |
|
|
1871
|
+
*/
|
|
1872
|
+
int32_t pactffi_pact_handle_write_file(PactHandle pact, const char *directory, bool overwrite);
|
|
1873
|
+
|
|
1874
|
+
/**
|
|
1875
|
+
* Creates a new V4 asynchronous message and returns a handle to it.
|
|
1876
|
+
*
|
|
1877
|
+
* * `description` - The message description. It needs to be unique for each Message.
|
|
1878
|
+
*
|
|
1879
|
+
* Returns a new `MessageHandle`.
|
|
1880
|
+
*/
|
|
1881
|
+
MessageHandle pactffi_new_async_message(PactHandle pact, const char *description);
|
|
1882
|
+
|
|
1883
|
+
/**
|
|
1884
|
+
* Delete a Pact handle and free the resources used by it.
|
|
1885
|
+
*
|
|
1886
|
+
* # Error Handling
|
|
1887
|
+
*
|
|
1888
|
+
* On failure, this function will return a positive integer value.
|
|
1889
|
+
*
|
|
1890
|
+
* * `1` - The handle is not valid or does not refer to a valid Pact. Could be that it was previously deleted.
|
|
1891
|
+
*
|
|
1892
|
+
*/
|
|
1893
|
+
unsigned int pactffi_free_pact_handle(PactHandle pact);
|
|
1894
|
+
|
|
1895
|
+
/**
|
|
1896
|
+
* Delete a Pact handle and free the resources used by it.
|
|
1897
|
+
*
|
|
1898
|
+
* # Error Handling
|
|
1899
|
+
*
|
|
1900
|
+
* On failure, this function will return a positive integer value.
|
|
1901
|
+
*
|
|
1902
|
+
* * `1` - The handle is not valid or does not refer to a valid Pact. Could be that it was previously deleted.
|
|
1903
|
+
*
|
|
1904
|
+
*/
|
|
1905
|
+
unsigned int pactffi_free_message_pact_handle(MessagePactHandle pact);
|
|
1906
|
+
|
|
1907
|
+
/**
|
|
1908
|
+
* External interface to verifier a provider
|
|
1909
|
+
*
|
|
1910
|
+
* * `args` - the same as the CLI interface, except newline delimited
|
|
1911
|
+
*
|
|
1912
|
+
* # Errors
|
|
1913
|
+
*
|
|
1914
|
+
* Errors are returned as non-zero numeric values.
|
|
1915
|
+
*
|
|
1916
|
+
* | Error | Description |
|
|
1917
|
+
* |-------|-------------|
|
|
1918
|
+
* | 1 | The verification process failed, see output for errors |
|
|
1919
|
+
* | 2 | A null pointer was received |
|
|
1920
|
+
* | 3 | The method panicked |
|
|
1921
|
+
* | 4 | Invalid arguments were provided to the verification process |
|
|
1922
|
+
*
|
|
1923
|
+
* # Safety
|
|
1924
|
+
*
|
|
1925
|
+
* Exported functions are inherently unsafe. Deal.
|
|
1926
|
+
*/
|
|
1927
|
+
int32_t pactffi_verify(const char *args);
|
|
1928
|
+
|
|
1929
|
+
/**
|
|
1930
|
+
* Get a Handle to a newly created verifier. You should call `pactffi_verifier_shutdown` when
|
|
1931
|
+
* done with the verifier to free all allocated resources.
|
|
1932
|
+
*
|
|
1933
|
+
* This function is deprecated. Use `pactffi_verifier_new_for_application` which allows the
|
|
1934
|
+
* calling application/framework name and version to be specified.
|
|
1935
|
+
*
|
|
1936
|
+
* # Safety
|
|
1937
|
+
*
|
|
1938
|
+
* This function is safe.
|
|
1939
|
+
*
|
|
1940
|
+
* # Error Handling
|
|
1941
|
+
*
|
|
1942
|
+
* Returns NULL on error.
|
|
1943
|
+
*/
|
|
1944
|
+
VerifierHandle *pactffi_verifier_new();
|
|
1945
|
+
|
|
1946
|
+
/**
|
|
1947
|
+
* Get a Handle to a newly created verifier. You should call `pactffi_verifier_shutdown` when
|
|
1948
|
+
* done with the verifier to free all allocated resources
|
|
1949
|
+
*
|
|
1950
|
+
* # Safety
|
|
1951
|
+
*
|
|
1952
|
+
* This function is safe.
|
|
1953
|
+
*
|
|
1954
|
+
* # Error Handling
|
|
1955
|
+
*
|
|
1956
|
+
* Returns NULL on error.
|
|
1957
|
+
*/
|
|
1958
|
+
VerifierHandle *pactffi_verifier_new_for_application(const char *name, const char *version);
|
|
1959
|
+
|
|
1960
|
+
/**
|
|
1961
|
+
* Shutdown the verifier and release all resources
|
|
1962
|
+
*/
|
|
1963
|
+
void pactffi_verifier_shutdown(VerifierHandle *handle);
|
|
1964
|
+
|
|
1965
|
+
/**
|
|
1966
|
+
* Set the provider details for the Pact verifier. Passing a NULL for any field will
|
|
1967
|
+
* use the default value for that field.
|
|
1968
|
+
*
|
|
1969
|
+
* # Safety
|
|
1970
|
+
*
|
|
1971
|
+
* All string fields must contain valid UTF-8. Invalid UTF-8
|
|
1972
|
+
* will be replaced with U+FFFD REPLACEMENT CHARACTER.
|
|
1973
|
+
*
|
|
1974
|
+
*/
|
|
1975
|
+
void pactffi_verifier_set_provider_info(VerifierHandle *handle,
|
|
1976
|
+
const char *name,
|
|
1977
|
+
const char *scheme,
|
|
1978
|
+
const char *host,
|
|
1979
|
+
unsigned short port,
|
|
1980
|
+
const char *path);
|
|
1981
|
+
|
|
1982
|
+
/**
|
|
1983
|
+
* Set the filters for the Pact verifier.
|
|
1984
|
+
*
|
|
1985
|
+
* If `filter_description` is not empty, it needs to be as a regular expression.
|
|
1986
|
+
*
|
|
1987
|
+
* `filter_no_state` is a boolean value. Set it to greater than zero to turn the option on.
|
|
1988
|
+
*
|
|
1989
|
+
* # Safety
|
|
1990
|
+
*
|
|
1991
|
+
* All string fields must contain valid UTF-8. Invalid UTF-8
|
|
1992
|
+
* will be replaced with U+FFFD REPLACEMENT CHARACTER.
|
|
1993
|
+
*
|
|
1994
|
+
*/
|
|
1995
|
+
void pactffi_verifier_set_filter_info(VerifierHandle *handle,
|
|
1996
|
+
const char *filter_description,
|
|
1997
|
+
const char *filter_state,
|
|
1998
|
+
unsigned char filter_no_state);
|
|
1999
|
+
|
|
2000
|
+
/**
|
|
2001
|
+
* Set the provider state for the Pact verifier.
|
|
2002
|
+
*
|
|
2003
|
+
* `teardown` is a boolean value. Set it to greater than zero to turn the option on.
|
|
2004
|
+
* `body` is a boolean value. Set it to greater than zero to turn the option on.
|
|
2005
|
+
*
|
|
2006
|
+
* # Safety
|
|
2007
|
+
*
|
|
2008
|
+
* All string fields must contain valid UTF-8. Invalid UTF-8
|
|
2009
|
+
* will be replaced with U+FFFD REPLACEMENT CHARACTER.
|
|
2010
|
+
*
|
|
2011
|
+
*/
|
|
2012
|
+
void pactffi_verifier_set_provider_state(VerifierHandle *handle,
|
|
2013
|
+
const char *url,
|
|
2014
|
+
unsigned char teardown,
|
|
2015
|
+
unsigned char body);
|
|
2016
|
+
|
|
2017
|
+
/**
|
|
2018
|
+
* Set the options used by the verifier when calling the provider
|
|
2019
|
+
*
|
|
2020
|
+
* `disable_ssl_verification` is a boolean value. Set it to greater than zero to turn the option on.
|
|
2021
|
+
*
|
|
2022
|
+
* # Safety
|
|
2023
|
+
*
|
|
2024
|
+
* All string fields must contain valid UTF-8. Invalid UTF-8
|
|
2025
|
+
* will be replaced with U+FFFD REPLACEMENT CHARACTER.
|
|
2026
|
+
*
|
|
2027
|
+
*/
|
|
2028
|
+
int pactffi_verifier_set_verification_options(VerifierHandle *handle,
|
|
2029
|
+
unsigned char disable_ssl_verification,
|
|
2030
|
+
unsigned long request_timeout);
|
|
2031
|
+
|
|
2032
|
+
/**
|
|
2033
|
+
* Set the options used when publishing verification results to the Pact Broker
|
|
2034
|
+
*
|
|
2035
|
+
* # Args
|
|
2036
|
+
*
|
|
2037
|
+
* - `handle` - The pact verifier handle to update
|
|
2038
|
+
* - `provider_version` - Version of the provider to publish
|
|
2039
|
+
* - `build_url` - URL to the build which ran the verification
|
|
2040
|
+
* - `provider_tags` - Collection of tags for the provider
|
|
2041
|
+
* - `provider_tags_len` - Number of provider tags supplied
|
|
2042
|
+
* - `provider_branch` - Name of the branch used for verification
|
|
2043
|
+
*
|
|
2044
|
+
* # Safety
|
|
2045
|
+
*
|
|
2046
|
+
* All string fields must contain valid UTF-8. Invalid UTF-8
|
|
2047
|
+
* will be replaced with U+FFFD REPLACEMENT CHARACTER.
|
|
2048
|
+
*
|
|
2049
|
+
*/
|
|
2050
|
+
int pactffi_verifier_set_publish_options(VerifierHandle *handle,
|
|
2051
|
+
const char *provider_version,
|
|
2052
|
+
const char *build_url,
|
|
2053
|
+
const char *const *provider_tags,
|
|
2054
|
+
unsigned short provider_tags_len,
|
|
2055
|
+
const char *provider_branch);
|
|
2056
|
+
|
|
2057
|
+
/**
|
|
2058
|
+
* Set the consumer filters for the Pact verifier.
|
|
2059
|
+
*
|
|
2060
|
+
* # Safety
|
|
2061
|
+
*
|
|
2062
|
+
* All string fields must contain valid UTF-8. Invalid UTF-8
|
|
2063
|
+
* will be replaced with U+FFFD REPLACEMENT CHARACTER.
|
|
2064
|
+
*
|
|
2065
|
+
*/
|
|
2066
|
+
void pactffi_verifier_set_consumer_filters(VerifierHandle *handle,
|
|
2067
|
+
const char *const *consumer_filters,
|
|
2068
|
+
unsigned short consumer_filters_len);
|
|
2069
|
+
|
|
2070
|
+
/**
|
|
2071
|
+
* Adds a custom header to be added to the requests made to the provider.
|
|
2072
|
+
*
|
|
2073
|
+
* # Safety
|
|
2074
|
+
*
|
|
2075
|
+
* The header name and value must point to a valid NULL terminated string and must contain
|
|
2076
|
+
* valid UTF-8.
|
|
2077
|
+
*/
|
|
2078
|
+
void pactffi_verifier_add_custom_header(VerifierHandle *handle,
|
|
2079
|
+
const char *header_name,
|
|
2080
|
+
const char *header_value);
|
|
2081
|
+
|
|
2082
|
+
/**
|
|
2083
|
+
* Adds a Pact file as a source to verify.
|
|
2084
|
+
*
|
|
2085
|
+
* # Safety
|
|
2086
|
+
*
|
|
2087
|
+
* All string fields must contain valid UTF-8. Invalid UTF-8
|
|
2088
|
+
* will be replaced with U+FFFD REPLACEMENT CHARACTER.
|
|
2089
|
+
*
|
|
2090
|
+
*/
|
|
2091
|
+
void pactffi_verifier_add_file_source(VerifierHandle *handle, const char *file);
|
|
2092
|
+
|
|
2093
|
+
/**
|
|
2094
|
+
* Adds a Pact directory as a source to verify. All pacts from the directory that match the
|
|
2095
|
+
* provider name will be verified.
|
|
2096
|
+
*
|
|
2097
|
+
* # Safety
|
|
2098
|
+
*
|
|
2099
|
+
* All string fields must contain valid UTF-8. Invalid UTF-8
|
|
2100
|
+
* will be replaced with U+FFFD REPLACEMENT CHARACTER.
|
|
2101
|
+
*
|
|
2102
|
+
*/
|
|
2103
|
+
void pactffi_verifier_add_directory_source(VerifierHandle *handle, const char *directory);
|
|
2104
|
+
|
|
2105
|
+
/**
|
|
2106
|
+
* Adds a URL as a source to verify. The Pact file will be fetched from the URL.
|
|
2107
|
+
*
|
|
2108
|
+
* If a username and password is given, then basic authentication will be used when fetching
|
|
2109
|
+
* the pact file. If a token is provided, then bearer token authentication will be used.
|
|
2110
|
+
*
|
|
2111
|
+
* # Safety
|
|
2112
|
+
*
|
|
2113
|
+
* All string fields must contain valid UTF-8. Invalid UTF-8
|
|
2114
|
+
* will be replaced with U+FFFD REPLACEMENT CHARACTER.
|
|
2115
|
+
*
|
|
2116
|
+
*/
|
|
2117
|
+
void pactffi_verifier_url_source(VerifierHandle *handle,
|
|
2118
|
+
const char *url,
|
|
2119
|
+
const char *username,
|
|
2120
|
+
const char *password,
|
|
2121
|
+
const char *token);
|
|
2122
|
+
|
|
2123
|
+
/**
|
|
2124
|
+
* Adds a Pact broker as a source to verify. This will fetch all the pact files from the broker
|
|
2125
|
+
* that match the provider name.
|
|
2126
|
+
*
|
|
2127
|
+
* If a username and password is given, then basic authentication will be used when fetching
|
|
2128
|
+
* the pact file. If a token is provided, then bearer token authentication will be used.
|
|
2129
|
+
*
|
|
2130
|
+
* # Safety
|
|
2131
|
+
*
|
|
2132
|
+
* All string fields must contain valid UTF-8. Invalid UTF-8
|
|
2133
|
+
* will be replaced with U+FFFD REPLACEMENT CHARACTER.
|
|
2134
|
+
*
|
|
2135
|
+
*/
|
|
2136
|
+
void pactffi_verifier_broker_source(VerifierHandle *handle,
|
|
2137
|
+
const char *url,
|
|
2138
|
+
const char *username,
|
|
2139
|
+
const char *password,
|
|
2140
|
+
const char *token);
|
|
2141
|
+
|
|
2142
|
+
/**
|
|
2143
|
+
* Adds a Pact broker as a source to verify. This will fetch all the pact files from the broker
|
|
2144
|
+
* that match the provider name and the consumer version selectors
|
|
2145
|
+
* (See `https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors/`).
|
|
2146
|
+
*
|
|
2147
|
+
* The consumer version selectors must be passed in in JSON format.
|
|
2148
|
+
*
|
|
2149
|
+
* `enable_pending` is a boolean value. Set it to greater than zero to turn the option on.
|
|
2150
|
+
*
|
|
2151
|
+
* If the `include_wip_pacts_since` option is provided, it needs to be a date formatted in
|
|
2152
|
+
* ISO format (YYYY-MM-DD).
|
|
2153
|
+
*
|
|
2154
|
+
* If a username and password is given, then basic authentication will be used when fetching
|
|
2155
|
+
* the pact file. If a token is provided, then bearer token authentication will be used.
|
|
2156
|
+
*
|
|
2157
|
+
* # Safety
|
|
2158
|
+
*
|
|
2159
|
+
* All string fields must contain valid UTF-8. Invalid UTF-8
|
|
2160
|
+
* will be replaced with U+FFFD REPLACEMENT CHARACTER.
|
|
2161
|
+
*
|
|
2162
|
+
*/
|
|
2163
|
+
void pactffi_verifier_broker_source_with_selectors(VerifierHandle *handle,
|
|
2164
|
+
const char *url,
|
|
2165
|
+
const char *username,
|
|
2166
|
+
const char *password,
|
|
2167
|
+
const char *token,
|
|
2168
|
+
unsigned char enable_pending,
|
|
2169
|
+
const char *include_wip_pacts_since,
|
|
2170
|
+
const char *const *provider_tags,
|
|
2171
|
+
unsigned short provider_tags_len,
|
|
2172
|
+
const char *provider_branch,
|
|
2173
|
+
const char *const *consumer_version_selectors,
|
|
2174
|
+
unsigned short consumer_version_selectors_len,
|
|
2175
|
+
const char *const *consumer_version_tags,
|
|
2176
|
+
unsigned short consumer_version_tags_len);
|
|
2177
|
+
|
|
2178
|
+
/**
|
|
2179
|
+
* Runs the verification.
|
|
2180
|
+
*
|
|
2181
|
+
* # Error Handling
|
|
2182
|
+
*
|
|
2183
|
+
* Errors will be reported with a non-zero return value.
|
|
2184
|
+
*/
|
|
2185
|
+
int pactffi_verifier_execute(VerifierHandle *handle);
|
|
2186
|
+
|
|
2187
|
+
/**
|
|
2188
|
+
* External interface to retrieve the options and arguments available when calling the CLI interface,
|
|
2189
|
+
* returning them as a JSON string.
|
|
2190
|
+
*
|
|
2191
|
+
* The purpose is to then be able to use in other languages which wrap the FFI library, to implement
|
|
2192
|
+
* the same CLI functionality automatically without manual maintenance of arguments, help descriptions
|
|
2193
|
+
* etc.
|
|
2194
|
+
*
|
|
2195
|
+
* # Example structure
|
|
2196
|
+
* ```json
|
|
2197
|
+
* {
|
|
2198
|
+
* "options": [
|
|
2199
|
+
* {
|
|
2200
|
+
* "long": "scheme",
|
|
2201
|
+
* "help": "Provider URI scheme (defaults to http)",
|
|
2202
|
+
* "possible_values": [
|
|
2203
|
+
* "http",
|
|
2204
|
+
* "https"
|
|
2205
|
+
* ],
|
|
2206
|
+
* "default_value": "http"
|
|
2207
|
+
* "multiple": false,
|
|
2208
|
+
* },
|
|
2209
|
+
* {
|
|
2210
|
+
* "long": "file",
|
|
2211
|
+
* "short": "f",
|
|
2212
|
+
* "help": "Pact file to verify (can be repeated)",
|
|
2213
|
+
* "multiple": true
|
|
2214
|
+
* },
|
|
2215
|
+
* {
|
|
2216
|
+
* "long": "user",
|
|
2217
|
+
* "help": "Username to use when fetching pacts from URLS",
|
|
2218
|
+
* "multiple": false,
|
|
2219
|
+
* "env": "PACT_BROKER_USERNAME"
|
|
2220
|
+
* }
|
|
2221
|
+
* ],
|
|
2222
|
+
* "flags": [
|
|
2223
|
+
* {
|
|
2224
|
+
* "long": "disable-ssl-verification",
|
|
2225
|
+
* "help": "Disables validation of SSL certificates",
|
|
2226
|
+
* "multiple": false
|
|
2227
|
+
* }
|
|
2228
|
+
* ]
|
|
2229
|
+
* }
|
|
2230
|
+
* ```
|
|
2231
|
+
*
|
|
2232
|
+
* # Safety
|
|
2233
|
+
*
|
|
2234
|
+
* Exported functions are inherently unsafe.
|
|
2235
|
+
*/
|
|
2236
|
+
const char *pactffi_verifier_cli_args();
|
|
2237
|
+
|
|
2238
|
+
/**
|
|
2239
|
+
* Extracts the logs for the verification run. This needs the memory buffer log sink to be
|
|
2240
|
+
* setup before the verification is executed. The returned string will need to be freed with
|
|
2241
|
+
* the `free_string` function call to avoid leaking memory.
|
|
2242
|
+
*
|
|
2243
|
+
* Will return a NULL pointer if the logs for the verification can not be retrieved.
|
|
2244
|
+
*/
|
|
2245
|
+
const char *pactffi_verifier_logs(const VerifierHandle *handle);
|
|
2246
|
+
|
|
2247
|
+
/**
|
|
2248
|
+
* Extracts the logs for the verification run for the provider name. This needs the memory
|
|
2249
|
+
* buffer log sink to be setup before the verification is executed. The returned string will
|
|
2250
|
+
* need to be freed with the `free_string` function call to avoid leaking memory.
|
|
2251
|
+
*
|
|
2252
|
+
* Will return a NULL pointer if the logs for the verification can not be retrieved.
|
|
2253
|
+
*/
|
|
2254
|
+
const char *pactffi_verifier_logs_for_provider(const char *provider_name);
|
|
2255
|
+
|
|
2256
|
+
/**
|
|
2257
|
+
* Extracts the standard output for the verification run. The returned string will need to be
|
|
2258
|
+
* freed with the `free_string` function call to avoid leaking memory.
|
|
2259
|
+
*
|
|
2260
|
+
* * `strip_ansi` - This parameter controls ANSI escape codes. Setting it to a non-zero value
|
|
2261
|
+
* will cause the ANSI control codes to be stripped from the output.
|
|
2262
|
+
*
|
|
2263
|
+
* Will return a NULL pointer if the handle is invalid.
|
|
2264
|
+
*/
|
|
2265
|
+
const char *pactffi_verifier_output(const VerifierHandle *handle, unsigned char strip_ansi);
|
|
2266
|
+
|
|
2267
|
+
/**
|
|
2268
|
+
* Extracts the verification result as a JSON document. The returned string will need to be
|
|
2269
|
+
* freed with the `free_string` function call to avoid leaking memory.
|
|
2270
|
+
*
|
|
2271
|
+
* Will return a NULL pointer if the handle is invalid.
|
|
2272
|
+
*/
|
|
2273
|
+
const char *pactffi_verifier_json(const VerifierHandle *handle);
|
|
2274
|
+
|
|
2275
|
+
/**
|
|
2276
|
+
* Add a plugin to be used by the test. The plugin needs to be installed correctly for this
|
|
2277
|
+
* function to work.
|
|
2278
|
+
*
|
|
2279
|
+
* * `plugin_name` is the name of the plugin to load.
|
|
2280
|
+
* * `plugin_version` is the version of the plugin to load. It is optional, and can be NULL.
|
|
2281
|
+
*
|
|
2282
|
+
* Returns zero on success, and a positive integer value on failure.
|
|
2283
|
+
*
|
|
2284
|
+
* Note that plugins run as separate processes, so will need to be cleaned up afterwards by
|
|
2285
|
+
* calling `pactffi_cleanup_plugins` otherwise you have plugin processes left running.
|
|
2286
|
+
*
|
|
2287
|
+
* # Safety
|
|
2288
|
+
*
|
|
2289
|
+
* `plugin_name` must be a valid pointer to a NULL terminated string. `plugin_version` may be null,
|
|
2290
|
+
* and if not NULL must also be a valid pointer to a NULL terminated string.
|
|
2291
|
+
*
|
|
2292
|
+
* # Errors
|
|
2293
|
+
*
|
|
2294
|
+
* * `1` - A general panic was caught.
|
|
2295
|
+
* * `2` - Failed to load the plugin.
|
|
2296
|
+
* * `3` - Pact Handle is not valid.
|
|
2297
|
+
*
|
|
2298
|
+
* When an error errors, LAST_ERROR will contain the error message.
|
|
2299
|
+
*/
|
|
2300
|
+
unsigned int pactffi_using_plugin(PactHandle pact,
|
|
2301
|
+
const char *plugin_name,
|
|
2302
|
+
const char *plugin_version);
|
|
2303
|
+
|
|
2304
|
+
/**
|
|
2305
|
+
* Decrement the access count on any plugins that are loaded for the Pact. This will shutdown
|
|
2306
|
+
* any plugins that are no longer required (access count is zero).
|
|
2307
|
+
*/
|
|
2308
|
+
void pactffi_cleanup_plugins(PactHandle pact);
|
|
2309
|
+
|
|
2310
|
+
/**
|
|
2311
|
+
* Setup the interaction part using a plugin. The contents is a JSON string that will be passed on to
|
|
2312
|
+
* the plugin to configure the interaction part. Refer to the plugin documentation on the format
|
|
2313
|
+
* of the JSON contents.
|
|
2314
|
+
*
|
|
2315
|
+
* Returns zero on success, and a positive integer value on failure.
|
|
2316
|
+
*
|
|
2317
|
+
* * `interaction` - Handle to the interaction to configure.
|
|
2318
|
+
* * `part` - The part of the interaction to configure (request or response). It is ignored for messages.
|
|
2319
|
+
* * `content_type` - NULL terminated C string of the content type of the part.
|
|
2320
|
+
* * `contents` - NULL terminated C string of the JSON contents that gets passed to the plugin.
|
|
2321
|
+
*
|
|
2322
|
+
* # Safety
|
|
2323
|
+
*
|
|
2324
|
+
* `content_type` and `contents` must be a valid pointers to NULL terminated strings.
|
|
2325
|
+
*
|
|
2326
|
+
* # Errors
|
|
2327
|
+
*
|
|
2328
|
+
* * `1` - A general panic was caught.
|
|
2329
|
+
* * `2` - The mock server has already been started.
|
|
2330
|
+
* * `3` - The interaction handle is invalid.
|
|
2331
|
+
* * `4` - The content type is not valid.
|
|
2332
|
+
* * `5` - The contents JSON is not valid JSON.
|
|
2333
|
+
* * `6` - The plugin returned an error.
|
|
2334
|
+
*
|
|
2335
|
+
* When an error errors, LAST_ERROR will contain the error message.
|
|
2336
|
+
*/
|
|
2337
|
+
unsigned int pactffi_interaction_contents(InteractionHandle interaction,
|
|
2338
|
+
InteractionPart part,
|
|
2339
|
+
const char *content_type,
|
|
2340
|
+
const char *contents);
|
|
2341
|
+
|
|
2342
|
+
} // extern "C"
|
|
2343
|
+
|
|
2344
|
+
#endif // pact_ffi_h
|