Skip to content

Commit

Permalink
Replace hyper with reqwest in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Feb 26, 2024
1 parent 0661bec commit 0b2ff58
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 48 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion shotover-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ cql-ws = { git = "https://github.com/shotover/cql-ws" }
opensearch = "2.1.0"
serde_json = "1.0.103"
time = { version = "0.3.25" }
hyper.workspace = true
shell-quote.workspace = true

[features]
Expand Down
51 changes: 5 additions & 46 deletions shotover-proxy/tests/transforms/tee.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::shotover_process;
use hyper::{body, Body, Client, Method, Request, Response};
use test_helpers::connection::redis_connection;
use test_helpers::docker_compose::docker_compose;
use test_helpers::shotover_process::{EventMatcher, Level};
Expand Down Expand Up @@ -205,23 +204,6 @@ async fn test_subchain_with_mismatch() {
shotover.shutdown_and_then_consume_events(&[]).await;
}

async fn read_response_body(res: Response<Body>) -> Result<String, hyper::Error> {
let bytes = body::to_bytes(res.into_body()).await?;
Ok(String::from_utf8(bytes.to_vec()).expect("response was not valid utf-8"))
}

async fn hyper_request(uri: String, method: Method, body: Body) -> Response<Body> {
let client = Client::new();

let req = Request::builder()
.method(method)
.uri(uri)
.body(body)
.expect("request builder");

client.request(req).await.unwrap()
}

#[tokio::test(flavor = "multi_thread")]
async fn test_switch_main_chain() {
let shotover = shotover_process("tests/test-configs/tee/switch_chain.yaml")
Expand All @@ -243,26 +225,11 @@ async fn test_switch_main_chain() {

assert_eq!("a", result);

let _ = hyper_request(
format!(
"http://localhost:{}/transform/tee/result-source",
switch_port
),
Method::PUT,
Body::from("tee-chain"),
)
.await;
let url = format!("http://localhost:{switch_port}/transform/tee/result-source");
let client = reqwest::Client::new();
client.put(&url).body("tee-chain").send().await.unwrap();

let res = hyper_request(
format!(
"http://localhost:{}/transform/tee/result-source",
switch_port
),
Method::GET,
Body::empty(),
)
.await;
let body = read_response_body(res).await.unwrap();
let body = client.get(&url).send().await.unwrap().text().await.unwrap();
assert_eq!("tee-chain", body);

let result = redis::cmd("SET")
Expand All @@ -274,15 +241,7 @@ async fn test_switch_main_chain() {

assert_eq!("b", result);

let _ = hyper_request(
format!(
"http://localhost:{}/transform/tee/result-source",
switch_port
),
Method::PUT,
Body::from("regular-chain"),
)
.await;
client.put(&url).body("regular-chain").send().await.unwrap();

let result = redis::cmd("SET")
.arg("key")
Expand Down

0 comments on commit 0b2ff58

Please sign in to comment.