Skip to content

Commit 0838015

Browse files
test: introduce test-db
1 parent 218d6b7 commit 0838015

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

crates/pg_completions/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ edition = "2021"
55

66
[dependencies]
77
async-std = "1.12.0"
8-
sqlx = { version = "0.7.3", features = [ "runtime-async-std", "tls-rustls", "postgres", "json" ] }
98

109
text-size = "1.1.1"
1110

1211
tree-sitter.workspace = true
1312
tree_sitter_sql.workspace = true
1413
pg_schema_cache.workspace = true
14+
pg_test_utils.workspace = true
1515

16-
[dev-dependencies]
16+
sqlx.workspace = true
17+
tokio = { version = "1.41.1", features = ["full"] }
1718

1819
[lib]
1920
doctest = false

crates/pg_completions/src/lib.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ pub fn complete<'a>(params: &'a CompletionParams<'a>) -> CompletionResult<'a> {
6565
mod tests {
6666
use async_std::task::block_on;
6767
use pg_schema_cache::SchemaCache;
68+
use pg_test_utils::test_database::*;
69+
6870
use sqlx::PgPool;
6971

7072
use crate::{complete, CompletionParams};
@@ -125,4 +127,41 @@ mod tests {
125127

126128
assert!(result.items.len() > 0);
127129
}
130+
131+
#[test]
132+
fn test_complete_with_db() {
133+
let setup = r#"
134+
create table users (
135+
id serial primary key,
136+
name text,
137+
password text
138+
);
139+
"#;
140+
141+
let input = "select * from u";
142+
143+
let conn_string = std::env::var("DB_CONNECTION_STRING").unwrap();
144+
let password = std::env::var("DB_PASSWORD").unwrap_or("postgres".into());
145+
146+
let test_db = block_on(get_new_test_db(conn_string, password));
147+
148+
let mut parser = tree_sitter::Parser::new();
149+
parser
150+
.set_language(tree_sitter_sql::language())
151+
.expect("Error loading sql language");
152+
153+
let tree = parser.parse(input, None).unwrap();
154+
let schema_cache = block_on(SchemaCache::load(&pool));
155+
156+
let p = CompletionParams {
157+
position: 47.into(),
158+
schema: &schema_cache,
159+
text: input,
160+
tree: Some(&tree),
161+
};
162+
163+
let result = complete(&p);
164+
165+
assert!(result.items.len() > 0);
166+
}
128167
}

0 commit comments

Comments
 (0)