Added config file for db (#9)
Some checks failed
Release Tagging / release (push) Successful in 47s
Rust Build / Check (push) Successful in 53s
Rust Build / Test Suite (push) Failing after 54s
Rust Build / Rustfmt (push) Successful in 28s
Rust Build / Clippy (push) Successful in 50s
Rust Build / build (push) Successful in 1m5s

Reviewed-on: #9
Co-authored-by: KD <kundeng94@gmail.com>
Co-committed-by: KD <kundeng94@gmail.com>
This commit is contained in:
KD
2025-04-03 13:59:54 +00:00
committed by phoenix
parent c9873d95d7
commit 4d3415acf2
11 changed files with 272 additions and 9 deletions

View File

@@ -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,13 +10,78 @@ use axum::{
http::{Request, StatusCode},
routing::get,
};
// use hyper::client::conn;
// use sqlx::PgPool;
// use sqlx::postgres::{self, PgPoolOptions};
// use testcontainers_modules::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;
const TEST_DATABASE_URL_ENV: &str = "TEST_DATABASE_URL";
const DEFAULT_TEST_DATABASE_URL: &str =
"postgres://icarus_op_test:password@localhost:5432/icarus_auth_test";
static SETUP: std::sync::Once = std::sync::Once::new();
// Ensure tracing is initialized only once for all tests in this file
/*
static TRACING_INIT: Lazy<()> = Lazy::new(|| {
if std::env::var("RUST_LOG").is_err() {
// Set default log level if not provided
unsafe {
std::env::set_var("RUST_LOG", "info,tower_http=debug,your_project_name=debug");
}
}
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_test_writer() // Write logs to the test output capture
.init();
});
*/
/*
async fn setup_database() -> sqlx::PgPool {
let database_url = std::env::var(TEST_DATABASE_URL_ENV)
.unwrap_or_else(|_| DEFAULT_TEST_DATABASE_URL.to_string());
let pool = sqlx::PgPool::connect(&database_url)
.await
.expect("Failed to connect to test database");
let migrator = sqlx::migrate::Migrator::new(std::path::Path::new("./migrations"))
.await
.expect("Failed to create migrator");
migrator.run(&pool).await.expect("Failed to run migrations");
// Seed here if needed
pool
}
*/
/*
#[tokio::test]
async fn test_db_health() {
SETUP.call_once(|| {
tokio::runtime::Runtime::new().unwrap().block_on(async {
setup_database().await;
});
});
}
*/
/*
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() {
let app = Router::new().route(callers::endpoints::ROOT, get(callers::common::root)); // Replace with your handler
@@ -40,3 +108,46 @@ 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 port = 5432;
let host_port = container.get_host_port_ipv4(port).await.unwrap();
let conn_string = &format!(
"postgres://postgres:postgres@localhost:{}/postgres",
host_port
);
println!("Test Database: {}", conn_string);
let app = Router::new().route(callers::endpoints::DBTEST, get(callers::common::db_ping)); // Replace with your handler
let response = app
.oneshot(
Request::builder()
.uri(callers::endpoints::DBTEST)
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(response.status(), StatusCode::OK);
match PgPoolOptions::new().connect(conn_string).await {
Ok(_) => {
assert!(true, "Success");
}
Err(err) => {
assert!(false, "Error: {:?}", err.to_string());
}
};
}
*/