@@ -63,21 +63,18 @@ pub fn complete<'a>(params: &'a CompletionParams<'a>) -> CompletionResult<'a> {
63
63
64
64
#[ cfg( test) ]
65
65
mod tests {
66
- use async_std:: task:: block_on;
67
66
use pg_schema_cache:: SchemaCache ;
68
67
use pg_test_utils:: test_database:: * ;
69
68
70
- use sqlx:: PgPool ;
69
+ use sqlx:: Executor ;
71
70
72
71
use crate :: { complete, CompletionParams } ;
73
72
74
- #[ test]
75
- fn test_complete ( ) {
76
- let input = "select id from c;" ;
77
-
78
- let conn_string = std:: env:: var ( "DB_CONNECTION_STRING" ) . unwrap ( ) ;
73
+ #[ tokio:: test]
74
+ async fn test_complete ( ) {
75
+ let pool = get_new_test_db ( ) . await ;
79
76
80
- let pool = block_on ( PgPool :: connect ( conn_string . as_str ( ) ) ) . unwrap ( ) ;
77
+ let input = "select id from c;" ;
81
78
82
79
let mut parser = tree_sitter:: Parser :: new ( ) ;
83
80
parser
@@ -86,7 +83,7 @@ mod tests {
86
83
87
84
let tree = parser. parse ( input, None ) . unwrap ( ) ;
88
85
89
- let schema_cache = block_on ( SchemaCache :: load ( & pool) ) ;
86
+ let schema_cache = SchemaCache :: load ( & pool) . await ;
90
87
91
88
let p = CompletionParams {
92
89
position : 15 . into ( ) ,
@@ -100,21 +97,19 @@ mod tests {
100
97
assert ! ( result. items. len( ) > 0 ) ;
101
98
}
102
99
103
- #[ test]
104
- fn test_complete_two ( ) {
105
- let input = "select id, name, test1231234123, unknown from co;" ;
106
-
107
- let conn_string = std:: env:: var ( "DB_CONNECTION_STRING" ) . unwrap ( ) ;
100
+ #[ tokio:: test]
101
+ async fn test_complete_two ( ) {
102
+ let pool = get_new_test_db ( ) . await ;
108
103
109
- let pool = block_on ( PgPool :: connect ( conn_string . as_str ( ) ) ) . unwrap ( ) ;
104
+ let input = "select id, name, test1231234123, unknown from co;" ;
110
105
111
106
let mut parser = tree_sitter:: Parser :: new ( ) ;
112
107
parser
113
108
. set_language ( tree_sitter_sql:: language ( ) )
114
109
. expect ( "Error loading sql language" ) ;
115
110
116
111
let tree = parser. parse ( input, None ) . unwrap ( ) ;
117
- let schema_cache = block_on ( SchemaCache :: load ( & pool) ) ;
112
+ let schema_cache = SchemaCache :: load ( & pool) . await ;
118
113
119
114
let p = CompletionParams {
120
115
position : 47 . into ( ) ,
@@ -128,8 +123,10 @@ mod tests {
128
123
assert ! ( result. items. len( ) > 0 ) ;
129
124
}
130
125
131
- #[ test]
132
- fn test_complete_with_db ( ) {
126
+ #[ tokio:: test]
127
+ async fn test_complete_with_db ( ) {
128
+ let test_db = get_new_test_db ( ) . await ;
129
+
133
130
let setup = r#"
134
131
create table users (
135
132
id serial primary key,
@@ -138,23 +135,23 @@ mod tests {
138
135
);
139
136
"# ;
140
137
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 ( ) ) ;
138
+ test_db
139
+ . execute ( setup )
140
+ . await
141
+ . expect ( "Failed to execute setup query" ) ;
145
142
146
- let test_db = block_on ( get_new_test_db ( conn_string , password ) ) ;
143
+ let input = "select * from u" ;
147
144
148
145
let mut parser = tree_sitter:: Parser :: new ( ) ;
149
146
parser
150
147
. set_language ( tree_sitter_sql:: language ( ) )
151
148
. expect ( "Error loading sql language" ) ;
152
149
153
150
let tree = parser. parse ( input, None ) . unwrap ( ) ;
154
- let schema_cache = block_on ( SchemaCache :: load ( & pool ) ) ;
151
+ let schema_cache = SchemaCache :: load ( & test_db ) . await ;
155
152
156
153
let p = CompletionParams {
157
- position : 47 . into ( ) ,
154
+ position : ( ( input . len ( ) - 1 ) as u32 ) . into ( ) ,
158
155
schema : & schema_cache,
159
156
text : input,
160
157
tree : Some ( & tree) ,
0 commit comments