Pact test DSL for writing consumer pact tests in Rust
This library provides a test DSL for writing consumer pact tests in Rust. It is based on the
V1.1 pact specification.
Online rust docs
To use it
To use it, add it to your dev-dependencies in your cargo manifest and add an extern crate definition for it.
[dev-dependencies]
pact_consumer = "0.1.0"
Then in your main module
#[cfg(test)]
#[macro_use]
extern crate pact_consumer;
You can now write a pact test using the consumer DSL.
use pact_consumer::*;
#[test]
fn a_service_consumer_side_of_a_pact_goes_a_little_something_like_this() {
let pact_runner = ConsumerPactBuilder::consumer(s!("Consumer")) .has_pact_with(s!("Alice Service")) .given("there is some good mallory".to_string()) .upon_receiving("a retrieve Mallory request".to_string()) .path(s!("/mallory")) .will_respond_with() .status(200)
.headers(hashmap!{ s!("Content-Type") => s!("text/html") })
.body(OptionalBody::Present(s!("That is some good Mallory.")))
.build();
let result = pact_runner.run(&|url| {
let client = Client { url: url.clone(), .. Client::default() }; let result = client.fetch("/mallory"); expect!(result).to(be_ok().value("That is some good Mallory."));
Ok(())
});
expect!(result).to(be_equal_to(VerificationResult::PactVerified)); }