kxio/tests/net.rs

37 lines
787 B
Rust
Raw Normal View History

2024-11-04 10:22:31 +00:00
//
use kxio::net::Error;
type TestResult = Result<(), Error>;
mod get {
use kxio::net::Net;
use super::*;
#[tokio::test]
async fn test() -> TestResult {
let mut net_mock = kxio::net::mock();
let url = "https://www.example.com";
let request = net_mock.client().get(url);
let my_response = net_mock.response().status(200).body("OK").unwrap();
net_mock.on(request).response(my_response.clone().into());
let net = net_mock.as_net();
let client = Net::client();
let response = net.send(client.get(url)).await?;
assert_eq!(response.status(), my_response.status());
net_mock.assert()?;
// let my_net = net::new();
// my_net.send(request).await?;
Ok(())
}
}