@@ -46,21 +46,34 @@ mod tests {
4646 );
4747 "# ;
4848
49+ fn expected_roles ( ) -> Vec < CompletionAssertion > {
50+ vec ! [
51+ CompletionAssertion :: LabelAndKind ( "anon" . into( ) , crate :: CompletionItemKind :: Role ) ,
52+ CompletionAssertion :: LabelAndKind (
53+ "authenticated" . into( ) ,
54+ crate :: CompletionItemKind :: Role ,
55+ ) ,
56+ CompletionAssertion :: LabelAndKind ( "owner" . into( ) , crate :: CompletionItemKind :: Role ) ,
57+ CompletionAssertion :: LabelAndKind (
58+ "service_role" . into( ) ,
59+ crate :: CompletionItemKind :: Role ,
60+ ) ,
61+ CompletionAssertion :: LabelAndKind (
62+ "test_login" . into( ) ,
63+ crate :: CompletionItemKind :: Role ,
64+ ) ,
65+ CompletionAssertion :: LabelAndKind (
66+ "test_nologin" . into( ) ,
67+ crate :: CompletionItemKind :: Role ,
68+ ) ,
69+ ]
70+ }
71+
4972 #[ sqlx:: test( migrator = "pgls_test_utils::MIGRATIONS" ) ]
5073 async fn works_in_drop_role ( pool : PgPool ) {
5174 assert_complete_results (
5275 format ! ( "drop role {}" , QueryWithCursorPosition :: cursor_marker( ) ) . as_str ( ) ,
53- vec ! [
54- CompletionAssertion :: LabelAndKind ( "owner" . into( ) , crate :: CompletionItemKind :: Role ) ,
55- CompletionAssertion :: LabelAndKind (
56- "test_login" . into( ) ,
57- crate :: CompletionItemKind :: Role ,
58- ) ,
59- CompletionAssertion :: LabelAndKind (
60- "test_nologin" . into( ) ,
61- crate :: CompletionItemKind :: Role ,
62- ) ,
63- ] ,
76+ expected_roles ( ) ,
6477 Some ( SETUP ) ,
6578 & pool,
6679 )
@@ -71,17 +84,7 @@ mod tests {
7184 async fn works_in_alter_role ( pool : PgPool ) {
7285 assert_complete_results (
7386 format ! ( "alter role {}" , QueryWithCursorPosition :: cursor_marker( ) ) . as_str ( ) ,
74- vec ! [
75- CompletionAssertion :: LabelAndKind ( "owner" . into( ) , crate :: CompletionItemKind :: Role ) ,
76- CompletionAssertion :: LabelAndKind (
77- "test_login" . into( ) ,
78- crate :: CompletionItemKind :: Role ,
79- ) ,
80- CompletionAssertion :: LabelAndKind (
81- "test_nologin" . into( ) ,
82- crate :: CompletionItemKind :: Role ,
83- ) ,
84- ] ,
87+ expected_roles ( ) ,
8588 Some ( SETUP ) ,
8689 & pool,
8790 )
@@ -94,17 +97,7 @@ mod tests {
9497
9598 assert_complete_results (
9699 format ! ( "set role {}" , QueryWithCursorPosition :: cursor_marker( ) ) . as_str ( ) ,
97- vec ! [
98- CompletionAssertion :: LabelAndKind ( "owner" . into( ) , crate :: CompletionItemKind :: Role ) ,
99- CompletionAssertion :: LabelAndKind (
100- "test_login" . into( ) ,
101- crate :: CompletionItemKind :: Role ,
102- ) ,
103- CompletionAssertion :: LabelAndKind (
104- "test_nologin" . into( ) ,
105- crate :: CompletionItemKind :: Role ,
106- ) ,
107- ] ,
100+ expected_roles ( ) ,
108101 None ,
109102 & pool,
110103 )
@@ -116,17 +109,7 @@ mod tests {
116109 QueryWithCursorPosition :: cursor_marker( )
117110 )
118111 . as_str ( ) ,
119- vec ! [
120- CompletionAssertion :: LabelAndKind ( "owner" . into( ) , crate :: CompletionItemKind :: Role ) ,
121- CompletionAssertion :: LabelAndKind (
122- "test_login" . into( ) ,
123- crate :: CompletionItemKind :: Role ,
124- ) ,
125- CompletionAssertion :: LabelAndKind (
126- "test_nologin" . into( ) ,
127- crate :: CompletionItemKind :: Role ,
128- ) ,
129- ] ,
112+ expected_roles ( ) ,
130113 None ,
131114 & pool,
132115 )
@@ -140,24 +123,14 @@ mod tests {
140123 assert_complete_results (
141124 format ! (
142125 r#"create policy "my cool policy" on public.users
143- as restrictive
126+ as restrictive
144127 for all
145128 to {}
146129 using (true);"# ,
147130 QueryWithCursorPosition :: cursor_marker( )
148131 )
149132 . as_str ( ) ,
150- vec ! [
151- CompletionAssertion :: LabelAndKind ( "owner" . into( ) , crate :: CompletionItemKind :: Role ) ,
152- CompletionAssertion :: LabelAndKind (
153- "test_login" . into( ) ,
154- crate :: CompletionItemKind :: Role ,
155- ) ,
156- CompletionAssertion :: LabelAndKind (
157- "test_nologin" . into( ) ,
158- crate :: CompletionItemKind :: Role ,
159- ) ,
160- ] ,
133+ expected_roles ( ) ,
161134 None ,
162135 & pool,
163136 )
@@ -171,17 +144,7 @@ mod tests {
171144 QueryWithCursorPosition :: cursor_marker( )
172145 )
173146 . as_str ( ) ,
174- vec ! [
175- CompletionAssertion :: LabelAndKind ( "owner" . into( ) , crate :: CompletionItemKind :: Role ) ,
176- CompletionAssertion :: LabelAndKind (
177- "test_login" . into( ) ,
178- crate :: CompletionItemKind :: Role ,
179- ) ,
180- CompletionAssertion :: LabelAndKind (
181- "test_nologin" . into( ) ,
182- crate :: CompletionItemKind :: Role ,
183- ) ,
184- ] ,
147+ expected_roles ( ) ,
185148 None ,
186149 & pool,
187150 )
@@ -200,18 +163,7 @@ mod tests {
200163 QueryWithCursorPosition :: cursor_marker( )
201164 )
202165 . as_str ( ) ,
203- vec ! [
204- // recognizing already mentioned roles is not supported for now
205- CompletionAssertion :: LabelAndKind ( "owner" . into( ) , crate :: CompletionItemKind :: Role ) ,
206- CompletionAssertion :: LabelAndKind (
207- "test_login" . into( ) ,
208- crate :: CompletionItemKind :: Role ,
209- ) ,
210- CompletionAssertion :: LabelAndKind (
211- "test_nologin" . into( ) ,
212- crate :: CompletionItemKind :: Role ,
213- ) ,
214- ] ,
166+ expected_roles ( ) ,
215167 None ,
216168 & pool,
217169 )
@@ -225,18 +177,7 @@ mod tests {
225177 QueryWithCursorPosition :: cursor_marker( )
226178 )
227179 . as_str ( ) ,
228- vec ! [
229- // recognizing already mentioned roles is not supported for now
230- CompletionAssertion :: LabelAndKind ( "owner" . into( ) , crate :: CompletionItemKind :: Role ) ,
231- CompletionAssertion :: LabelAndKind (
232- "test_login" . into( ) ,
233- crate :: CompletionItemKind :: Role ,
234- ) ,
235- CompletionAssertion :: LabelAndKind (
236- "test_nologin" . into( ) ,
237- crate :: CompletionItemKind :: Role ,
238- ) ,
239- ] ,
180+ expected_roles ( ) ,
240181 None ,
241182 & pool,
242183 )
@@ -248,18 +189,7 @@ mod tests {
248189 QueryWithCursorPosition :: cursor_marker( )
249190 )
250191 . as_str ( ) ,
251- vec ! [
252- // recognizing already mentioned roles is not supported for now
253- CompletionAssertion :: LabelAndKind ( "owner" . into( ) , crate :: CompletionItemKind :: Role ) ,
254- CompletionAssertion :: LabelAndKind (
255- "test_login" . into( ) ,
256- crate :: CompletionItemKind :: Role ,
257- ) ,
258- CompletionAssertion :: LabelAndKind (
259- "test_nologin" . into( ) ,
260- crate :: CompletionItemKind :: Role ,
261- ) ,
262- ] ,
192+ expected_roles ( ) ,
263193 None ,
264194 & pool,
265195 )
@@ -298,27 +228,8 @@ mod tests {
298228 ] ;
299229
300230 for query in queries {
301- assert_complete_results (
302- query. as_str ( ) ,
303- vec ! [
304- // recognizing already mentioned roles is not supported for now
305- CompletionAssertion :: LabelAndKind (
306- "owner" . into( ) ,
307- crate :: CompletionItemKind :: Role ,
308- ) ,
309- CompletionAssertion :: LabelAndKind (
310- "test_login" . into( ) ,
311- crate :: CompletionItemKind :: Role ,
312- ) ,
313- CompletionAssertion :: LabelAndKind (
314- "test_nologin" . into( ) ,
315- crate :: CompletionItemKind :: Role ,
316- ) ,
317- ] ,
318- None ,
319- & pool,
320- )
321- . await ;
231+ assert_complete_results ( query. as_str ( ) , expected_roles ( ) , None , & pool)
232+ . await ;
322233 }
323234 }
324235}
0 commit comments