Skip to content

Commit

Permalink
Tests load db url from ENV (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 authored Sep 7, 2022
1 parent 3ee6317 commit 0d53346
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 29 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ jobs:
runs-on: ubuntu-20.04
needs: compile-mysql
env:
DATABASE_URL: "mysql://sea:sea@localhost/sakila"
DATABASE_URL_SAKILA: "mysql://sea:sea@localhost/sakila"
DATABASE_URL_LIVE: "mysql://sea:sea@localhost"
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -244,7 +245,8 @@ jobs:
runs-on: ubuntu-20.04
needs: compile-mysql
env:
DATABASE_URL: "mysql://sea:sea@localhost/sakila"
DATABASE_URL_SAKILA: "mysql://sea:sea@localhost/sakila"
DATABASE_URL_LIVE: "mysql://sea:sea@localhost"
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -316,7 +318,8 @@ jobs:
needs: compile-postgres
runs-on: ubuntu-20.04
env:
DATABASE_URL: "postgres://sea:sea@localhost/sakila"
DATABASE_URL_SAKILA: "postgres://sea:sea@localhost/sakila"
DATABASE_URL_LIVE: "postgres://sea:sea@localhost"
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -382,7 +385,8 @@ jobs:
needs: compile-sqlite
runs-on: ubuntu-20.04
env:
DATABASE_URL: "sqlite::memory:"
DATABASE_URL_SAKILA: "sqlite://tests/sakila/sqlite/sakila.db"
DATABASE_URL_LIVE: "sqlite::memory:"
strategy:
fail-fast: false
matrix:
Expand Down
7 changes: 4 additions & 3 deletions tests/discovery/mysql/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ async fn main() {
// .is_test(true)
// .init();

let connection = MySqlPool::connect("mysql://sea:sea@localhost/sakila")
.await
.unwrap();
let url =
std::env::var("DATABASE_URL_SAKILA").unwrap_or("mysql://root:root@localhost".to_owned());

let connection = MySqlPool::connect(&url).await.unwrap();

let schema_discovery = SchemaDiscovery::new(connection, "sakila");

Expand Down
7 changes: 4 additions & 3 deletions tests/discovery/postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ async fn main() {
// .is_test(true)
// .init();

let connection = PgPool::connect("postgres://sea:sea@localhost/sakila")
.await
.unwrap();
let url = std::env::var("DATABASE_URL_SAKILA")
.unwrap_or("postgres://root:root@localhost/sakila".to_owned());

let connection = PgPool::connect(&url).await.unwrap();

let schema_discovery = SchemaDiscovery::new(connection, "public");

Expand Down
7 changes: 4 additions & 3 deletions tests/discovery/sqlite/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use sqlx::SqlitePool;

#[async_std::main]
async fn main() -> DiscoveryResult<()> {
let connection = SqlitePool::connect("sqlite://tests/sakila/sqlite/sakila.db")
.await
.unwrap();
let url = std::env::var("DATABASE_URL_SAKILA")
.unwrap_or("sqlite://tests/sakila/sqlite/sakila.db".to_owned());

let connection = SqlitePool::connect(&url).await.unwrap();

let schema_discovery = SchemaDiscovery::new(connection);

Expand Down
5 changes: 4 additions & 1 deletion tests/live/mysql/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ async fn main() {
// .is_test(true)
// .init();

let connection = setup("mysql://sea:sea@localhost", "sea-schema").await;
let url =
std::env::var("DATABASE_URL_LIVE").unwrap_or("mysql://root:root@localhost".to_owned());

let connection = setup(&url, "sea-schema").await;
let mut executor = connection.acquire().await.unwrap();

let tbl_create_stmts = vec![
Expand Down
5 changes: 4 additions & 1 deletion tests/live/postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ async fn main() {
// .is_test(true)
// .init();

let connection = setup("postgres://sea:sea@localhost", "sea-schema").await;
let url =
std::env::var("DATABASE_URL_LIVE").unwrap_or("postgres://root:root@localhost".to_owned());

let connection = setup(&url, "sea-schema").await;
let mut executor = connection.acquire().await.unwrap();

let create_enum_stmt = Type::create()
Expand Down
11 changes: 6 additions & 5 deletions tests/live/sqlite/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ async fn main() -> DiscoveryResult<()> {
}

async fn test_001() -> DiscoveryResult<()> {
let sqlite_pool = SqlitePoolOptions::new()
.connect("sqlite::memory:")
.await
.unwrap();
let url = std::env::var("DATABASE_URL_LIVE").unwrap_or("sqlite::memory:".to_owned());

let sqlite_pool = SqlitePoolOptions::new().connect(&url).await.unwrap();

//DROP TABLES to ensure all tests pass
sqlx::query("DROP TABLE IF EXISTS Programming_Langs")
Expand Down Expand Up @@ -241,7 +240,9 @@ async fn test_001() -> DiscoveryResult<()> {
}

async fn test_002() -> DiscoveryResult<()> {
let connection = SqlitePool::connect("sqlite::memory:").await.unwrap();
let url = std::env::var("DATABASE_URL_LIVE").unwrap_or("sqlite::memory:".to_owned());

let connection = SqlitePool::connect(&url).await.unwrap();
let mut executor = connection.acquire().await.unwrap();

let tbl_create_stmts = vec![
Expand Down
7 changes: 4 additions & 3 deletions tests/writer/mysql/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ async fn main() {
// .is_test(true)
// .init();

let connection = MySqlPool::connect("mysql://sea:sea@localhost/sakila")
.await
.unwrap();
let url =
std::env::var("DATABASE_URL_SAKILA").unwrap_or("mysql://root:root@localhost".to_owned());

let connection = MySqlPool::connect(&url).await.unwrap();

let schema_discovery = SchemaDiscovery::new(connection, "sakila");

Expand Down
7 changes: 4 additions & 3 deletions tests/writer/postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ async fn main() {
// .is_test(true)
// .init();

let connection = PgPool::connect("postgres://sea:sea@localhost/sakila")
.await
.unwrap();
let url = std::env::var("DATABASE_URL_SAKILA")
.unwrap_or("postgres://root:root@localhost/sakila".to_owned());

let connection = PgPool::connect(&url).await.unwrap();

let schema_discovery = SchemaDiscovery::new(connection, "public");

Expand Down
7 changes: 4 additions & 3 deletions tests/writer/sqlite/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use sqlx::sqlite::SqlitePool;

#[async_std::main]
async fn main() -> DiscoveryResult<()> {
let sqlite_pool = SqlitePool::connect("sqlite://tests/sakila/sqlite/sakila.db")
.await
.unwrap();
let url = std::env::var("DATABASE_URL_SAKILA")
.unwrap_or("sqlite://tests/sakila/sqlite/sakila.db".to_owned());

let sqlite_pool = SqlitePool::connect(&url).await.unwrap();

let schema_discovery = SchemaDiscovery::new(sqlite_pool);

Expand Down

0 comments on commit 0d53346

Please sign in to comment.