test refactoring
Some checks failed
Rust Build / Check (pull_request) Successful in 39s
Rust Build / Test Suite (pull_request) Failing after 43s
Rust Build / Rustfmt (pull_request) Failing after 22s
Rust Build / Clippy (pull_request) Successful in 37s
Rust Build / build (pull_request) Successful in 1m2s
Some checks failed
Rust Build / Check (pull_request) Successful in 39s
Rust Build / Test Suite (pull_request) Failing after 43s
Rust Build / Rustfmt (pull_request) Failing after 22s
Rust Build / Clippy (pull_request) Successful in 37s
Rust Build / build (pull_request) Successful in 1m2s
This commit is contained in:
38
src/main.rs
38
src/main.rs
@@ -69,12 +69,9 @@ mod tests {
|
||||
mod db_mgr {
|
||||
use std::str::FromStr;
|
||||
|
||||
use icarus_auth::keys;
|
||||
|
||||
pub const LIMIT: usize = 6;
|
||||
|
||||
pub async fn get_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||
dotenvy::dotenv().ok(); // Load .env file if it exists
|
||||
let tm_db_url = icarus_envy::environment::get_db_url().await;
|
||||
let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap();
|
||||
sqlx::PgPool::connect_with(tm_options).await
|
||||
@@ -114,28 +111,23 @@ mod tests {
|
||||
}
|
||||
|
||||
pub fn get_database_name() -> Result<String, Box<dyn std::error::Error>> {
|
||||
dotenvy::dotenv().ok(); // Load .env file if it exists
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
|
||||
match std::env::var(icarus_envy::keys::DB_URL) {
|
||||
Ok(database_url) => {
|
||||
let parsed_url = url::Url::parse(&database_url)?;
|
||||
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
|
||||
match parsed_url
|
||||
.path_segments()
|
||||
.and_then(|segments| segments.last().map(|s| s.to_string()))
|
||||
{
|
||||
Some(sss) => Ok(sss),
|
||||
None => Err("Error parsing".into()),
|
||||
}
|
||||
} else {
|
||||
// Handle other database types if needed
|
||||
Err("Error parsing".into())
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
// DATABASE_URL environment variable not found
|
||||
Err("Error parsing".into())
|
||||
// Block on the async function to get the result
|
||||
let database_url = rt.block_on(icarus_envy::environment::get_db_url());
|
||||
|
||||
let parsed_url = url::Url::parse(&database_url)?;
|
||||
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
|
||||
match parsed_url
|
||||
.path_segments()
|
||||
.and_then(|segments| segments.last().map(|s| s.to_string()))
|
||||
{
|
||||
Some(sss) => Ok(sss),
|
||||
None => Err("Error parsing".into()),
|
||||
}
|
||||
} else {
|
||||
// Handle other database types if needed
|
||||
Err("Error parsing".into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user