Mike Geeves
06/29/2022, 10:32 AMMike Geeves
06/29/2022, 11:01 AMMatt (pactflow.io / pact-js / pact-go)
Mike Geeves
06/29/2022, 2:01 PMMike Geeves
06/29/2022, 2:02 PMMike Geeves
06/29/2022, 2:04 PMMike Geeves
06/29/2022, 2:10 PMMike Geeves
06/29/2022, 2:21 PMconst opts = {
...baseOpts,
...(process.env.PACT_URL ? pactChangedOpts : fetchPactsDynamicallyOpts),
messageProviders: {
"a product event update": () =>
createEvent(new Product("42", "food", "pizza"), "UPDATED"),
},
};
const p = new MessageProviderPact(opts);
Mike Geeves
06/29/2022, 2:29 PMMike Geeves
06/29/2022, 2:29 PMmake test
is failing for me on that example so I can't actually see how that one is expected to behave š¤Mike Geeves
06/29/2022, 2:34 PMMatt (pactflow.io / pact-js / pact-go)
Order
updated use case, which has these scenarios:
1. Order has new shipping information
2. Order has a new delivery note
3. ā¦
You could write the consumer tests for these in two ways:
1. The use case + scenario is all in a single description:
āAn order is updated with new shipping informationā
āAn order is updated with a new delivery noteā
āAn order is updated with ā¦ā
2. The use case + scenario is separated by different provider states
use case: āAn order update eventā
scenario 1: āwith new shipping informationā
scenario 2: āwith a new delivery noteā
scenario 3: āā¦ā
I think 2 is more readable, but does rely on the state handlers instead of a single function that handles the whole thingMatt (pactflow.io / pact-js / pact-go)
-> in which case the provider-states-setup-url is no longer relevant and python shouldnāt be WARNāing that itās missingI agree that we should not have this warning though if there are no states to be setup. Itās not a useful warning - that could be fixed in the Ruby core I think (i.e. donāt warn if there are no states and that URL is not set)
Matt (pactflow.io / pact-js / pact-go)
Beth (pactflow.io/Pact Broker/pact-ruby)
Beth (pactflow.io/Pact Broker/pact-ruby)
Mike Geeves
06/30/2022, 2:02 AMset_up_provider_state.rb
/ set_up_provider_state_spec.rb
I'll see if I can find other language examples to see what they do, in case it's a non-issue down to the way the python implementation sets things up
The use case + scenario is separated by different provider statesDo you know of any other examples demonstrating that approach for message? Don't worry about looking if not, (I'll have a look through in the morning) I haven't been able to see so far how that's intended to hook in š¤ Only approach 1 with the single description as it's basically a map of description to handler
Matt (pactflow.io / pact-js / pact-go)
Mike Geeves
06/30/2022, 2:04 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Mike Geeves
06/30/2022, 2:06 AM(
pact.given("A document deleted successfully")
.expects_to_receive("Description with broker")
.with_content(expected_event)
.with_metadata({"Content-Type": "application/json"})
)
provider side has something like
def test_verify_success():
provider = MessageProvider(
message_providers={
"A document created successfully": document_created_handler,
"A document deleted successfully": document_deleted_handler,
},
provider="ContentProvider",
consumer="DetectContentLambda",
pact_dir="pacts",
)
with provider:
provider.verify()
Mike Geeves
06/30/2022, 2:07 AMMike Geeves
06/30/2022, 2:08 AMdef _setup_states(self):
message_handlers = {}
for key, handler in self.message_providers.items():
message_handlers[f'{key}'] = handler()
resp = <http://requests.post|requests.post>(f'{self._proxy_url()}/setup',
verify=False,
json={"messageHandlers": message_handlers})
assert resp.status_code == 201, resp.text
return message_handlers
so calling that handler, and passing whatever it generates as a key -> payloadMatt (pactflow.io / pact-js / pact-go)
(
pact.given("A document deleted successfully") <--------- this is the state
.expects_to_receive("Description with broker") <--------- this is the actual scenario, that should map to a handler
.with_content(expected_event)
.with_metadata({"Content-Type": "application/json"})
)
Matt (pactflow.io / pact-js / pact-go)
def test_verify_success():
provider = MessageProvider(
message_providers={
"A document created successfully": document_created_handler, <--- scenario handler, not a state
"A document deleted successfully": document_deleted_handler,
},
state_handlers={
"A document deleted successfully": some_func, <---- in an ideal world, we want something like this
},
provider="ContentProvider",
consumer="DetectContentLambda",
pact_dir="pacts",
)
with provider:
provider.verify()
Mike Geeves
06/30/2022, 2:14 AMMatt (pactflow.io / pact-js / pact-go)
Mike Geeves
06/30/2022, 2:18 AMMike Geeves
06/30/2022, 2:18 AMMike Geeves
06/30/2022, 2:18 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Mike Geeves
06/30/2022, 2:20 AMMike Geeves
06/30/2022, 2:20 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Mike Geeves
06/30/2022, 2:21 AMMike Geeves
06/30/2022, 2:21 AMMike Geeves
06/30/2022, 2:22 AMMike Geeves
06/30/2022, 2:22 AMMatt (pactflow.io / pact-js / pact-go)
Iāve been doing the usual going in circles a bit looking at trying to improve some of the examples and hitting the...but...different examples...things not working...head hurtPython or beyond?
Mike Geeves
06/30/2022, 2:24 AMMike Geeves
06/30/2022, 2:25 AMMike Geeves
06/30/2022, 2:28 AMMike Geeves
06/30/2022, 2:29 AMMike Geeves
06/30/2022, 2:29 AMYousaf Nabi (pactflow.io)
Mike Geeves
07/01/2022, 10:46 AMMike Geeves
07/01/2022, 10:47 AMMike Geeves
07/01/2022, 10:48 AMYousaf Nabi (pactflow.io)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Mike Geeves
07/01/2022, 10:57 AMMike Geeves
07/01/2022, 10:57 AMMike Geeves
07/01/2022, 10:58 AMMike Geeves
07/01/2022, 10:59 AMMatt (pactflow.io / pact-js / pact-go)
Injecting values from provider state callbacks
itās only useful for the basic/obvious features.Matt (pactflow.io / pact-js / pact-go)
Mike Geeves
07/01/2022, 11:07 AMMike Geeves
07/01/2022, 11:08 AMMike Geeves
07/01/2022, 11:09 AMMike Geeves
07/02/2022, 10:04 AM