diff --git a/examples/get.rs b/examples/get.rs index 530f19b..2ae10bc 100644 --- a/examples/get.rs +++ b/examples/get.rs @@ -151,6 +151,8 @@ mod tests { assert_eq!(contents, "contents"); + net.assert_no_unused_plans(); + // not needed for this test, but should it be needed, we can avoid checking for any // unconsumed request matches. // let mock_net = kxio::net::MockNet::try_from(net).expect("recover mock"); diff --git a/tests/net.rs b/tests/net.rs index 50ee27c..71ce0c0 100644 --- a/tests/net.rs +++ b/tests/net.rs @@ -53,6 +53,52 @@ async fn test_get_url() { assert_eq!(response.bytes().await.expect("response body"), "Get OK"); } +#[tokio::test] +async fn test_when_all_plans_match_assert_is_ok() { + //given + let mock_net = kxio::net::mock(); + + let url = "https://www.example.com"; + + mock_net + .on() + .get(url) + .respond(StatusCode::OK) + .body("Get OK") + .expect("mock"); + let net = Net::from(mock_net); + + //when + let _response = net.get(url).send().await.expect("response"); + + //then + net.assert_no_unused_plans(); +} + +#[tokio::test] +#[should_panic] +async fn test_when_not_all_plans_match_assert_fails() { + //given + let mock_net = kxio::net::mock(); + + let url = "https://www.example.com"; + + mock_net + .on() + .get(url) + .respond(StatusCode::OK) + .body("Get OK") + .expect("mock"); + let net = Net::from(mock_net); + + //when + // request is not made + // let _response = net.get(url).send().await.expect("response"); + + //then + net.assert_no_unused_plans(); +} + #[tokio::test] async fn test_post_url() { //given