tests(net): add explicit tests for assert_no_unused_plans
This commit is contained in:
parent
2f646c4131
commit
a91dcb3a4a
2 changed files with 48 additions and 0 deletions
|
@ -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");
|
||||
|
|
46
tests/net.rs
46
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
|
||||
|
|
Loading…
Reference in a new issue