From e9e76f6fc56679c34caab79bcb52ee108ef6dbec Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 26 Apr 2022 14:35:07 +0200 Subject: [PATCH] Remove a bit of noise --- src/garage/tests/common/custom_requester.rs | 16 ++++++++++++++++ src/garage/tests/k2v/simple.rs | 13 +++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/garage/tests/common/custom_requester.rs b/src/garage/tests/common/custom_requester.rs index 182cd803..42875b51 100644 --- a/src/garage/tests/common/custom_requester.rs +++ b/src/garage/tests/common/custom_requester.rs @@ -91,16 +91,32 @@ impl<'a> RequestBuilder<'a> { self } + pub fn query_param(&mut self, param: T, value: Option) -> &mut Self + where T: ToString, U: ToString, { + self.query_params.insert(param.to_string(), value.as_ref().map(ToString::to_string)); + self + } + pub fn signed_headers(&mut self, signed_headers: HashMap) -> &mut Self { self.signed_headers = signed_headers; self } + pub fn signed_header(&mut self, name: impl ToString, value: impl ToString) -> &mut Self { + self.signed_headers.insert(name.to_string(), value.to_string()); + self + } + pub fn unsigned_headers(&mut self, unsigned_headers: HashMap) -> &mut Self { self.unsigned_headers = unsigned_headers; self } + pub fn unsigned_header(&mut self, name: impl ToString, value: impl ToString) -> &mut Self { + self.unsigned_headers.insert(name.to_string(), value.to_string()); + self + } + pub fn body(&mut self, body: Vec) -> &mut Self { self.body = body; self diff --git a/src/garage/tests/k2v/simple.rs b/src/garage/tests/k2v/simple.rs index b722e754..164d82aa 100644 --- a/src/garage/tests/k2v/simple.rs +++ b/src/garage/tests/k2v/simple.rs @@ -1,4 +1,3 @@ -use std::collections::HashMap; use crate::common; use common::custom_requester::BodySignature; @@ -9,14 +8,11 @@ async fn test_simple() { let ctx = common::context(); let bucket = ctx.create_bucket("test-k2v-simple"); - let mut query_params = HashMap::new(); - query_params.insert("sort_key".to_string(), Some("test1".to_string())); - let res = ctx.k2v.request .builder(bucket.clone()) .method(Method::PUT) .path("root".into()) - .query_params(query_params.clone()) + .query_param("sort_key", Some("test1")) .body(b"Hello, world!".to_vec()) .body_signature(BodySignature::Classic) .send() @@ -24,14 +20,11 @@ async fn test_simple() { .unwrap(); assert_eq!(res.status(), 200); - let mut h = HashMap::new(); - h.insert("accept".to_string(), "application/octet-stream".to_string()); - let res2 = ctx.k2v.request .builder(bucket.clone()) .path("root".into()) - .query_params(query_params.clone()) - .signed_headers(h) + .query_param("sort_key", Some("test1")) + .signed_header("accept", "application/octet-stream") .body_signature(BodySignature::Classic) .send() .await