Skip to content

Commit 008aa07

Browse files
committed
chore: add .env.test for database tests
- Tests load .env.test via dotenvy - Keep .env and .env.local in .gitignore for local overrides
1 parent 64fd9b6 commit 008aa07

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

.env.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DATABASE_URL=postgres://postgres:postgres@localhost/postgres

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/target
2+
.env
3+
.env.local

tests/db_test.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//! Database integration tests
22
//!
3-
//! These tests require a PostgreSQL database. Set DATABASE_URL to run them:
3+
//! These tests require a PostgreSQL database. Either:
4+
//! - Create a `.env` file with `DATABASE_URL=postgres://...`
5+
//! - Or set the environment variable directly
46
//!
57
//! ```bash
6-
//! DATABASE_URL=postgres://user:pass@localhost/test cargo test --features v8,database db_
8+
//! cargo test --features v8,database db_
79
//! ```
810
//!
911
//! The tests will create and clean up their own tables.
@@ -14,8 +16,10 @@ use openworkers_task_executor::db::{DbPool, TaskCompletion};
1416
use sqlx::Row;
1517
use uuid::Uuid;
1618

17-
/// Get database URL from environment, skip test if not set
19+
/// Get database URL from environment or .env.test file
1820
fn get_database_url() -> Option<String> {
21+
// Load .env.test for tests (ignore errors if not found)
22+
let _ = dotenvy::from_filename(".env.test");
1923
std::env::var("DATABASE_URL").ok()
2024
}
2125

0 commit comments

Comments
 (0)