@@ -77,7 +77,6 @@ pub fn meilisearch_test(params: TokenStream, input: TokenStream) -> TokenStream
77
77
let use_name = params
78
78
. iter ( )
79
79
. any ( |param| matches ! ( param, Param :: String | Param :: Index ) ) ;
80
- let use_index = params. contains ( & Param :: Index ) ;
81
80
82
81
// Now we are going to build the body of the outer function
83
82
let mut outer_block: Vec < Stmt > = Vec :: new ( ) ;
@@ -106,59 +105,77 @@ pub fn meilisearch_test(params: TokenStream, input: TokenStream) -> TokenStream
106
105
) ) ;
107
106
}
108
107
108
+ let index_var = |idx : usize | Ident :: new ( & format ! ( "index_{idx}" ) , Span :: call_site ( ) ) ;
109
+
109
110
// And finally if an index was asked, we delete it, and we (re)create it and wait until meilisearch confirm its creation.
110
- if use_index {
111
- outer_block. push ( parse_quote ! ( {
112
- let res = client
113
- . delete_index( & name)
114
- . await
115
- . expect( "Network issue while sending the delete index task" )
116
- . wait_for_completion( & client, None , None )
117
- . await
118
- . expect( "Network issue while waiting for the index deletion" ) ;
119
- if res. is_failure( ) {
120
- let error = res. unwrap_failure( ) ;
121
- assert_eq!(
122
- error. error_code,
123
- crate :: errors:: ErrorCode :: IndexNotFound ,
124
- "{:?}" ,
125
- error
126
- ) ;
127
- }
128
- } ) ) ;
111
+ for ( i, param) in params. iter ( ) . enumerate ( ) {
112
+ if !matches ! ( param, Param :: Index ) {
113
+ continue ;
114
+ }
129
115
116
+ let var_name = index_var ( i) ;
130
117
outer_block. push ( parse_quote ! (
131
- let index = client
132
- . create_index( & name, None )
133
- . await
134
- . expect( "Network issue while sending the create index task" )
135
- . wait_for_completion( & client, None , None )
136
- . await
137
- . expect( "Network issue while waiting for the index creation" )
138
- . try_make_index( & client)
139
- . expect( "Could not create the index out of the create index task" ) ;
118
+ let #var_name = {
119
+ let index_uid = format!( "{name}_{}" , #i) ;
120
+ let res = client
121
+ . delete_index( & index_uid)
122
+ . await
123
+ . expect( "Network issue while sending the delete index task" )
124
+ . wait_for_completion( & client, None , None )
125
+ . await
126
+ . expect( "Network issue while waiting for the index deletion" ) ;
127
+
128
+ if res. is_failure( ) {
129
+ let error = res. unwrap_failure( ) ;
130
+ assert_eq!(
131
+ error. error_code,
132
+ crate :: errors:: ErrorCode :: IndexNotFound ,
133
+ "{:?}" ,
134
+ error
135
+ ) ;
136
+ }
137
+
138
+ client
139
+ . create_index( & index_uid, None )
140
+ . await
141
+ . expect( "Network issue while sending the create index task" )
142
+ . wait_for_completion( & client, None , None )
143
+ . await
144
+ . expect( "Network issue while waiting for the index creation" )
145
+ . try_make_index( & client)
146
+ . expect( "Could not create the index out of the create index task" )
147
+ } ;
140
148
) ) ;
141
149
}
142
150
143
151
// Create a list of params separated by comma with the name we defined previously.
144
- let params: Vec < Expr > = params
145
- . into_iter ( )
146
- . map ( |param| match param {
152
+ let args: Vec < Expr > = params
153
+ . iter ( )
154
+ . enumerate ( )
155
+ . map ( |( i, param) | match param {
147
156
Param :: Client => parse_quote ! ( client) ,
148
- Param :: Index => parse_quote ! ( index) ,
157
+ Param :: Index => {
158
+ let var = index_var ( i) ;
159
+ parse_quote ! ( #var)
160
+ }
149
161
Param :: String => parse_quote ! ( name) ,
150
162
} )
151
163
. collect ( ) ;
152
164
153
165
// Now we can call the user code with our parameters :tada:
154
166
outer_block. push ( parse_quote ! (
155
- let result = #inner_ident( #( #params . clone( ) ) , * ) . await ;
167
+ let result = #inner_ident( #( #args . clone( ) ) , * ) . await ;
156
168
) ) ;
157
169
158
170
// And right before the end, if an index was created and the tests successfully executed we delete it.
159
- if use_index {
171
+ for ( i, param) in params. iter ( ) . enumerate ( ) {
172
+ if !matches ! ( param, Param :: Index ) {
173
+ continue ;
174
+ }
175
+
176
+ let var_name = index_var ( i) ;
160
177
outer_block. push ( parse_quote ! (
161
- index
178
+ #var_name
162
179
. delete( )
163
180
. await
164
181
. expect( "Network issue while sending the last delete index task" ) ;
0 commit comments