Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lcmgh opened this issue Jun 21, 2023 · 4 comments
Closed

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

lcmgh opened this issue Jun 21, 2023 · 4 comments

Comments

@lcmgh
Copy link

lcmgh commented Jun 21, 2023

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
Copy link
Contributor

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
Copy link
Contributor

@lcmgh
Copy link
Author

lcmgh commented Jun 22, 2023

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
Copy link
Member

YOU54F commented Jul 18, 2023

Thanks for updating the docs Ron

@YOU54F YOU54F closed this as completed Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants