Skip to content

Commit 1be61b4

Browse files
ok
1 parent 0753b50 commit 1be61b4

File tree

11 files changed

+246
-289
lines changed

11 files changed

+246
-289
lines changed

crates/pgt_completions/src/providers/columns.rs

Lines changed: 87 additions & 50 deletions
Large diffs are not rendered by default.

crates/pgt_completions/src/providers/functions.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ fn get_completion_text(ctx: &CompletionContext, func: &Function) -> CompletionTe
6565

6666
#[cfg(test)]
6767
mod tests {
68+
use sqlx::PgPool;
69+
6870
use crate::{
6971
CompletionItem, CompletionItemKind, complete,
7072
test_helper::{CURSOR_POS, get_test_deps, get_test_params},
7173
};
7274

73-
#[tokio::test]
74-
async fn completes_fn() {
75+
#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")]
76+
async fn completes_fn(pool: PgPool) {
7577
let setup = r#"
7678
create or replace function cool()
7779
returns trigger
@@ -86,7 +88,7 @@ mod tests {
8688

8789
let query = format!("select coo{}", CURSOR_POS);
8890

89-
let (tree, cache) = get_test_deps(setup, query.as_str().into()).await;
91+
let (tree, cache) = get_test_deps(Some(setup), query.as_str().into(), &pool).await;
9092
let params = get_test_params(&tree, &cache, query.as_str().into());
9193
let results = complete(params);
9294

@@ -98,8 +100,8 @@ mod tests {
98100
assert_eq!(label, "cool");
99101
}
100102

101-
#[tokio::test]
102-
async fn prefers_fn_if_invocation() {
103+
#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")]
104+
async fn prefers_fn_if_invocation(pool: PgPool) {
103105
let setup = r#"
104106
create table coos (
105107
id serial primary key,
@@ -119,7 +121,7 @@ mod tests {
119121

120122
let query = format!(r#"select * from coo{}()"#, CURSOR_POS);
121123

122-
let (tree, cache) = get_test_deps(setup, query.as_str().into()).await;
124+
let (tree, cache) = get_test_deps(Some(setup), query.as_str().into(), &pool).await;
123125
let params = get_test_params(&tree, &cache, query.as_str().into());
124126
let results = complete(params);
125127

@@ -132,8 +134,8 @@ mod tests {
132134
assert_eq!(kind, CompletionItemKind::Function);
133135
}
134136

135-
#[tokio::test]
136-
async fn prefers_fn_in_select_clause() {
137+
#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")]
138+
async fn prefers_fn_in_select_clause(pool: PgPool) {
137139
let setup = r#"
138140
create table coos (
139141
id serial primary key,
@@ -153,7 +155,7 @@ mod tests {
153155

154156
let query = format!(r#"select coo{}"#, CURSOR_POS);
155157

156-
let (tree, cache) = get_test_deps(setup, query.as_str().into()).await;
158+
let (tree, cache) = get_test_deps(Some(setup), query.as_str().into(), &pool).await;
157159
let params = get_test_params(&tree, &cache, query.as_str().into());
158160
let results = complete(params);
159161

@@ -166,8 +168,8 @@ mod tests {
166168
assert_eq!(kind, CompletionItemKind::Function);
167169
}
168170

169-
#[tokio::test]
170-
async fn prefers_function_in_from_clause_if_invocation() {
171+
#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")]
172+
async fn prefers_function_in_from_clause_if_invocation(pool: PgPool) {
171173
let setup = r#"
172174
create table coos (
173175
id serial primary key,
@@ -187,7 +189,7 @@ mod tests {
187189

188190
let query = format!(r#"select * from coo{}()"#, CURSOR_POS);
189191

190-
let (tree, cache) = get_test_deps(setup, query.as_str().into()).await;
192+
let (tree, cache) = get_test_deps(Some(setup), query.as_str().into(), &pool).await;
191193
let params = get_test_params(&tree, &cache, query.as_str().into());
192194
let results = complete(params);
193195

crates/pgt_completions/src/providers/policies.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ pub fn complete_policies<'a>(ctx: &CompletionContext<'a>, builder: &mut Completi
5959

6060
#[cfg(test)]
6161
mod tests {
62+
use sqlx::{Executor, PgPool};
63+
6264
use crate::test_helper::{CURSOR_POS, CompletionAssertion, assert_complete_results};
6365

64-
#[tokio::test]
65-
async fn completes_within_quotation_marks() {
66+
#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")]
67+
async fn completes_within_quotation_marks(pool: PgPool) {
6668
let setup = r#"
6769
create schema private;
6870
@@ -84,13 +86,16 @@ mod tests {
8486
with check (true);
8587
"#;
8688

89+
pool.execute(setup).await.unwrap();
90+
8791
assert_complete_results(
8892
format!("alter policy \"{}\" on private.users;", CURSOR_POS).as_str(),
8993
vec![
9094
CompletionAssertion::Label("read for public users disallowed".into()),
9195
CompletionAssertion::Label("write for public users allowed".into()),
9296
],
93-
setup,
97+
None,
98+
&pool,
9499
)
95100
.await;
96101

@@ -99,7 +104,8 @@ mod tests {
99104
vec![CompletionAssertion::Label(
100105
"write for public users allowed".into(),
101106
)],
102-
setup,
107+
None,
108+
&pool,
103109
)
104110
.await;
105111
}

crates/pgt_completions/src/providers/schemas.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ pub fn complete_schemas<'a>(ctx: &'a CompletionContext, builder: &mut Completion
2727
#[cfg(test)]
2828
mod tests {
2929

30+
use sqlx::PgPool;
31+
3032
use crate::{
3133
CompletionItemKind,
3234
test_helper::{CURSOR_POS, CompletionAssertion, assert_complete_results},
3335
};
3436

35-
#[tokio::test]
36-
async fn autocompletes_schemas() {
37+
#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")]
38+
async fn autocompletes_schemas(pool: PgPool) {
3739
let setup = r#"
3840
create schema private;
3941
create schema auth;
@@ -75,13 +77,14 @@ mod tests {
7577
CompletionItemKind::Schema,
7678
),
7779
],
78-
setup,
80+
Some(setup),
81+
&pool,
7982
)
8083
.await;
8184
}
8285

83-
#[tokio::test]
84-
async fn suggests_tables_and_schemas_with_matching_keys() {
86+
#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")]
87+
async fn suggests_tables_and_schemas_with_matching_keys(pool: PgPool) {
8588
let setup = r#"
8689
create schema ultimate;
8790
@@ -99,7 +102,8 @@ mod tests {
99102
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
100103
CompletionAssertion::LabelAndKind("ultimate".into(), CompletionItemKind::Schema),
101104
],
102-
setup,
105+
Some(setup),
106+
&pool,
103107
)
104108
.await;
105109
}

0 commit comments

Comments
 (0)