aboutsummaryrefslogtreecommitdiff
path: root/src/garage/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/garage/tests')
-rw-r--r--src/garage/tests/common/custom_requester.rs34
-rw-r--r--src/garage/tests/k2v/batch.rs3
-rw-r--r--src/garage/tests/k2v/item.rs3
-rw-r--r--src/garage/tests/k2v/poll.rs3
-rw-r--r--src/garage/tests/k2v/simple.rs3
-rw-r--r--src/garage/tests/lib.rs9
-rw-r--r--src/garage/tests/s3/website.rs47
7 files changed, 67 insertions, 35 deletions
diff --git a/src/garage/tests/common/custom_requester.rs b/src/garage/tests/common/custom_requester.rs
index 4133bb8b..72fb1a46 100644
--- a/src/garage/tests/common/custom_requester.rs
+++ b/src/garage/tests/common/custom_requester.rs
@@ -5,12 +5,17 @@ use std::convert::TryFrom;
use chrono::{offset::Utc, DateTime};
use hmac::{Hmac, Mac};
-use hyper::client::HttpConnector;
-use hyper::{Body, Client, Method, Request, Response, Uri};
+use http_body_util::BodyExt;
+use http_body_util::Full as FullBody;
+use hyper::{Method, Request, Response, Uri};
+use hyper_util::client::legacy::{connect::HttpConnector, Client};
+use hyper_util::rt::TokioExecutor;
use super::garage::{Instance, Key};
use garage_api::signature;
+pub type Body = FullBody<hyper::body::Bytes>;
+
/// You should ever only use this to send requests AWS sdk won't send,
/// like to reproduce behavior of unusual implementations found to be
/// problematic.
@@ -19,7 +24,7 @@ pub struct CustomRequester {
key: Key,
uri: Uri,
service: &'static str,
- client: Client<HttpConnector>,
+ client: Client<HttpConnector, Body>,
}
impl CustomRequester {
@@ -28,7 +33,7 @@ impl CustomRequester {
key: key.clone(),
uri: instance.s3_uri(),
service: "s3",
- client: Client::new(),
+ client: Client::builder(TokioExecutor::new()).build_http(),
}
}
@@ -37,7 +42,7 @@ impl CustomRequester {
key: key.clone(),
uri: instance.k2v_uri(),
service: "k2v",
- client: Client::new(),
+ client: Client::builder(TokioExecutor::new()).build_http(),
}
}
@@ -139,7 +144,7 @@ impl<'a> RequestBuilder<'a> {
self
}
- pub async fn send(&mut self) -> hyper::Result<Response<Body>> {
+ pub async fn send(&mut self) -> Result<Response<Body>, String> {
// TODO this is a bit incorrect in that path and query params should be url-encoded and
// aren't, but this is good enought for now.
@@ -242,7 +247,22 @@ impl<'a> RequestBuilder<'a> {
.method(self.method.clone())
.body(Body::from(body))
.unwrap();
- self.requester.client.request(request).await
+
+ let result = self
+ .requester
+ .client
+ .request(request)
+ .await
+ .map_err(|err| format!("hyper client error: {}", err))?;
+
+ let (head, body) = result.into_parts();
+ let body = Body::new(
+ body.collect()
+ .await
+ .map_err(|err| format!("hyper client error in body.collect: {}", err))?
+ .to_bytes(),
+ );
+ Ok(Response::from_parts(head, body))
}
}
diff --git a/src/garage/tests/k2v/batch.rs b/src/garage/tests/k2v/batch.rs
index 417fe7ea..39554d4d 100644
--- a/src/garage/tests/k2v/batch.rs
+++ b/src/garage/tests/k2v/batch.rs
@@ -7,7 +7,8 @@ use base64::prelude::*;
use serde_json::json;
use crate::json_body;
-use hyper::{body::HttpBody, Method, StatusCode};
+use http_body_util::BodyExt;
+use hyper::{Method, StatusCode};
#[tokio::test]
async fn test_batch() {
diff --git a/src/garage/tests/k2v/item.rs b/src/garage/tests/k2v/item.rs
index 6b653088..5a347bd9 100644
--- a/src/garage/tests/k2v/item.rs
+++ b/src/garage/tests/k2v/item.rs
@@ -7,7 +7,8 @@ use base64::prelude::*;
use serde_json::json;
use crate::json_body;
-use hyper::{body::HttpBody, Method, StatusCode};
+use http_body_util::BodyExt;
+use hyper::{Method, StatusCode};
#[tokio::test]
async fn test_items_and_indices() {
diff --git a/src/garage/tests/k2v/poll.rs b/src/garage/tests/k2v/poll.rs
index b75fa9c7..277f8bc8 100644
--- a/src/garage/tests/k2v/poll.rs
+++ b/src/garage/tests/k2v/poll.rs
@@ -1,5 +1,6 @@
use base64::prelude::*;
-use hyper::{body::HttpBody, Method, StatusCode};
+use http_body_util::BodyExt;
+use hyper::{Method, StatusCode};
use std::time::Duration;
use assert_json_diff::assert_json_eq;
diff --git a/src/garage/tests/k2v/simple.rs b/src/garage/tests/k2v/simple.rs
index a1d5008b..1017330d 100644
--- a/src/garage/tests/k2v/simple.rs
+++ b/src/garage/tests/k2v/simple.rs
@@ -1,6 +1,7 @@
use crate::common;
-use hyper::{body::HttpBody, Method, StatusCode};
+use http_body_util::BodyExt;
+use hyper::{Method, StatusCode};
#[tokio::test]
async fn test_simple() {
diff --git a/src/garage/tests/lib.rs b/src/garage/tests/lib.rs
index 3cb17a2b..ef370db3 100644
--- a/src/garage/tests/lib.rs
+++ b/src/garage/tests/lib.rs
@@ -11,9 +11,14 @@ mod k2v;
#[cfg(feature = "k2v")]
mod k2v_client;
-use hyper::{body::HttpBody, Body, Response};
+use http_body_util::BodyExt;
+use hyper::{body::Body, Response};
-pub async fn json_body(res: Response<Body>) -> serde_json::Value {
+pub async fn json_body<B>(res: Response<B>) -> serde_json::Value
+where
+ B: Body,
+ <B as Body>::Error: std::fmt::Debug,
+{
let body = res.into_body().collect().await.unwrap().to_bytes();
let res_body: serde_json::Value = serde_json::from_slice(&body).unwrap();
res_body
diff --git a/src/garage/tests/s3/website.rs b/src/garage/tests/s3/website.rs
index 94acafc7..19f53fcd 100644
--- a/src/garage/tests/s3/website.rs
+++ b/src/garage/tests/s3/website.rs
@@ -8,15 +8,18 @@ use aws_sdk_s3::{
types::{CorsConfiguration, CorsRule, ErrorDocument, IndexDocument, WebsiteConfiguration},
};
use http::{Request, StatusCode};
-use hyper::{
- body::{Body, HttpBody},
- Client,
-};
+use http_body_util::BodyExt;
+use http_body_util::Full as FullBody;
+use hyper::body::Bytes;
+use hyper_util::client::legacy::Client;
+use hyper_util::rt::TokioExecutor;
use serde_json::json;
const BODY: &[u8; 16] = b"<h1>bonjour</h1>";
const BODY_ERR: &[u8; 6] = b"erreur";
+pub type Body = FullBody<Bytes>;
+
#[tokio::test]
async fn test_website() {
const BCKT_NAME: &str = "my-website";
@@ -34,14 +37,14 @@ async fn test_website() {
.await
.unwrap();
- let client = Client::new();
+ let client = Client::builder(TokioExecutor::new()).build_http();
let req = || {
Request::builder()
.method("GET")
.uri(format!("http://127.0.0.1:{}/", ctx.garage.web_port))
.header("Host", format!("{}.web.garage", BCKT_NAME))
- .body(Body::empty())
+ .body(Body::new(Bytes::new()))
.unwrap()
};
@@ -49,7 +52,7 @@ async fn test_website() {
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
assert_ne!(
- resp.into_body().collect().await.unwrap().to_bytes(),
+ BodyExt::collect(resp.into_body()).await.unwrap().to_bytes(),
BODY.as_ref()
); /* check that we do not leak body */
@@ -61,7 +64,7 @@ async fn test_website() {
ctx.garage.admin_port,
BCKT_NAME.to_string()
))
- .body(Body::empty())
+ .body(Body::new(Bytes::new()))
.unwrap()
};
@@ -103,7 +106,7 @@ async fn test_website() {
"http://127.0.0.1:{0}/check?domain={1}",
ctx.garage.admin_port, bname
))
- .body(Body::empty())
+ .body(Body::new(Bytes::new()))
.unwrap()
};
@@ -136,7 +139,7 @@ async fn test_website() {
ctx.garage.admin_port,
BCKT_NAME.to_string()
))
- .body(Body::empty())
+ .body(Body::new(Bytes::new()))
.unwrap()
};
@@ -248,7 +251,7 @@ async fn test_website_s3_api() {
);
}
- let client = Client::new();
+ let client = Client::builder(TokioExecutor::new()).build_http();
// Test direct requests with CORS
{
@@ -257,7 +260,7 @@ async fn test_website_s3_api() {
.uri(format!("http://127.0.0.1:{}/site/", ctx.garage.web_port))
.header("Host", format!("{}.web.garage", BCKT_NAME))
.header("Origin", "https://example.com")
- .body(Body::empty())
+ .body(Body::new(Bytes::new()))
.unwrap();
let resp = client.request(req).await.unwrap();
@@ -282,7 +285,7 @@ async fn test_website_s3_api() {
ctx.garage.web_port
))
.header("Host", format!("{}.web.garage", BCKT_NAME))
- .body(Body::empty())
+ .body(Body::new(Bytes::new()))
.unwrap();
let resp = client.request(req).await.unwrap();
@@ -302,7 +305,7 @@ async fn test_website_s3_api() {
.header("Host", format!("{}.web.garage", BCKT_NAME))
.header("Origin", "https://example.com")
.header("Access-Control-Request-Method", "PUT")
- .body(Body::empty())
+ .body(Body::new(Bytes::new()))
.unwrap();
let resp = client.request(req).await.unwrap();
@@ -326,7 +329,7 @@ async fn test_website_s3_api() {
.header("Host", format!("{}.web.garage", BCKT_NAME))
.header("Origin", "https://example.com")
.header("Access-Control-Request-Method", "DELETE")
- .body(Body::empty())
+ .body(Body::new(Bytes::new()))
.unwrap();
let resp = client.request(req).await.unwrap();
@@ -367,7 +370,7 @@ async fn test_website_s3_api() {
.header("Host", format!("{}.web.garage", BCKT_NAME))
.header("Origin", "https://example.com")
.header("Access-Control-Request-Method", "PUT")
- .body(Body::empty())
+ .body(Body::new(Bytes::new()))
.unwrap();
let resp = client.request(req).await.unwrap();
@@ -393,7 +396,7 @@ async fn test_website_s3_api() {
.method("GET")
.uri(format!("http://127.0.0.1:{}/site/", ctx.garage.web_port))
.header("Host", format!("{}.web.garage", BCKT_NAME))
- .body(Body::empty())
+ .body(Body::new(Bytes::new()))
.unwrap();
let resp = client.request(req).await.unwrap();
@@ -409,13 +412,13 @@ async fn test_website_s3_api() {
async fn test_website_check_domain() {
let ctx = common::context();
- let client = Client::new();
+ let client = Client::builder(TokioExecutor::new()).build_http();
let admin_req = || {
Request::builder()
.method("GET")
.uri(format!("http://127.0.0.1:{}/check", ctx.garage.admin_port))
- .body(Body::empty())
+ .body(Body::new(Bytes::new()))
.unwrap()
};
@@ -439,7 +442,7 @@ async fn test_website_check_domain() {
"http://127.0.0.1:{}/check?domain=",
ctx.garage.admin_port
))
- .body(Body::empty())
+ .body(Body::new(Bytes::new()))
.unwrap()
};
@@ -463,7 +466,7 @@ async fn test_website_check_domain() {
"http://127.0.0.1:{}/check?domain=foobar",
ctx.garage.admin_port
))
- .body(Body::empty())
+ .body(Body::new(Bytes::new()))
.unwrap()
};
@@ -487,7 +490,7 @@ async fn test_website_check_domain() {
"http://127.0.0.1:{}/check?domain=%E2%98%B9",
ctx.garage.admin_port
))
- .body(Body::empty())
+ .body(Body::new(Bytes::new()))
.unwrap()
};