wiremock_logical_matchers

Crates.iowiremock_logical_matchers
lib.rswiremock_logical_matchers
version0.6.0
sourcesrc
created_at2023-07-01 07:31:01.13685
updated_at2024-02-21 12:11:31.151965
descriptionLogical matchers for use with wiremock.
homepagehttps://github.com/clechasseur/wiremock_logical_matchers#readme
repositoryhttps://github.com/clechasseur/wiremock_logical_matchers
max_upload_size
id905337
size23,367
Charles Lechasseur (clechasseur)

documentation

https://docs.rs/wiremock_logical_matchers/

README

wiremock_logical_matchers

CI codecov Security audit crates.io downloads docs.rs Contributor Covenant

Additional matchers for wiremock that implement logical operators (AND, OR, XOR, NOT).

Installing

Add wiremock_logical_matchers to your development dependencies:

[dev-dependencies]
wiremock = "0.6.0"
wiremock_logical_matchers = "0.6.0"

or by running:

cargo add wiremock_logical_matchers --dev

Getting started

use wiremock::{Mock, MockServer, ResponseTemplate};
use wiremock::matchers::{header, header_exists, path, query_param};
use wiremock_logical_matchers::{and, not, or, xor};

#[tokio::test]
async fn test_getting_started() {
    let mock_server = MockServer::start().await;

    Mock::given(path("/test"))
        .and(
            and(
                header_exists("x-for-testing-purposes"),
                query_param("page", "1")
            )
        ).and(
            or(
                header("authorization", "Bearer some_token"),
                query_param("override-security", "1")
            )
        ).and(
            xor(
                header("x-license", "MIT"),
                header("x-license-file", "LICENSE")
            )
        ).and(
            not(
                header_exists("x-necronomicon")
            )
        ).respond_with(ResponseTemplate::new(200))
        .mount(&mock_server)
        .await;

    // ...
}

See also

wiremock on crates.io

Commit count: 52

cargo fmt