Correction
All checks were successful
Rust Build / Check (pull_request) Successful in 50s
Rust Build / Test Suite (pull_request) Successful in 1m48s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Successful in 48s
Rust Build / build (pull_request) Successful in 1m18s
All checks were successful
Rust Build / Check (pull_request) Successful in 50s
Rust Build / Test Suite (pull_request) Successful in 1m48s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Successful in 48s
Rust Build / build (pull_request) Successful in 1m18s
This commit is contained in:
@@ -4,7 +4,7 @@ pub mod hashing;
|
|||||||
pub mod models;
|
pub mod models;
|
||||||
pub mod repo;
|
pub mod repo;
|
||||||
|
|
||||||
mod keys {
|
pub mod keys {
|
||||||
pub const DBURL: &str = "DATABASE_URL";
|
pub const DBURL: &str = "DATABASE_URL";
|
||||||
|
|
||||||
pub mod error {
|
pub mod error {
|
||||||
|
12
src/main.rs
12
src/main.rs
@@ -78,10 +78,12 @@ mod tests {
|
|||||||
mod db_mgr {
|
mod db_mgr {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use icarus_auth::keys;
|
||||||
|
|
||||||
pub const LIMIT: usize = 6;
|
pub const LIMIT: usize = 6;
|
||||||
|
|
||||||
pub async fn eeee() -> Result<sqlx::PgPool, sqlx::Error> {
|
pub async fn get_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||||
let tm_db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be present");
|
let tm_db_url = std::env::var(keys::DBURL).expect("DATABASE_URL must be present");
|
||||||
let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap();
|
let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap();
|
||||||
sqlx::PgPool::connect_with(tm_options).await
|
sqlx::PgPool::connect_with(tm_options).await
|
||||||
}
|
}
|
||||||
@@ -93,7 +95,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect_to_db(db_name: &str) -> Result<sqlx::PgPool, sqlx::Error> {
|
pub async fn connect_to_db(db_name: &str) -> Result<sqlx::PgPool, sqlx::Error> {
|
||||||
let db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set for tests");
|
let db_url = std::env::var(keys::DBURL).expect("DATABASE_URL must be set for tests");
|
||||||
let options = sqlx::postgres::PgConnectOptions::from_str(&db_url)?.database(db_name);
|
let options = sqlx::postgres::PgConnectOptions::from_str(&db_url)?.database(db_name);
|
||||||
sqlx::PgPool::connect_with(options).await
|
sqlx::PgPool::connect_with(options).await
|
||||||
}
|
}
|
||||||
@@ -122,7 +124,7 @@ mod tests {
|
|||||||
pub fn get_database_name() -> Result<String, Box<dyn std::error::Error>> {
|
pub fn get_database_name() -> Result<String, Box<dyn std::error::Error>> {
|
||||||
dotenvy::dotenv().ok(); // Load .env file if it exists
|
dotenvy::dotenv().ok(); // Load .env file if it exists
|
||||||
|
|
||||||
match std::env::var("DATABASE_URL") {
|
match std::env::var(keys::DBURL) {
|
||||||
Ok(database_url) => {
|
Ok(database_url) => {
|
||||||
let parsed_url = url::Url::parse(&database_url)?;
|
let parsed_url = url::Url::parse(&database_url)?;
|
||||||
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
|
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
|
||||||
@@ -170,7 +172,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_register_user() {
|
async fn test_register_user() {
|
||||||
let tm_pool = db_mgr::eeee().await.unwrap();
|
let tm_pool = db_mgr::get_pool().await.unwrap();
|
||||||
|
|
||||||
let db_name = db_mgr::generate_db_name().await;
|
let db_name = db_mgr::generate_db_name().await;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user