Javier Jimenez Roda
05/22/2024, 8:28 AMJavier Jimenez Roda
05/22/2024, 8:30 AMYousaf Nabi (pactflow.io)
Javier Jimenez Roda
05/22/2024, 11:11 AMYousaf Nabi (pactflow.io)
BrokerWithDynamicConfiguration
https://github.com/pact-foundation/pact-reference/blob/260a91d55ad2829d4362e8f28db4d4d5b6d0844d/rust/pact_verifier/tests/tests.rs#L494Yousaf Nabi (pactflow.io)
Loading pacts options:
-f, --file <file>
Pact file to verify (can be repeated)
-d, --dir <dir>
Directory of pact files to verify (can be repeated)
-u, --url <url>
URL of pact file to verify (can be repeated)
-b, --broker-url <broker-url>
URL of the pact broker to fetch pacts from to verify (requires the provider name parameter) [env: PACT_BROKER_BASE_URL=]
--webhook-callback-url <webhook-callback-url>
URL of a Pact to verify via a webhook callback. Requires the broker-url to be set. [env: PACT_WEBHOOK_CALLBACK_URL=]
--ignore-no-pacts-error
Do not fail if no pacts are found to verify
Pact Broker options:
--consumer-version-tags <consumer-version-tags>
Consumer tags to use when fetching pacts from the Broker. Accepts comma-separated values.
--consumer-version-selectors <consumer-version-selectors>
Consumer version selectors to use when fetching pacts from the Broker. Accepts a JSON string as per <https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors/>. Can be repeated.
--enable-pending
Enables Pending Pacts
--include-wip-pacts-since <include-wip-pacts-since>
Allow pacts that don't match given consumer selectors (or tags) to be verified, without causing the overall task to fail. For more information, see <https://pact.io/wip>
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Javier Jimenez Roda
05/22/2024, 11:56 AMMatt (pactflow.io / pact-js / pact-go)
Javier Jimenez Roda
05/22/2024, 11:56 AMMatt (pactflow.io / pact-js / pact-go)
Javier Jimenez Roda
05/22/2024, 11:57 AMYousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
But then do I have to create an HTTP server or can I just use the Rust testing framework as I did with the consumer pact tests?I believe so, for message tests. I would be a good feature enhancement for rust users, using the crate directly rather than the cli
Matt (pactflow.io / pact-js / pact-go)
I believe this endpoint is the one triggered by the pact-broker based on a signal send via webhook to it?I think this is a common misconception. The Pact Broker is really just the place the contracts are collaborated/exchanged - the SDKs are what actually do the testing bits. So in this case, the process is basically: 1. Create an API that can respond to POST calls, taking in the message payload (
{"description": "..", "providerStates": […]}
) , and returns the event/message details
2. Call the verifier SDK, passing in the details to the broker and how to communicate to the provider (in step 1)
3. The verifier speaks to the Pact Broker to discover the contracts (pacts) to validate
4. For each interaction in each pact file, the verifier calls your API and looks at the emitted events in the outputJavier Jimenez Roda
05/22/2024, 4:14 PM#[test_log::test(tokio::test)]
async fn when_instrument_state_switched_to_starting_up_then_example_unit_starts_up_itself() {
// Arrange
let provider = PactBuilder::new_v4("instrument-state-unit", "example-unit")
.interaction("Instrument State changes to Starting Up and triggers units to startup", "", |mut i| {
i.test_name("test_unit_reacts_to_instrument_state_starting_up");
i.request.content_type("application/json");
i.request.json_body(json_pattern!({
"origin": like!("simulated-instrument-sn555"),
"version": like!("1.0.0"),
"name": like!("InstrumentStateChanged"),
"old_state": like!("PoweredOff"),
"new_state": like!("StartingUp")
}));
i.response.ok().content_type("application/json").json_body(json_pattern!({
"result": "hello"
}));
i
}).start_mock_server(None);
let provider_info = ProviderInfo {
name: "example-unit".to_string(),
host: provider.url().host_str().unwrap().to_string(),
transports: vec![ ProviderTransport {
transport: "HTTP".to_string(),
port: provider.url().port(),
path: None,
scheme: Some("http".to_string())
} ],
.. ProviderInfo::default()
};
// Create the pact source to pull pacts from the pact-broker
let pact_source = PactSource::BrokerUrl("example-unit".to_string(), "<http://localhost:9292>".to_string(), None, vec![]);
// Arrange
let verification_options: VerificationOptions<NullRequestFilterExecutor> = VerificationOptions::default();
let provider_state_executor = Arc::new(DummyProviderStateExecutor{});
let publish_options = PublishOptions {
provider_version: Some("1.0.0".to_string()),
build_url: None,
provider_tags: vec![],
provider_branch: None,
};
let result = verify_provider_async(
provider_info,
vec![ pact_source ],
FilterInfo::None,
vec![ "instrument-state-unit".to_string() ],
&verification_options,
Some(&publish_options),
&provider_state_executor,
None
).await;
// Assert
expect!(result.unwrap().result).to(be_true());
}
The results of it is:
Failures:
1) Verifying a pact between instrument-state-unit and example-unit Given Unit is powered off And Hardware units works normally - Instrument State changes to Starting Up and triggers units to startup - error sending request for url (http://127.0.0.1:8080/)
2) Verifying a pact between instrument-state-unit and example-unit - Unit State Changed to StartingUp - error sending request for url (http://127.0.0.1:8080/)
3) Verifying a pact between instrument-state-unit and example-unit Given Unit is powered off And Hardware units works normally - Unit State Changed to StartingUp - error sending request for url (http://127.0.0.1:8080/)
There were 3 pact failuresSo I could: 1. create a rust test that pulls the consumer pacts from a running pact-broker 2. Creates a MockServer (which seems to be now the source of the problem) 3. Provide dummy state data The issue is that the error message is quite unspecific. Any idea what could be the issue?
Javier Jimenez Roda
05/22/2024, 4:15 PMJavier Jimenez Roda
05/23/2024, 12:01 AMJavier Jimenez Roda
05/23/2024, 12:02 AMYousaf Nabi (pactflow.io)