Skip to content

Commit 59b8065

Browse files
fix?: use test db in tests
1 parent 6c67271 commit 59b8065

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

Cargo.lock

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

crates/pg_schema_cache/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ serde.workspace = true
1919
serde_json.workspace = true
2020
pg_diagnostics.workspace = true
2121
pg_console.workspace = true
22-
2322
sqlx.workspace = true
2423

24+
[dev-dependencies]
25+
pg_test_utils.workspace = true
26+
2527
[lib]
2628
doctest = false

crates/pg_schema_cache/src/schema_cache.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,16 @@ pub trait SchemaCacheItem {
7575

7676
#[cfg(test)]
7777
mod tests {
78-
use sqlx::PgPool;
78+
use async_std::task::block_on;
79+
use pg_test_utils::test_database::get_new_test_db;
7980

8081
use crate::SchemaCache;
8182

8283
#[test]
8384
fn test_schema_cache() {
84-
let conn_string = std::env::var("DATABASE_URL").unwrap();
85+
let test_db = block_on(get_new_test_db());
8586

86-
let pool = async_std::task::block_on(PgPool::connect(conn_string.as_str())).unwrap();
87-
88-
async_std::task::block_on(SchemaCache::load(&pool)).expect("Couldn't load Schema Cache");
87+
block_on(SchemaCache::load(&test_db)).expect("Couldn't load Schema Cache");
8988

9089
assert!(true);
9190
}

crates/pg_typecheck/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ async-std = "1.12.0"
2424

2525

2626
[dev-dependencies]
27+
pg_test_utils.workspace = true
2728

2829
[lib]
2930
doctest = false

crates/pg_typecheck/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,21 @@ pub async fn check_sql<'a>(params: TypecheckerParams<'a>) -> Vec<TypeError> {
8585
#[cfg(test)]
8686
mod tests {
8787
use async_std::task::block_on;
88-
use sqlx::PgPool;
88+
use pg_test_utils::test_database::get_new_test_db;
8989

9090
use crate::{check_sql, TypecheckerParams};
9191

9292
#[test]
93-
fn test_check_sql() {
93+
fn test_basic_type() {
9494
let input = "select id, unknown from contact;";
9595

96-
let conn_string = std::env::var("DATABASE_URL").unwrap();
97-
98-
let pool = block_on(PgPool::connect(conn_string.as_str())).unwrap();
96+
let test_db = block_on(get_new_test_db());
9997

10098
let root = pg_query_ext::parse(input).unwrap();
10199
let ast = pg_syntax::parse_syntax(input, &root).ast;
102100

103101
let errs = block_on(check_sql(TypecheckerParams {
104-
conn: &pool,
102+
conn: &test_db,
105103
sql: input,
106104
ast: &root,
107105
enriched_ast: Some(&ast),
@@ -111,6 +109,6 @@ mod tests {
111109

112110
let e = &errs[0];
113111

114-
assert_eq!(&input[e.range.unwrap()], "unknown");
112+
assert_eq!(&input[e.range.unwrap()], "contact");
115113
}
116114
}

0 commit comments

Comments
 (0)