summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Anshul Gupta <ansg191@anshulg.com> 2024-03-13 19:18:08 -0700
committerGravatar Anshul Gupta <ansg191@anshulg.com> 2024-03-13 19:34:12 -0700
commit5a8f2b04825ddd8f30acdce989eca68eab12db79 (patch)
tree7dc74b0304e9b842cb13d83bba8294947dac9e26
parent9a1942a475b0f363aecf60b6be5b5c6f56861975 (diff)
downloadtrakt-5a8f2b04825ddd8f30acdce989eca68eab12db79.tar.gz
trakt-5a8f2b04825ddd8f30acdce989eca68eab12db79.tar.zst
trakt-5a8f2b04825ddd8f30acdce989eca68eab12db79.zip
test: switches from reqwest to ureq for tests
`reqwest` does not support `http` 1.0 yet, but `ureq` does. This only effects tests. (cherry picked from commit 73738e6d782d293cc6df50927396464f2c503cc7)
-rw-r--r--trakt-rs/Cargo.toml2
-rw-r--r--trakt-rs/src/test.rs39
2 files changed, 9 insertions, 32 deletions
diff --git a/trakt-rs/Cargo.toml b/trakt-rs/Cargo.toml
index 670cd1c..bda8f1b 100644
--- a/trakt-rs/Cargo.toml
+++ b/trakt-rs/Cargo.toml
@@ -28,4 +28,4 @@ unicode-segmentation = "1"
[dev-dependencies]
httpmock = "0.7"
-reqwest = { version = "0.11", default-features = false, features = ["blocking"] }
+ureq = { version = "2.9", default-features = false, features = ["http-crate"] }
diff --git a/trakt-rs/src/test.rs b/trakt-rs/src/test.rs
index c00a38d..3444499 100644
--- a/trakt-rs/src/test.rs
+++ b/trakt-rs/src/test.rs
@@ -1,14 +1,8 @@
-use std::sync::OnceLock;
-
-use bytes::Bytes;
-use reqwest::blocking::Client;
use trakt_core::{
error::{FromHttpError, IntoHttpError},
Context, Request, Response,
};
-static CLIENT: OnceLock<Client> = OnceLock::new();
-
pub fn assert_request<R, T>(ctx: Context, req: R, exp_url: &str, exp_body: &T)
where
R: Request,
@@ -41,43 +35,26 @@ where
}
pub fn execute<R: Request>(ctx: Context, req: R) -> Result<R::Response, Error> {
- let client = CLIENT.get_or_init(Client::new);
-
let request: http::Request<Vec<u8>> = req.try_into_http_request(ctx)?;
+ let (parts, body) = request.into_parts();
+ let request = ureq::Request::from(parts);
- let reqwest_res = client.execute(request.try_into()?)?;
- let http_res = reqwest_to_http(reqwest_res)?;
+ let response = request.send_bytes(&body)?;
+ let http_res: http::Response<Vec<u8>> = http::Response::from(response);
Ok(Response::try_from_http_response(http_res)?)
}
-fn reqwest_to_http(
- mut response: reqwest::blocking::Response,
-) -> Result<http::Response<Bytes>, Error> {
- let mut builder = http::Response::builder()
- .status(response.status())
- .version(response.version());
-
- std::mem::swap(
- builder.headers_mut().expect("response should be valid"),
- response.headers_mut(),
- );
-
- Ok(builder
- .body(response.bytes()?)
- .expect("response should be valid"))
-}
-
#[derive(Debug)]
pub enum Error {
- Reqwest(reqwest::Error),
+ Reqwest(Box<ureq::Error>),
IntoHttp(IntoHttpError),
FromHttp(FromHttpError),
}
-impl From<reqwest::Error> for Error {
- fn from(e: reqwest::Error) -> Self {
- Self::Reqwest(e)
+impl From<ureq::Error> for Error {
+ fn from(e: ureq::Error) -> Self {
+ Self::Reqwest(Box::new(e))
}
}