50 lines
1.2 KiB
Rust
50 lines
1.2 KiB
Rust
//
|
|
use kxio::net::Error;
|
|
|
|
type TestResult = Result<(), Error>;
|
|
|
|
#[tokio::test]
|
|
async fn test_get() -> TestResult {
|
|
let mut net = kxio::net::mock();
|
|
let client = net.client();
|
|
|
|
let url = "https://www.example.com";
|
|
let request = client.get(url).build().expect("build request");
|
|
let my_response = net
|
|
.response()
|
|
.status(200)
|
|
.body("Get OK")
|
|
.expect("request body");
|
|
|
|
net.on(request).response(my_response.into());
|
|
|
|
let response = net.send(client.get(url)).await?;
|
|
|
|
assert_eq!(response.status(), http::StatusCode::OK);
|
|
assert_eq!(response.bytes().await.expect("response body"), "Get OK");
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_post() -> TestResult {
|
|
let mut net = kxio::net::mock();
|
|
let client = net.client();
|
|
|
|
let url = "https://www.example.com";
|
|
let request = client.post(url).build().expect("build request");
|
|
let my_response = net
|
|
.response()
|
|
.status(200)
|
|
.body("Post OK")
|
|
.expect("request body");
|
|
|
|
net.on(request).response(my_response.into());
|
|
|
|
let response = net.send(client.post(url)).await?;
|
|
|
|
assert_eq!(response.status(), http::StatusCode::OK);
|
|
assert_eq!(response.bytes().await.expect("response body"), "Post OK");
|
|
|
|
Ok(())
|
|
}
|