Skip to content

Commit 3dd93bc

Browse files
committed
Tests: one test database URL (app::testing::database_url, VISUALCI_APP_TEST_DATABASE_URL else CI's), so the live transport's test reaches CI's Postgres instead of the dev box's user
1 parent 23817f6 commit 3dd93bc

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎app/src/testing.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ pub fn create() -> Application {
1313
configure().create()
1414
}
1515

16+
/// The test database: `VISUALCI_APP_TEST_DATABASE_URL`, else CI's.
17+
#[must_use]
18+
pub fn database_url() -> String {
19+
std::env::var("VISUALCI_APP_TEST_DATABASE_URL").unwrap_or_else(|_| CI_DATABASE.to_string())
20+
}
21+
1622
pub fn configure() -> ApplicationBuilder {
17-
let url = std::env::var("VISUALCI_APP_TEST_DATABASE_URL").unwrap_or_else(|_| CI_DATABASE.to_string());
23+
let url = database_url();
1824
crate::configure()
1925
.for_testing(env!("CARGO_MANIFEST_DIR"))
2026
.with_envs([

‎app/tests/hosts.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn in_production() -> laravel::foundation::ApplicationBuilder {
3838
("CACHE_STORE", "memory"),
3939
("QUEUE_CONNECTION", "sync"),
4040
("DB_CONNECTION", "pgsql"),
41-
("DATABASE_URL", "postgres://loco:loco@127.0.0.1:55433/visualci_app_test"),
41+
("DATABASE_URL", app::testing::database_url().as_str()),
4242
("S3_ENDPOINT", "http://127.0.0.1:59000"),
4343
("S3_BUCKET", "visualci-test"),
4444
("S3_ACCESS_KEY_ID", "visualci"),

‎app/tests/live.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use sqlx::Connection;
88
/// The test server's `postgres` database: LISTEN and NOTIFY only need both sides on one database, and the tests' own
99
/// databases are per-test copies.
1010
fn database() -> String {
11-
let url = std::env::var("VISUALCI_APP_TEST_DATABASE_URL")
12-
.unwrap_or_else(|_| "postgres://loco:loco@127.0.0.1:55433/visualci_app_test".to_string());
11+
let url = app::testing::database_url();
1312
let server = url.rsplit_once('/').map_or(url.as_str(), |(server, _)| server);
1413
format!("{server}/postgres")
1514
}

0 commit comments

Comments
 (0)