Implement a Generator
interface
#747
Labels
area:v3
Relating to the pact.v3 module
difficulty:hard
A task requiring a lot of work and an in-depth understanding of the codebase
type:feature
New feature
Summary
Provide a Pythonic interface for creating generators.
Motivation
The Pact specification supports generators for most aspects of an interaction. These generators allow for values to be dynamic which can be particularly useful for values such as unique IDs, or datetimes.
At present, functions such as
with_body
orwith_matching_rules
only take strings or byte arrays which are passed as-is to the underlying FFI. As a result, while generators are technically supported, the end user is responsible for writing out the generators in a JSON string. This is clearly undesirable.Proposed Implementation
General Considerations
The proposed changes would apply to all functions that can support generators, whether it be the body, headers, metadata, etc. The specific might change slightly based on context, but the general idea should remain the same.
There should also be consistency between using
with_body(...)
with a generators, andwith_generators(...)
. That is, a user should be able to straightforward refactor from one to the other. Similarly, adapting a generator fromwith_body
towith_header
should be equally straightforward.Generator Constructor
The specific implementation might depend a bit on what is done for the matching rules in #746, but I would want to follow a similar pattern. That is:
type
,min
,max
,timestamp
,time
,date
, etc.Generator
object.with_body
function and friends.&
operator to allow for logical and. This would allow for the creation of more generators such astype(42) & min(0) & max(100)
for "a random integer between 0 and 100 inclusive".Types
Unlike the matching rules, the types supported by generators is a bit more restricted and needs to be more properly informed by the underlying capabilities of the Rust library.
References
Note
To be filled out.
The text was updated successfully, but these errors were encountered: