Struct wiremock::matchers::BodyExactMatcher [−][src]
pub struct BodyExactMatcher(_);
Expand description
Match exactly the body of a request.
Example (string):
use wiremock::{MockServer, Mock, ResponseTemplate}; use wiremock::matchers::body_string; #[async_std::main] async fn main() { // Arrange let mock_server = MockServer::start().await; Mock::given(body_string("hello world!")) .respond_with(ResponseTemplate::new(200)) .mount(&mock_server) .await; // Act let status = surf::post(&mock_server.uri()) .body("hello world!") .await .unwrap() .status(); // Assert assert_eq!(status, 200); }
Example (json):
use wiremock::{MockServer, Mock, ResponseTemplate}; use wiremock::matchers::body_json; use serde_json::json; #[async_std::main] async fn main() { // Arrange let mock_server = MockServer::start().await; let expected_body = json!({ "hello": "world!" }); Mock::given(body_json(&expected_body)) .respond_with(ResponseTemplate::new(200)) .mount(&mock_server) .await; // Act let status = surf::post(&mock_server.uri()) .body(expected_body) .await .unwrap() .status(); // Assert assert_eq!(status, 200); }
Implementations
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for BodyExactMatcher
impl Send for BodyExactMatcher
impl Sync for BodyExactMatcher
impl Unpin for BodyExactMatcher
impl UnwindSafe for BodyExactMatcher