tests(net): add explicit tests for assert_no_unused_plans
All checks were successful
Test / build (map[name:stable]) (push) Successful in 8m14s
Test / build (map[name:nightly]) (push) Successful in 8m23s
Release Please / Release-plz (push) Successful in 1m23s

This commit is contained in:
Paul Campbell 2024-12-29 21:51:46 +00:00
parent 2f646c4131
commit a91dcb3a4a
2 changed files with 48 additions and 0 deletions

View file

@ -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");

View file

@ -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