Skip to content

Commit 0753b50

Browse files
better
1 parent 9021bc0 commit 0753b50

File tree

4 files changed

+45
-25
lines changed

4 files changed

+45
-25
lines changed

crates/pgt_completions/src/test_helper.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::Display;
22

33
use pgt_schema_cache::SchemaCache;
4-
use pgt_test_utils::test_database::get_new_test_db;
4+
use sqlx::{Executor, PgPool};
55

66
use crate::{CompletionItem, CompletionItemKind, CompletionParams, complete};
77

@@ -35,9 +35,8 @@ impl Display for InputQuery {
3535
pub(crate) async fn get_test_deps(
3636
setup: &str,
3737
input: InputQuery,
38+
test_db: &PgPool,
3839
) -> (tree_sitter::Tree, pgt_schema_cache::SchemaCache) {
39-
let test_db = get_new_test_db().await;
40-
4140
test_db
4241
.execute(setup)
4342
.await
@@ -206,8 +205,9 @@ pub(crate) async fn assert_complete_results(
206205
query: &str,
207206
assertions: Vec<CompletionAssertion>,
208207
setup: &str,
208+
pool: &PgPool,
209209
) {
210-
let (tree, cache) = get_test_deps(setup, query.into()).await;
210+
let (tree, cache) = get_test_deps(setup, query.into(), pool).await;
211211
let params = get_test_params(&tree, &cache, query.into());
212212
let items = complete(params);
213213

@@ -240,8 +240,8 @@ pub(crate) async fn assert_complete_results(
240240
});
241241
}
242242

243-
pub(crate) async fn assert_no_complete_results(query: &str, setup: &str) {
244-
let (tree, cache) = get_test_deps(setup, query.into()).await;
243+
pub(crate) async fn assert_no_complete_results(query: &str, setup: &str, pool: &PgPool) {
244+
let (tree, cache) = get_test_deps(setup, query.into(), pool).await;
245245
let params = get_test_params(&tree, &cache, query.into());
246246
let items = complete(params);
247247

crates/pgt_lsp/tests/server.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ use pgt_configuration::database::PartialDatabaseConfiguration;
1313
use pgt_fs::MemoryFileSystem;
1414
use pgt_lsp::LSPServer;
1515
use pgt_lsp::ServerFactory;
16-
use pgt_test_utils::test_database::get_new_test_db;
1716
use pgt_workspace::DynRef;
1817
use serde::Serialize;
1918
use serde::de::DeserializeOwned;
2019
use serde_json::Value;
2120
use serde_json::{from_value, to_value};
21+
use sqlx::Executor;
22+
use sqlx::PgPool;
2223
use std::any::type_name;
2324
use std::fmt::Display;
2425
use std::time::Duration;
@@ -344,11 +345,10 @@ async fn basic_lifecycle() -> Result<()> {
344345
Ok(())
345346
}
346347

347-
#[tokio::test]
348-
async fn test_database_connection() -> Result<()> {
348+
#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")]
349+
async fn test_database_connection(test_db: PgPool) -> Result<()> {
349350
let factory = ServerFactory::default();
350351
let mut fs = MemoryFileSystem::default();
351-
let test_db = get_new_test_db().await;
352352

353353
let setup = r#"
354354
create table public.users (
@@ -456,11 +456,10 @@ async fn server_shutdown() -> Result<()> {
456456
Ok(())
457457
}
458458

459-
#[tokio::test]
460-
async fn test_completions() -> Result<()> {
459+
#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")]
460+
async fn test_completions(test_db: PgPool) -> Result<()> {
461461
let factory = ServerFactory::default();
462462
let mut fs = MemoryFileSystem::default();
463-
let test_db = get_new_test_db().await;
464463

465464
let setup = r#"
466465
create table public.users (
@@ -557,11 +556,10 @@ async fn test_completions() -> Result<()> {
557556
Ok(())
558557
}
559558

560-
#[tokio::test]
561-
async fn test_issue_271() -> Result<()> {
559+
#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")]
560+
async fn test_issue_271(test_db: PgPool) -> Result<()> {
562561
let factory = ServerFactory::default();
563562
let mut fs = MemoryFileSystem::default();
564-
let test_db = get_new_test_db().await;
565563

566564
let setup = r#"
567565
create table public.users (
@@ -759,11 +757,10 @@ async fn test_issue_271() -> Result<()> {
759757
Ok(())
760758
}
761759

762-
#[tokio::test]
763-
async fn test_execute_statement() -> Result<()> {
760+
#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")]
761+
async fn test_execute_statement(test_db: PgPool) -> Result<()> {
764762
let factory = ServerFactory::default();
765763
let mut fs = MemoryFileSystem::default();
766-
let test_db = get_new_test_db().await;
767764

768765
let database = test_db
769766
.connect_options()
@@ -898,11 +895,10 @@ async fn test_execute_statement() -> Result<()> {
898895
Ok(())
899896
}
900897

901-
#[tokio::test]
902-
async fn test_issue_281() -> Result<()> {
898+
#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")]
899+
async fn test_issue_281(test_db: PgPool) -> Result<()> {
903900
let factory = ServerFactory::default();
904901
let mut fs = MemoryFileSystem::default();
905-
let test_db = get_new_test_db().await;
906902

907903
let setup = r#"
908904
create table public.users (
@@ -982,11 +978,10 @@ async fn test_issue_281() -> Result<()> {
982978
Ok(())
983979
}
984980

985-
#[tokio::test]
986-
async fn test_issue_303() -> Result<()> {
981+
#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")]
982+
async fn test_issue_303(test_db: PgPool) -> Result<()> {
987983
let factory = ServerFactory::default();
988984
let mut fs = MemoryFileSystem::default();
989-
let test_db = get_new_test_db().await;
990985

991986
let setup = r#"
992987
create table public.users (

crates/pgt_test_utils/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
pub mod test_database;
2+
3+
pub static MIGRATIONS: sqlx::migrate::Migrator = sqlx::migrate!("./testdb_migrations");
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
do $$
2+
begin
3+
if not exists (
4+
select from pg_catalog.pg_roles
5+
where rolname = 'admin'
6+
) then
7+
create role admin superuser createdb login bypassrls;
8+
end if;
9+
10+
if not exists (
11+
select from pg_catalog.pg_roles
12+
where rolname = 'test_login'
13+
) then
14+
create role test_login login;
15+
end if;
16+
17+
if not exists (
18+
select from pg_catalog.pg_roles
19+
where rolname = 'test_nologin'
20+
) then
21+
create role test_nologin;
22+
end if;
23+
end;

0 commit comments

Comments
 (0)