aboutsummaryrefslogtreecommitdiff
path: root/src/garage/tests
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2024-02-05 14:44:12 +0100
committerAlex Auvolat <alex@adnab.me>2024-02-05 14:44:12 +0100
commit6e69a1fffc715c752a399750c1e26aa46683dbb2 (patch)
treed1539c6107372f14aa6ca09255977df69411a553 /src/garage/tests
parent6e4229e29c1ee3e0b7f3511f80b6108e3beb1efd (diff)
downloadgarage-6e69a1fffc715c752a399750c1e26aa46683dbb2.tar.gz
garage-6e69a1fffc715c752a399750c1e26aa46683dbb2.zip
[dep-upgrade-202402] prepare migration to http/hyper 1.0
Diffstat (limited to 'src/garage/tests')
-rw-r--r--src/garage/tests/k2v/batch.rs7
-rw-r--r--src/garage/tests/k2v/item.rs22
-rw-r--r--src/garage/tests/k2v/poll.rs16
-rw-r--r--src/garage/tests/k2v/simple.rs9
-rw-r--r--src/garage/tests/lib.rs11
-rw-r--r--src/garage/tests/s3/website.rs45
6 files changed, 38 insertions, 72 deletions
diff --git a/src/garage/tests/k2v/batch.rs b/src/garage/tests/k2v/batch.rs
index 71de91bf..417fe7ea 100644
--- a/src/garage/tests/k2v/batch.rs
+++ b/src/garage/tests/k2v/batch.rs
@@ -7,7 +7,7 @@ use base64::prelude::*;
use serde_json::json;
use crate::json_body;
-use hyper::{Method, StatusCode};
+use hyper::{body::HttpBody, Method, StatusCode};
#[tokio::test]
async fn test_batch() {
@@ -77,10 +77,7 @@ async fn test_batch() {
.unwrap()
.to_string(),
);
- let res_body = hyper::body::to_bytes(res.into_body())
- .await
- .unwrap()
- .to_vec();
+ let res_body = res.into_body().collect().await.unwrap().to_bytes();
assert_eq!(res_body, values.get(sk).unwrap().as_bytes());
}
diff --git a/src/garage/tests/k2v/item.rs b/src/garage/tests/k2v/item.rs
index 20add889..6b653088 100644
--- a/src/garage/tests/k2v/item.rs
+++ b/src/garage/tests/k2v/item.rs
@@ -7,7 +7,7 @@ use base64::prelude::*;
use serde_json::json;
use crate::json_body;
-use hyper::{Method, StatusCode};
+use hyper::{body::HttpBody, Method, StatusCode};
#[tokio::test]
async fn test_items_and_indices() {
@@ -83,10 +83,7 @@ async fn test_items_and_indices() {
.to_str()
.unwrap()
.to_string();
- let res_body = hyper::body::to_bytes(res.into_body())
- .await
- .unwrap()
- .to_vec();
+ let res_body = res.into_body().collect().await.unwrap().to_bytes();
assert_eq!(res_body, content);
// ReadIndex -- now there should be some stuff
@@ -152,10 +149,7 @@ async fn test_items_and_indices() {
res.headers().get("content-type").unwrap().to_str().unwrap(),
"application/octet-stream"
);
- let res_body = hyper::body::to_bytes(res.into_body())
- .await
- .unwrap()
- .to_vec();
+ let res_body = res.into_body().collect().await.unwrap().to_bytes();
assert_eq!(res_body, content2);
// ReadIndex -- now there should be some stuff
@@ -394,10 +388,7 @@ async fn test_item_return_format() {
.to_str()
.unwrap()
.to_string();
- let res_body = hyper::body::to_bytes(res.into_body())
- .await
- .unwrap()
- .to_vec();
+ let res_body = res.into_body().collect().await.unwrap().to_bytes();
assert_eq!(res_body, single_value);
// f1: not specified
@@ -434,10 +425,7 @@ async fn test_item_return_format() {
res.headers().get("content-type").unwrap().to_str().unwrap(),
"application/octet-stream"
);
- let res_body = hyper::body::to_bytes(res.into_body())
- .await
- .unwrap()
- .to_vec();
+ let res_body = res.into_body().collect().await.unwrap().to_bytes();
assert_eq!(res_body, single_value);
// f3: json
diff --git a/src/garage/tests/k2v/poll.rs b/src/garage/tests/k2v/poll.rs
index 452317c2..b75fa9c7 100644
--- a/src/garage/tests/k2v/poll.rs
+++ b/src/garage/tests/k2v/poll.rs
@@ -1,5 +1,5 @@
use base64::prelude::*;
-use hyper::{Method, StatusCode};
+use hyper::{body::HttpBody, Method, StatusCode};
use std::time::Duration;
use assert_json_diff::assert_json_eq;
@@ -47,11 +47,8 @@ async fn test_poll_item() {
.unwrap()
.to_string();
- let res2_body = hyper::body::to_bytes(res2.into_body())
- .await
- .unwrap()
- .to_vec();
- assert_eq!(res2_body, b"Initial value");
+ let res2_body = res2.into_body().collect().await.unwrap().to_bytes();
+ assert_eq!(res2_body, b"Initial value"[..]);
// Start poll operation
let poll = {
@@ -95,11 +92,8 @@ async fn test_poll_item() {
assert_eq!(poll_res.status(), StatusCode::OK);
- let poll_res_body = hyper::body::to_bytes(poll_res.into_body())
- .await
- .unwrap()
- .to_vec();
- assert_eq!(poll_res_body, b"New value");
+ let poll_res_body = poll_res.into_body().collect().await.unwrap().to_bytes();
+ assert_eq!(poll_res_body, b"New value"[..]);
}
#[tokio::test]
diff --git a/src/garage/tests/k2v/simple.rs b/src/garage/tests/k2v/simple.rs
index 465fc24d..a1d5008b 100644
--- a/src/garage/tests/k2v/simple.rs
+++ b/src/garage/tests/k2v/simple.rs
@@ -1,6 +1,6 @@
use crate::common;
-use hyper::{Method, StatusCode};
+use hyper::{body::HttpBody, Method, StatusCode};
#[tokio::test]
async fn test_simple() {
@@ -32,9 +32,6 @@ async fn test_simple() {
.unwrap();
assert_eq!(res2.status(), StatusCode::OK);
- let res2_body = hyper::body::to_bytes(res2.into_body())
- .await
- .unwrap()
- .to_vec();
- assert_eq!(res2_body, b"Hello, world!");
+ let res2_body = res2.into_body().collect().await.unwrap().to_bytes();
+ assert_eq!(res2_body, b"Hello, world!"[..]);
}
diff --git a/src/garage/tests/lib.rs b/src/garage/tests/lib.rs
index ab92bc0a..3cb17a2b 100644
--- a/src/garage/tests/lib.rs
+++ b/src/garage/tests/lib.rs
@@ -11,15 +11,10 @@ mod k2v;
#[cfg(feature = "k2v")]
mod k2v_client;
-use hyper::{Body, Response};
+use hyper::{body::HttpBody, Body, Response};
pub async fn json_body(res: Response<Body>) -> serde_json::Value {
- let res_body: serde_json::Value = serde_json::from_slice(
- &hyper::body::to_bytes(res.into_body())
- .await
- .unwrap()
- .to_vec()[..],
- )
- .unwrap();
+ 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 59c990f8..94acafc7 100644
--- a/src/garage/tests/s3/website.rs
+++ b/src/garage/tests/s3/website.rs
@@ -9,7 +9,7 @@ use aws_sdk_s3::{
};
use http::{Request, StatusCode};
use hyper::{
- body::{to_bytes, Body},
+ body::{Body, HttpBody},
Client,
};
use serde_json::json;
@@ -49,7 +49,7 @@ async fn test_website() {
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
assert_ne!(
- to_bytes(resp.body_mut()).await.unwrap().as_ref(),
+ resp.into_body().collect().await.unwrap().to_bytes(),
BODY.as_ref()
); /* check that we do not leak body */
@@ -87,7 +87,7 @@ async fn test_website() {
resp = client.request(req()).await.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
assert_eq!(
- to_bytes(resp.body_mut()).await.unwrap().as_ref(),
+ resp.into_body().collect().await.unwrap().to_bytes(),
BODY.as_ref()
);
@@ -107,10 +107,10 @@ async fn test_website() {
.unwrap()
};
- let mut admin_resp = client.request(admin_req()).await.unwrap();
+ let admin_resp = client.request(admin_req()).await.unwrap();
assert_eq!(admin_resp.status(), StatusCode::OK);
assert_eq!(
- to_bytes(admin_resp.body_mut()).await.unwrap().as_ref(),
+ admin_resp.into_body().collect().await.unwrap().to_bytes(),
format!("Domain '{bname}' is managed by Garage").as_bytes()
);
}
@@ -124,7 +124,7 @@ async fn test_website() {
resp = client.request(req()).await.unwrap();
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
assert_ne!(
- to_bytes(resp.body_mut()).await.unwrap().as_ref(),
+ resp.into_body().collect().await.unwrap().to_bytes(),
BODY.as_ref()
); /* check that we do not leak body */
@@ -260,7 +260,7 @@ async fn test_website_s3_api() {
.body(Body::empty())
.unwrap();
- let mut resp = client.request(req).await.unwrap();
+ let resp = client.request(req).await.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
assert_eq!(
@@ -268,7 +268,7 @@ async fn test_website_s3_api() {
"*"
);
assert_eq!(
- to_bytes(resp.body_mut()).await.unwrap().as_ref(),
+ resp.into_body().collect().await.unwrap().to_bytes(),
BODY.as_ref()
);
}
@@ -285,11 +285,11 @@ async fn test_website_s3_api() {
.body(Body::empty())
.unwrap();
- let mut resp = client.request(req).await.unwrap();
+ let resp = client.request(req).await.unwrap();
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
assert_eq!(
- to_bytes(resp.body_mut()).await.unwrap().as_ref(),
+ resp.into_body().collect().await.unwrap().to_bytes(),
BODY_ERR.as_ref()
);
}
@@ -305,7 +305,7 @@ async fn test_website_s3_api() {
.body(Body::empty())
.unwrap();
- let mut resp = client.request(req).await.unwrap();
+ let resp = client.request(req).await.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
assert_eq!(
@@ -313,7 +313,7 @@ async fn test_website_s3_api() {
"*"
);
assert_ne!(
- to_bytes(resp.body_mut()).await.unwrap().as_ref(),
+ resp.into_body().collect().await.unwrap().to_bytes(),
BODY.as_ref()
);
}
@@ -329,11 +329,11 @@ async fn test_website_s3_api() {
.body(Body::empty())
.unwrap();
- let mut resp = client.request(req).await.unwrap();
+ let resp = client.request(req).await.unwrap();
assert_eq!(resp.status(), StatusCode::FORBIDDEN);
assert_ne!(
- to_bytes(resp.body_mut()).await.unwrap().as_ref(),
+ resp.into_body().collect().await.unwrap().to_bytes(),
BODY.as_ref()
);
}
@@ -370,11 +370,11 @@ async fn test_website_s3_api() {
.body(Body::empty())
.unwrap();
- let mut resp = client.request(req).await.unwrap();
+ let resp = client.request(req).await.unwrap();
assert_eq!(resp.status(), StatusCode::FORBIDDEN);
assert_ne!(
- to_bytes(resp.body_mut()).await.unwrap().as_ref(),
+ resp.into_body().collect().await.unwrap().to_bytes(),
BODY.as_ref()
);
}
@@ -396,17 +396,12 @@ async fn test_website_s3_api() {
.body(Body::empty())
.unwrap();
- let mut resp = client.request(req).await.unwrap();
+ let resp = client.request(req).await.unwrap();
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
- assert_ne!(
- to_bytes(resp.body_mut()).await.unwrap().as_ref(),
- BODY_ERR.as_ref()
- );
- assert_ne!(
- to_bytes(resp.body_mut()).await.unwrap().as_ref(),
- BODY.as_ref()
- );
+ let resp_bytes = resp.into_body().collect().await.unwrap().to_bytes();
+ assert_ne!(resp_bytes, BODY_ERR.as_ref());
+ assert_ne!(resp_bytes, BODY.as_ref());
}
}