From b6c4e074ff3ee8fa759e0a17a12652cfe24b7072 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 1 Apr 2025 21:53:52 -0400 Subject: [PATCH] Updated tests --- tests/auth_tests.rs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/auth_tests.rs b/tests/auth_tests.rs index 19e08fe..4329563 100644 --- a/tests/auth_tests.rs +++ b/tests/auth_tests.rs @@ -1,5 +1,8 @@ extern crate icarus_auth; +use crate::icarus_auth::callers; + +use axum::Extension; use axum::body::Body; // use axum::response::Response; use axum::{ @@ -7,12 +10,23 @@ use axum::{ http::{Request, StatusCode}, routing::get, }; +use hyper::client::conn; +use sqlx::PgPool; +use sqlx::postgres::PgPoolOptions; +use testcontainers_modules::{postgres, testcontainers::runners::AsyncRunner}; +// use hyper::client; +// use sqlx::postgres; // use http::{Request, StatusCode}; // use serde_json::json; // use tower::ServiceExt; // for `.oneshot()` use tower::util::ServiceExt; +// use testcontainers_modules::testcontainers::core::client:: -use crate::icarus_auth::callers; +async fn setup_test(pool: sqlx::PgPool) -> Router { + Router::new() + .route(callers::endpoints::DBTEST, get(callers::common::db_ping)) + .layer(Extension(pool)) +} #[tokio::test] async fn test_hello_world() { @@ -40,3 +54,21 @@ async fn test_hello_world() { assert_eq!(body, "Hello, World!"); } + +#[tokio::test] +async fn test_db_health_check() { + let container = testcontainers_modules::postgres::Postgres::default() + .start() + .await + .unwrap(); + let host_ip = container.get_host().await.unwrap(); + let host_port = container.get_host_port_ipv4(5432).await.unwrap(); + let conn_string = &format!( + "postgres://postgres:postgres@localhost:{}/postgres", + host_port + ); + + println!("Test Database: {}", conn_string); + + let test_pool = PgPoolOptions::new().connect(conn_string).await.unwrap(); +}