pact-foundation / pact-reference

Reference implementations for the pact specifications
https://pact.io
MIT License
91 stars 46 forks source link

rust pact_consumer doc: how to trigger generation of pact files? #294

Closed lcmgh closed 1 year ago

lcmgh commented 1 year ago

Hi!

Refering to https://docs.rs/pact_consumer/latest/pact_consumer/ .

It is not clear to me which fn call actually triggers the generation of pact files.

My test file looks like but I can't see any pac files in target/pacts.

use pact_consumer::json_pattern_internal;
use pact_consumer::{json_pattern, like, prelude::*};
#[tokio::test]
async fn preactivation_req() {
    // Define the Pact for the test, specify the names of the consuming
    // application and the provider application.
    let pact = PactBuilder::new("A", "B")
        // Start a new interaction. We can add as many interactions as we want.
        .interaction("a preactivation request", "", |mut i| {
            // Define the request, a GET (default) request to '/mallory'.
            i.request.path("/abc/v1/abc");
            i.request
                .body(r#"{"abc":["abc"],"hub":"abc"}"#);
            i.request.content_type("application/json");
            // Define the response we want returned. We assume a 200 OK
            // response by default.
            i.response
                .content_type(
                    "
                application/json",
                )
                .json_body(json_pattern!({
                    "status": "CREATED",
                }));
            // Return the interaction builder back to the pact framework
            i
        })
        .build();
}
rholshausen commented 1 year ago

That is not doing anything other then creating a Pact object. You need to start a mock server, write the test code that interacts with it, and if everything is good, the mock server will write the Pact file out afterwards.

rholshausen commented 1 year ago

Refer to https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_consumer/tests/tests.rs#L59 for an example

lcmgh commented 1 year ago

https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_consumer/tests/tests.rs#L59

Thanks. This became only clear to me after trying out the example.

YOU54F commented 1 year ago

Thanks for updating the docs Ron