Skip to content

Commit

Permalink
move tests to dev dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
AryanGodara authored and Tranduy1dol committed Aug 1, 2024
1 parent 1bc710a commit 1298401
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions crates/orchestrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ dotenvy = { workspace = true }
ethereum-da-client = { workspace = true, optional = true }
futures = { workspace = true }
mongodb = { workspace = true, features = ["bson-uuid-1"], optional = true }
hyper = { version = "0.14", features = ["full"] }
omniqueue = { workspace = true, optional = true }
rstest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
starknet = { workspace = true }
Expand All @@ -39,3 +37,7 @@ default = ["ethereum", "with_mongodb", "with_sqs"]
ethereum = ["ethereum-da-client"]
with_mongodb = ["mongodb"]
with_sqs = ["omniqueue"]

[dev-dependencies]
hyper = { version = "0.14", features = ["full"] }
rstest = { workspace = true }
2 changes: 2 additions & 0 deletions crates/orchestrator/tests/common/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub const MADARA_RPC_URL: &str = "http://localhost:9944";
pub const MONGODB_CONNECTION_STRING: &str = "mongodb+srv://admin:[email protected]/";
1 change: 1 addition & 0 deletions crates/orchestrator/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod constants;
2 changes: 2 additions & 0 deletions crates/orchestrator/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#[cfg(test)]
pub mod server;

pub mod common;
21 changes: 14 additions & 7 deletions crates/orchestrator/tests/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@ use rstest::*;
use starknet::providers::Provider;

use orchestrator::{
queue::init_consumers,
config::{config, Config},
routes::app_router,
utils::env_utils::get_env_var_or_default,
};

use crate::common::constants::{MADARA_RPC_URL, MONGODB_CONNECTION_STRING};

#[fixture]
fn rpc_url() -> String {
String::from("http://localhost:9944")
String::from(MADARA_RPC_URL)
}

#[fixture]
pub async fn init_valid_config(
rpc_url: String
) -> &'static Config {
env::set_var("MADARA_RPC_URL", rpc_url.as_str());
env::set_var("MONGODB_CONNECTION_STRING", MONGODB_CONNECTION_STRING);

let _ = tracing_subscriber::fmt().with_max_level(tracing::Level::INFO).with_target(false).try_init();

Expand Down Expand Up @@ -68,14 +72,11 @@ async fn test_valid_config(

#[rstest]
#[tokio::test]
async fn health(#[future] setup_server: SocketAddr) {
println!("Setting up the server for health");
async fn test_health_endpoint(#[future] setup_server: SocketAddr) {
let addr = setup_server.await;
println!("server for health is set up");


let client = hyper::Client::new();
println!("Client created, now making request to health");
let response = client
.request(Request::builder().uri(format!("http://{}/health", addr)).body(Body::empty()).unwrap())
.await
Expand All @@ -86,5 +87,11 @@ async fn health(#[future] setup_server: SocketAddr) {
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let mut buf = String::new();
let res = body.reader().read_to_string(&mut buf).unwrap();
println!("body health = {}", res);
}
assert_eq!(res, 2);
}

#[rstest]
#[tokio::test]
async fn test_init_consumer() {
assert!(init_consumers().await.is_ok());
}

0 comments on commit 1298401

Please sign in to comment.