Test suit load environment variable from env files (#1701)
This commit is contained in:
parent
1431d8027c
commit
d35cd6aa3b
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,4 +3,5 @@ Cargo.lock
|
||||
*.sublime*
|
||||
.vscode
|
||||
.idea/*
|
||||
*/.idea/*
|
||||
*/.idea/*
|
||||
.env.local
|
@ -61,6 +61,7 @@ time = { version = "0.3", features = ["macros"] }
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
once_cell = "1.8"
|
||||
arraystring = "0.3"
|
||||
dotenv = "0.15"
|
||||
|
||||
[features]
|
||||
debug-print = []
|
||||
|
@ -8,6 +8,9 @@ pub use sea_orm::{entity::*, error::*, query::*, sea_query, tests_cfg::*, Databa
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(feature = "sqlx-sqlite")]
|
||||
async fn main() -> Result<(), DbErr> {
|
||||
dotenv::from_filename(".env.local").ok();
|
||||
dotenv::from_filename(".env").ok();
|
||||
|
||||
let base_url = std::env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite::memory:".to_owned());
|
||||
|
||||
let db: DbConn = Database::connect(&base_url).await?;
|
||||
|
@ -13,6 +13,9 @@ pub struct TestContext {
|
||||
|
||||
impl TestContext {
|
||||
pub async fn new(test_name: &str) -> Self {
|
||||
dotenv::from_filename(".env.local").ok();
|
||||
dotenv::from_filename(".env").ok();
|
||||
|
||||
let base_url =
|
||||
std::env::var("DATABASE_URL").expect("Enviroment variable 'DATABASE_URL' not set");
|
||||
let db: DatabaseConnection = setup::setup(&base_url, test_name).await;
|
||||
|
Loading…
x
Reference in New Issue
Block a user