From c9873d95d761fbec4f1e78f34f8178d19f4222ce Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 1 Apr 2025 00:29:09 +0000 Subject: [PATCH] Added test (#8) Reviewed-on: https://git.kundeng.us/phoenix/icarus_auth/pulls/8 Co-authored-by: phoenix Co-committed-by: phoenix --- Cargo.toml | 4 +++- src/lib.rs | 3 +++ src/main.rs | 5 ++--- tests/auth_tests.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 src/lib.rs create mode 100644 tests/auth_tests.rs diff --git a/Cargo.toml b/Cargo.toml index d27538f..ce7a653 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,5 +8,7 @@ axum = { version = "0.8.3" } serde = { version = "1.0.218", features = ["derive"] } serde_json = { version = "1.0.139" } tokio = { version = "1.44.1", features = ["rt-multi-thread"] } -tracing-subscriber = "0.3.19" +tracing-subscriber = { version = "0.3.19" } +tower = { version = "0.5.2" } +hyper = { version = "1.6.0" } icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.2.0" } diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..231cc1e --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,3 @@ +pub mod callers; +pub mod config; +pub mod models; diff --git a/src/main.rs b/src/main.rs index a18c999..036d622 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,9 +3,8 @@ use axum::{ routing::{get, post}, }; -pub mod callers; -pub mod config; -pub mod models; +use icarus_auth::callers; +use icarus_auth::config; #[tokio::main] async fn main() { diff --git a/tests/auth_tests.rs b/tests/auth_tests.rs new file mode 100644 index 0000000..19e08fe --- /dev/null +++ b/tests/auth_tests.rs @@ -0,0 +1,42 @@ +extern crate icarus_auth; + +use axum::body::Body; +// use axum::response::Response; +use axum::{ + Router, + http::{Request, StatusCode}, + routing::get, +}; +// use http::{Request, StatusCode}; +// use serde_json::json; +// use tower::ServiceExt; // for `.oneshot()` +use tower::util::ServiceExt; + +use crate::icarus_auth::callers; + +#[tokio::test] +async fn test_hello_world() { + let app = Router::new().route(callers::endpoints::ROOT, get(callers::common::root)); // Replace with your handler + + let response = app + .oneshot( + Request::builder() + .uri(callers::endpoints::ROOT) + .body(Body::empty()) + .unwrap(), + ) + .await + .unwrap(); + + assert_eq!(response.status(), StatusCode::OK); + + let body = String::from_utf8( + axum::body::to_bytes(response.into_body(), usize::MAX) + .await + .unwrap() + .to_vec(), + ) + .unwrap(); + + assert_eq!(body, "Hello, World!"); +}