Skip to content

Commit 254f4a5

Browse files
committed
Use dotenvy for tests, so you can set DATABASE_URL in .env.
1 parent 6fa5248 commit 254f4a5

File tree

7 files changed

+21
-0
lines changed

7 files changed

+21
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
target
22
.DS_Store
3+
.env

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ tokio-postgres = "0.7"
2424

2525
[dev-dependencies]
2626
chrono = "0.4"
27+
dotenvy = "0.15"
2728
macrotest = "1.1"
2829
serial_test = "3.2"
2930
tokio = { version = "1.43", features = ["full"] }

benches/bucket_size.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ mod bucket_size {
1717
use bucket_size::*;
1818

1919
static DB_POOL: std::sync::LazyLock<std::sync::Arc<deadpool_postgres::Pool>> = std::sync::LazyLock::new(|| {
20+
if std::path::Path::new(".env").exists() {
21+
dotenvy::dotenv().unwrap();
22+
}
2023
let url = std::env::var("DATABASE_URL").unwrap_or("postgresql://localhost:5432/postgres".to_string());
2124
let pg_config = tokio_postgres::Config::from_str(&url).unwrap();
2225
let mgr_config = deadpool_postgres::ManagerConfig { recycling_method: deadpool_postgres::RecyclingMethod::Fast };

benches/comparison.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ mod comparison {
1818
use comparison::*;
1919

2020
static DB_POOL: std::sync::LazyLock<std::sync::Arc<deadpool_postgres::Pool>> = std::sync::LazyLock::new(|| {
21+
if std::path::Path::new(".env").exists() {
22+
dotenvy::dotenv().unwrap();
23+
}
2124
let url = std::env::var("DATABASE_URL").unwrap_or("postgresql://localhost:5432/postgres".to_string());
2225
let pg_config = tokio_postgres::Config::from_str(&url).unwrap();
2326
let mgr_config = deadpool_postgres::ManagerConfig { recycling_method: deadpool_postgres::RecyclingMethod::Fast };

benches/float.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ mod float {
1717
use float::*;
1818

1919
static DB_POOL: std::sync::LazyLock<std::sync::Arc<deadpool_postgres::Pool>> = std::sync::LazyLock::new(|| {
20+
if std::path::Path::new(".env").exists() {
21+
dotenvy::dotenv().unwrap();
22+
}
2023
let url = std::env::var("DATABASE_URL").unwrap_or("postgresql://localhost:5432/postgres".to_string());
2124
let pg_config = tokio_postgres::Config::from_str(&url).unwrap();
2225
let mgr_config = deadpool_postgres::ManagerConfig { recycling_method: deadpool_postgres::RecyclingMethod::Fast };

tests/tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ fn macrotest() {
1111
}
1212

1313
pub static DB_POOL: std::sync::LazyLock<std::sync::Arc<deadpool_postgres::Pool>> = std::sync::LazyLock::new(|| {
14+
if std::path::Path::new(".env").exists() {
15+
dotenvy::dotenv().unwrap();
16+
}
1417
let url = std::env::var("DATABASE_URL").unwrap_or("postgresql://localhost:5432/postgres".to_string());
1518
let pg_config = tokio_postgres::Config::from_str(&url).unwrap();
1619
let mgr_config = deadpool_postgres::ManagerConfig { recycling_method: deadpool_postgres::RecyclingMethod::Fast };

0 commit comments

Comments
 (0)