All checks were successful
Rust Build / Check (pull_request) Successful in 42s
Rust Build / Test Suite (pull_request) Successful in 51s
Rust Build / Rustfmt (pull_request) Successful in 25s
Rust Build / Clippy (pull_request) Successful in 49s
Rust Build / build (pull_request) Successful in 1m19s
101 lines
2.6 KiB
Rust
101 lines
2.6 KiB
Rust
extern crate icarus_auth;
|
|
|
|
use crate::icarus_auth::callers;
|
|
|
|
// use axum::Extension;
|
|
use axum::body::Body;
|
|
// use axum::response::Response;
|
|
use axum::{
|
|
Router,
|
|
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::
|
|
|
|
/*
|
|
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
|
|
|
|
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!");
|
|
}
|
|
|
|
/*
|
|
#[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());
|
|
}
|
|
};
|
|
}
|
|
*/
|