integration test: move json_body to root of crate

This commit is contained in:
Alex Auvolat 2023-08-28 12:32:57 +02:00
parent 51011e68b1
commit e66c78d6ea
7 changed files with 22 additions and 17 deletions

View file

@ -1,6 +1,7 @@
use aws_sdk_s3::config::Region; use aws_sdk_s3::config::Region;
use aws_sdk_s3::Client; use aws_sdk_s3::Client;
use ext::*; use ext::*;
#[cfg(feature = "k2v")]
use k2v_client::K2vClient; use k2v_client::K2vClient;
#[macro_use] #[macro_use]
@ -21,6 +22,7 @@ pub struct Context {
pub key: garage::Key, pub key: garage::Key,
pub client: Client, pub client: Client,
pub custom_request: CustomRequester, pub custom_request: CustomRequester,
#[cfg(feature = "k2v")]
pub k2v: K2VContext, pub k2v: K2VContext,
} }
@ -35,6 +37,7 @@ impl Context {
let key = garage.key(None); let key = garage.key(None);
let client = client::build_client(&key); let client = client::build_client(&key);
let custom_request = CustomRequester::new_s3(garage, &key); let custom_request = CustomRequester::new_s3(garage, &key);
#[cfg(feature = "k2v")]
let k2v_request = CustomRequester::new_k2v(garage, &key); let k2v_request = CustomRequester::new_k2v(garage, &key);
Context { Context {
@ -42,6 +45,7 @@ impl Context {
client, client,
key, key,
custom_request, custom_request,
#[cfg(feature = "k2v")]
k2v: K2VContext { k2v: K2VContext {
request: k2v_request, request: k2v_request,
}, },
@ -72,6 +76,7 @@ impl Context {
} }
/// Build a K2vClient for a given bucket /// Build a K2vClient for a given bucket
#[cfg(feature = "k2v")]
pub fn k2v_client(&self, bucket: &str) -> K2vClient { pub fn k2v_client(&self, bucket: &str) -> K2vClient {
let config = k2v_client::K2vClientConfig { let config = k2v_client::K2vClientConfig {
region: REGION.to_string(), region: REGION.to_string(),

View file

@ -6,7 +6,7 @@ use assert_json_diff::assert_json_eq;
use base64::prelude::*; use base64::prelude::*;
use serde_json::json; use serde_json::json;
use super::json_body; use crate::json_body;
use hyper::{Method, StatusCode}; use hyper::{Method, StatusCode};
#[tokio::test] #[tokio::test]

View file

@ -6,7 +6,7 @@ use assert_json_diff::assert_json_eq;
use base64::prelude::*; use base64::prelude::*;
use serde_json::json; use serde_json::json;
use super::json_body; use crate::json_body;
use hyper::{Method, StatusCode}; use hyper::{Method, StatusCode};
#[tokio::test] #[tokio::test]

View file

@ -3,16 +3,3 @@ pub mod errorcodes;
pub mod item; pub mod item;
pub mod poll; pub mod poll;
pub mod simple; pub mod simple;
use hyper::{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();
res_body
}

View file

@ -5,8 +5,8 @@ use std::time::Duration;
use assert_json_diff::assert_json_eq; use assert_json_diff::assert_json_eq;
use serde_json::json; use serde_json::json;
use super::json_body;
use crate::common; use crate::common;
use crate::json_body;
#[tokio::test] #[tokio::test]
async fn test_poll_item() { async fn test_poll_item() {

View file

@ -10,3 +10,16 @@ mod s3;
mod k2v; mod k2v;
#[cfg(feature = "k2v")] #[cfg(feature = "k2v")]
mod k2v_client; mod k2v_client;
use hyper::{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();
res_body
}

View file

@ -1,6 +1,6 @@
use crate::common; use crate::common;
use crate::common::ext::*; use crate::common::ext::*;
use crate::k2v::json_body; use crate::json_body;
use assert_json_diff::assert_json_eq; use assert_json_diff::assert_json_eq;
use aws_sdk_s3::{ use aws_sdk_s3::{