11use std:: collections:: HashMap ;
22
33use async_trait:: async_trait;
4- use spin_expressions:: { provider :: ProviderVariableKind , Key , Provider , ProviderResolver } ;
4+ use spin_expressions:: { Key , Provider , ProviderResolver } ;
55use spin_locked_app:: Variable ;
66
77#[ derive( Default ) ]
@@ -43,23 +43,23 @@ impl ResolverTester {
4343 }
4444}
4545
46- #[ tokio :: test( flavor = "multi_thread" ) ]
47- async fn if_single_static_provider_with_no_key_to_resolve_is_valid ( ) -> anyhow:: Result < ( ) > {
46+ #[ test]
47+ fn if_single_static_provider_with_no_key_to_resolve_is_valid ( ) -> anyhow:: Result < ( ) > {
4848 let resolver = ResolverTester :: new ( )
4949 . with_provider ( StaticProvider :: with_variable (
5050 "database_host" ,
5151 Some ( "localhost" ) ,
5252 ) )
5353 . make_resolver ( ) ?;
5454
55- resolver. ensure_required_variables_resolvable ( ) . await ?;
55+ resolver. ensure_required_variables_resolvable ( ) ?;
5656
5757 Ok ( ( ) )
5858}
5959
60- #[ tokio :: test( flavor = "multi_thread" ) ]
61- async fn if_single_static_provider_has_data_for_variable_key_to_resolve_it_succeeds (
62- ) -> anyhow :: Result < ( ) > {
60+ #[ test]
61+ fn if_single_static_provider_has_data_for_variable_key_to_resolve_it_succeeds ( ) -> anyhow :: Result < ( ) >
62+ {
6363 let resolver = ResolverTester :: new ( )
6464 . with_provider ( StaticProvider :: with_variable (
6565 "database_host" ,
@@ -68,13 +68,13 @@ async fn if_single_static_provider_has_data_for_variable_key_to_resolve_it_succe
6868 . with_variable ( "database_host" , None )
6969 . make_resolver ( ) ?;
7070
71- resolver. ensure_required_variables_resolvable ( ) . await ?;
71+ resolver. ensure_required_variables_resolvable ( ) ?;
7272
7373 Ok ( ( ) )
7474}
7575
76- #[ tokio :: test( flavor = "multi_thread" ) ]
77- async fn if_there_is_a_single_static_provider_and_it_does_not_contain_a_required_variable_then_validation_fails (
76+ #[ test]
77+ fn if_there_is_a_single_static_provider_and_it_does_not_contain_a_required_variable_then_validation_fails (
7878) -> anyhow:: Result < ( ) > {
7979 let resolver = ResolverTester :: new ( )
8080 . with_provider ( StaticProvider :: with_variable (
@@ -84,29 +84,26 @@ async fn if_there_is_a_single_static_provider_and_it_does_not_contain_a_required
8484 . with_variable ( "api_key" , None )
8585 . make_resolver ( ) ?;
8686
87- assert ! ( resolver
88- . ensure_required_variables_resolvable( )
89- . await
90- . is_err( ) ) ;
87+ assert ! ( resolver. ensure_required_variables_resolvable( ) . is_err( ) ) ;
9188
9289 Ok ( ( ) )
9390}
9491
95- #[ tokio :: test( flavor = "multi_thread" ) ]
96- async fn if_there_is_a_dynamic_provider_then_validation_succeeds_even_without_default_value_in_play (
92+ #[ test]
93+ fn if_there_is_a_dynamic_provider_then_validation_succeeds_even_without_default_value_in_play (
9794) -> anyhow:: Result < ( ) > {
9895 let resolver = ResolverTester :: new ( )
9996 . with_provider ( DynamicProvider )
10097 . with_variable ( "api_key" , None )
10198 . make_resolver ( ) ?;
10299
103- resolver. ensure_required_variables_resolvable ( ) . await ?;
100+ resolver. ensure_required_variables_resolvable ( ) ?;
104101
105102 Ok ( ( ) )
106103}
107104
108- #[ tokio :: test( flavor = "multi_thread" ) ]
109- async fn if_there_is_a_dynamic_provider_and_static_provider_but_the_variable_to_be_resolved_is_not_in_play (
105+ #[ test]
106+ fn if_there_is_a_dynamic_provider_and_static_provider_but_the_variable_to_be_resolved_is_not_in_play (
110107) -> anyhow:: Result < ( ) > {
111108 let resolver = ResolverTester :: new ( )
112109 . with_provider ( DynamicProvider )
@@ -117,13 +114,13 @@ async fn if_there_is_a_dynamic_provider_and_static_provider_but_the_variable_to_
117114 . with_variable ( "api_key" , None )
118115 . make_resolver ( ) ?;
119116
120- resolver. ensure_required_variables_resolvable ( ) . await ?;
117+ resolver. ensure_required_variables_resolvable ( ) ?;
121118
122119 Ok ( ( ) )
123120}
124121
125- #[ tokio :: test( flavor = "multi_thread" ) ]
126- async fn if_there_is_a_dynamic_provider_and_a_static_provider_then_validation_succeeds_even_if_there_is_a_variable_in_play (
122+ #[ test]
123+ fn if_there_is_a_dynamic_provider_and_a_static_provider_then_validation_succeeds_even_if_there_is_a_variable_in_play (
127124) -> anyhow:: Result < ( ) > {
128125 let resolver = ResolverTester :: new ( )
129126 . with_provider ( DynamicProvider )
@@ -134,13 +131,13 @@ async fn if_there_is_a_dynamic_provider_and_a_static_provider_then_validation_su
134131 . with_variable ( "api_key" , Some ( "super-secret-key" ) )
135132 . make_resolver ( ) ?;
136133
137- resolver. ensure_required_variables_resolvable ( ) . await ?;
134+ resolver. ensure_required_variables_resolvable ( ) ?;
138135
139136 Ok ( ( ) )
140137}
141138
142- #[ tokio :: test( flavor = "multi_thread" ) ]
143- async fn if_there_are_two_static_providers_where_one_has_data_is_valid ( ) -> anyhow:: Result < ( ) > {
139+ #[ test]
140+ fn if_there_are_two_static_providers_where_one_has_data_is_valid ( ) -> anyhow:: Result < ( ) > {
144141 let resolver = ResolverTester :: new ( )
145142 . with_provider ( StaticProvider :: with_variable (
146143 "database_host" ,
@@ -153,14 +150,14 @@ async fn if_there_are_two_static_providers_where_one_has_data_is_valid() -> anyh
153150 . with_variable ( "database_host" , None )
154151 . make_resolver ( ) ?;
155152
156- resolver. ensure_required_variables_resolvable ( ) . await ?;
153+ resolver. ensure_required_variables_resolvable ( ) ?;
157154
158155 Ok ( ( ) )
159156}
160157// Ensure that if there are two or more static providers and the first one does not have data for the variable to be resolved,
161158// but the second or subsequent one does, then validation still succeeds.
162- #[ tokio :: test( flavor = "multi_thread" ) ]
163- async fn if_there_are_two_static_providers_where_first_provider_does_not_have_data_while_second_provider_does (
159+ #[ test]
160+ fn if_there_are_two_static_providers_where_first_provider_does_not_have_data_while_second_provider_does (
164161) -> anyhow:: Result < ( ) > {
165162 let resolver = ResolverTester :: new ( )
166163 . with_provider ( StaticProvider :: with_variable (
@@ -174,13 +171,13 @@ async fn if_there_are_two_static_providers_where_first_provider_does_not_have_da
174171 . with_variable ( "api_key" , None )
175172 . make_resolver ( ) ?;
176173
177- resolver. ensure_required_variables_resolvable ( ) . await ?;
174+ resolver. ensure_required_variables_resolvable ( ) ?;
178175
179176 Ok ( ( ) )
180177}
181178
182- #[ tokio :: test( flavor = "multi_thread" ) ]
183- async fn if_there_is_two_static_providers_neither_having_data_is_invalid ( ) -> anyhow:: Result < ( ) > {
179+ #[ test]
180+ fn if_there_is_two_static_providers_neither_having_data_is_invalid ( ) -> anyhow:: Result < ( ) > {
184181 let resolver = ResolverTester :: new ( )
185182 . with_provider ( StaticProvider :: with_variable (
186183 "database_host" ,
@@ -193,37 +190,30 @@ async fn if_there_is_two_static_providers_neither_having_data_is_invalid() -> an
193190 . with_variable ( "hello" , None )
194191 . make_resolver ( ) ?;
195192
196- assert ! ( resolver
197- . ensure_required_variables_resolvable( )
198- . await
199- . is_err( ) ) ;
193+ assert ! ( resolver. ensure_required_variables_resolvable( ) . is_err( ) ) ;
200194
201195 Ok ( ( ) )
202196}
203197
204- #[ tokio:: test( flavor = "multi_thread" ) ]
205- async fn no_provider_data_available_but_variable_default_value_needed_is_invalid (
206- ) -> anyhow:: Result < ( ) > {
198+ #[ test]
199+ fn no_provider_data_available_but_variable_default_value_needed_is_invalid ( ) -> anyhow:: Result < ( ) > {
207200 let resolver = ResolverTester :: new ( )
208201 . with_variable ( "api_key" , None )
209202 . make_resolver ( ) ?;
210203
211- assert ! ( resolver
212- . ensure_required_variables_resolvable( )
213- . await
214- . is_err( ) ) ;
204+ assert ! ( resolver. ensure_required_variables_resolvable( ) . is_err( ) ) ;
215205
216206 Ok ( ( ) )
217207}
218208
219- #[ tokio :: test( flavor = "multi_thread" ) ]
220- async fn no_provider_data_available_but_variable_has_default_value_needed_is_valid (
221- ) -> anyhow :: Result < ( ) > {
209+ #[ test]
210+ fn no_provider_data_available_but_variable_has_default_value_needed_is_valid ( ) -> anyhow :: Result < ( ) >
211+ {
222212 let resolver = ResolverTester :: new ( )
223213 . with_variable ( "api_key" , Some ( "super-secret-key" ) )
224214 . make_resolver ( ) ?;
225215
226- resolver. ensure_required_variables_resolvable ( ) . await ?;
216+ resolver. ensure_required_variables_resolvable ( ) ?;
227217
228218 Ok ( ( ) )
229219}
@@ -247,8 +237,8 @@ impl Provider for StaticProvider {
247237 Ok ( self . variables . get ( key. as_str ( ) ) . cloned ( ) . flatten ( ) )
248238 }
249239
250- fn kind ( & self ) -> ProviderVariableKind {
251- ProviderVariableKind :: Static
240+ fn may_resolve ( & self , key : & Key ) -> bool {
241+ self . variables . contains_key ( key . as_str ( ) )
252242 }
253243}
254244
@@ -260,8 +250,4 @@ impl Provider for DynamicProvider {
260250 async fn get ( & self , _key : & Key ) -> anyhow:: Result < Option < String > > {
261251 panic ! ( "validation should never call get for a dynamic provider" )
262252 }
263-
264- fn kind ( & self ) -> ProviderVariableKind {
265- ProviderVariableKind :: Dynamic
266- }
267253}
0 commit comments