@@ -63,21 +63,18 @@ pub fn complete<'a>(params: &'a CompletionParams<'a>) -> CompletionResult<'a> {
6363
6464#[ cfg( test) ]
6565mod tests {
66- use async_std:: task:: block_on;
6766 use pg_schema_cache:: SchemaCache ;
6867 use pg_test_utils:: test_database:: * ;
6968
70- use sqlx:: PgPool ;
69+ use sqlx:: Executor ;
7170
7271 use crate :: { complete, CompletionParams } ;
7372
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 ;
7976
80- let pool = block_on ( PgPool :: connect ( conn_string . as_str ( ) ) ) . unwrap ( ) ;
77+ let input = "select id from c;" ;
8178
8279 let mut parser = tree_sitter:: Parser :: new ( ) ;
8380 parser
@@ -86,7 +83,7 @@ mod tests {
8683
8784 let tree = parser. parse ( input, None ) . unwrap ( ) ;
8885
89- let schema_cache = block_on ( SchemaCache :: load ( & pool) ) ;
86+ let schema_cache = SchemaCache :: load ( & pool) . await ;
9087
9188 let p = CompletionParams {
9289 position : 15 . into ( ) ,
@@ -100,21 +97,19 @@ mod tests {
10097 assert ! ( result. items. len( ) > 0 ) ;
10198 }
10299
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 ;
108103
109- let pool = block_on ( PgPool :: connect ( conn_string . as_str ( ) ) ) . unwrap ( ) ;
104+ let input = "select id, name, test1231234123, unknown from co;" ;
110105
111106 let mut parser = tree_sitter:: Parser :: new ( ) ;
112107 parser
113108 . set_language ( tree_sitter_sql:: language ( ) )
114109 . expect ( "Error loading sql language" ) ;
115110
116111 let tree = parser. parse ( input, None ) . unwrap ( ) ;
117- let schema_cache = block_on ( SchemaCache :: load ( & pool) ) ;
112+ let schema_cache = SchemaCache :: load ( & pool) . await ;
118113
119114 let p = CompletionParams {
120115 position : 47 . into ( ) ,
@@ -128,8 +123,10 @@ mod tests {
128123 assert ! ( result. items. len( ) > 0 ) ;
129124 }
130125
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+
133130 let setup = r#"
134131 create table users (
135132 id serial primary key,
@@ -138,23 +135,23 @@ mod tests {
138135 );
139136 "# ;
140137
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" ) ;
145142
146- let test_db = block_on ( get_new_test_db ( conn_string , password ) ) ;
143+ let input = "select * from u" ;
147144
148145 let mut parser = tree_sitter:: Parser :: new ( ) ;
149146 parser
150147 . set_language ( tree_sitter_sql:: language ( ) )
151148 . expect ( "Error loading sql language" ) ;
152149
153150 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 ;
155152
156153 let p = CompletionParams {
157- position : 47 . into ( ) ,
154+ position : ( ( input . len ( ) - 1 ) as u32 ) . into ( ) ,
158155 schema : & schema_cache,
159156 text : input,
160157 tree : Some ( & tree) ,
0 commit comments