Hi, pact-js has `url2` method, which allow to use...
# pact-rust
t
Hi, pact-js has
url2
method, which allow to use the generator
MockServerURL
to generate url with the mock server as the base URL. It work as expected. But stub server (rust version - https://github.com/pact-foundation/pact-stub-server) doesn't support that generator. Is it expected? Here is the demo code https://github.com/tienvx/test-mock-server-url-generator
🤔 1
m
interesting. Maybe it just needs an internal version bump and new release?
ah, actually was released 2 weeks ago, so you’d imagine it would be there given that method was added ages ago.
mind raising an issue on that repo?
t
Will do. But first I need to understand this is a bug or not (from my side). I think documents about matchers and generators are not quite clear to me (I even think there are no document for generators? There are some here https://github.com/pact-foundation/pact-specification/tree/version-4#generators but it doesn't tell where or when they are used) so I make a summary on this: According to this page https://docs.pact.io/implementation_guides/rust/pact_ffi/integrationjson, there are 3 attributes to worry about: • Matcher (type, and its configuration) • Generator (type, and its configuration) • Example value There are 3 entities (that I think) use those attributes: • Consumer's contract test (use mock server) • Consumer's integration test (use stub server) • Provider (called by provider verifier) I assume: • Mock server --- (provide) -----> Example value ----- (to) ------> Consumer's contract test • Stub server --- (provide) -----> Example value ----- (to) ------> Consumer's integration test • Provider verifier --- (use) -----> Matcher ------ (to verify with) -----> Provider • I assume, if there is generator specified (except
ProviderState
and
MockServerURL
): Mock server --- (use) ---> Generator --- (to generate random data, then send to) ---> Consumer's contract test • If generator is
ProviderState
: Provider verifier --- (grab value from) ---> Provider state handler --- (then send it to) ----> Provider • If generator is
MockServerURL
: Mock server --- (replace base url from) ---> Example value ----- (then send it to) -----------> Consumer's contract test I'm assuming that stub server (rust version) doesn't care about generators at all? I'm not sure, I didn't use generators other than
ProviderState
and
MockServerURL
. I think the behavior should be: • Stub server --- (provide) -----> Example value ----- (to) ------> Consumer's integration test • if there is generator specified (except
ProviderState
and
MockServerURL
): Stub server --- (use) ---> Generator --- (to generate random data, then send to) ---> Consumer's integration test • If generator is
MockServerURL
: Stub server --- (replace base url from) ---> Example value ----- (then send it to) -----------> Consumer's integration test If all of my assumptions are correct, I will create 2 tickets for the last 2 items: • Stub server should use generators if specified • Stub server should replace base url if generator
MockServerURL
is specified
I tested the generator
RandomInt
and both Mock Server and Stub Server use this generator. So I think that Stub Server doesn't replace url if generator
MockServerURL
is specified is a bug to me. I will create the ticket
I think we should document these flows (in sequence diagram?)
I did my best to create sequence diagram from what I understand + expect https://www.plantuml.com/plantuml/uml/SoWkIImgAStDuNBCoKnELT2rKt3AJx9IS2mjoKZDAybCJYp[…]oYde0jM05MDHLLoGdrUSoeLkM5u-K5sHGY9sGo6ARNHr2QY66kwGcfS2SZ00 I hope it isn't wrong somewhere
I tested with
Copy code
{
        'pact:generator:type': 'RandomInt',
        'pact:matcher:type': 'integer',
        // value: 101, <--------------- I can't remove this, it's still needed for stub server, not sure why
    }
So either my diagram is wrong (about example value on stub server), or stub server has another 'bug' here
m
Thanks Tien - I think this is all really helpful. We should include this in the maintainer guide we’re about to pick up, what do you think @uglyog?
u
the maintainer guide sounds like a holy grail that is going to solve all our problems
😆 1
m
Well, i’m hoping it can capture some of these tricky ones that seem to trip us up