1
1
use std:: collections:: HashMap ;
2
2
3
3
use async_trait:: async_trait;
4
- use spin_expressions:: { provider :: ProviderVariableKind , Key , Provider , ProviderResolver } ;
4
+ use spin_expressions:: { Key , Provider , ProviderResolver } ;
5
5
use spin_locked_app:: Variable ;
6
6
7
7
#[ derive( Default ) ]
@@ -43,23 +43,23 @@ impl ResolverTester {
43
43
}
44
44
}
45
45
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 < ( ) > {
48
48
let resolver = ResolverTester :: new ( )
49
49
. with_provider ( StaticProvider :: with_variable (
50
50
"database_host" ,
51
51
Some ( "localhost" ) ,
52
52
) )
53
53
. make_resolver ( ) ?;
54
54
55
- resolver. ensure_required_variables_resolvable ( ) . await ?;
55
+ resolver. ensure_required_variables_resolvable ( ) ?;
56
56
57
57
Ok ( ( ) )
58
58
}
59
59
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
+ {
63
63
let resolver = ResolverTester :: new ( )
64
64
. with_provider ( StaticProvider :: with_variable (
65
65
"database_host" ,
@@ -68,13 +68,13 @@ async fn if_single_static_provider_has_data_for_variable_key_to_resolve_it_succe
68
68
. with_variable ( "database_host" , None )
69
69
. make_resolver ( ) ?;
70
70
71
- resolver. ensure_required_variables_resolvable ( ) . await ?;
71
+ resolver. ensure_required_variables_resolvable ( ) ?;
72
72
73
73
Ok ( ( ) )
74
74
}
75
75
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 (
78
78
) -> anyhow:: Result < ( ) > {
79
79
let resolver = ResolverTester :: new ( )
80
80
. 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
84
84
. with_variable ( "api_key" , None )
85
85
. make_resolver ( ) ?;
86
86
87
- assert ! ( resolver
88
- . ensure_required_variables_resolvable( )
89
- . await
90
- . is_err( ) ) ;
87
+ assert ! ( resolver. ensure_required_variables_resolvable( ) . is_err( ) ) ;
91
88
92
89
Ok ( ( ) )
93
90
}
94
91
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 (
97
94
) -> anyhow:: Result < ( ) > {
98
95
let resolver = ResolverTester :: new ( )
99
96
. with_provider ( DynamicProvider )
100
97
. with_variable ( "api_key" , None )
101
98
. make_resolver ( ) ?;
102
99
103
- resolver. ensure_required_variables_resolvable ( ) . await ?;
100
+ resolver. ensure_required_variables_resolvable ( ) ?;
104
101
105
102
Ok ( ( ) )
106
103
}
107
104
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 (
110
107
) -> anyhow:: Result < ( ) > {
111
108
let resolver = ResolverTester :: new ( )
112
109
. with_provider ( DynamicProvider )
@@ -117,13 +114,13 @@ async fn if_there_is_a_dynamic_provider_and_static_provider_but_the_variable_to_
117
114
. with_variable ( "api_key" , None )
118
115
. make_resolver ( ) ?;
119
116
120
- resolver. ensure_required_variables_resolvable ( ) . await ?;
117
+ resolver. ensure_required_variables_resolvable ( ) ?;
121
118
122
119
Ok ( ( ) )
123
120
}
124
121
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 (
127
124
) -> anyhow:: Result < ( ) > {
128
125
let resolver = ResolverTester :: new ( )
129
126
. with_provider ( DynamicProvider )
@@ -134,13 +131,13 @@ async fn if_there_is_a_dynamic_provider_and_a_static_provider_then_validation_su
134
131
. with_variable ( "api_key" , Some ( "super-secret-key" ) )
135
132
. make_resolver ( ) ?;
136
133
137
- resolver. ensure_required_variables_resolvable ( ) . await ?;
134
+ resolver. ensure_required_variables_resolvable ( ) ?;
138
135
139
136
Ok ( ( ) )
140
137
}
141
138
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 < ( ) > {
144
141
let resolver = ResolverTester :: new ( )
145
142
. with_provider ( StaticProvider :: with_variable (
146
143
"database_host" ,
@@ -153,14 +150,14 @@ async fn if_there_are_two_static_providers_where_one_has_data_is_valid() -> anyh
153
150
. with_variable ( "database_host" , None )
154
151
. make_resolver ( ) ?;
155
152
156
- resolver. ensure_required_variables_resolvable ( ) . await ?;
153
+ resolver. ensure_required_variables_resolvable ( ) ?;
157
154
158
155
Ok ( ( ) )
159
156
}
160
157
// Ensure that if there are two or more static providers and the first one does not have data for the variable to be resolved,
161
158
// 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 (
164
161
) -> anyhow:: Result < ( ) > {
165
162
let resolver = ResolverTester :: new ( )
166
163
. with_provider ( StaticProvider :: with_variable (
@@ -174,13 +171,13 @@ async fn if_there_are_two_static_providers_where_first_provider_does_not_have_da
174
171
. with_variable ( "api_key" , None )
175
172
. make_resolver ( ) ?;
176
173
177
- resolver. ensure_required_variables_resolvable ( ) . await ?;
174
+ resolver. ensure_required_variables_resolvable ( ) ?;
178
175
179
176
Ok ( ( ) )
180
177
}
181
178
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 < ( ) > {
184
181
let resolver = ResolverTester :: new ( )
185
182
. with_provider ( StaticProvider :: with_variable (
186
183
"database_host" ,
@@ -193,37 +190,30 @@ async fn if_there_is_two_static_providers_neither_having_data_is_invalid() -> an
193
190
. with_variable ( "hello" , None )
194
191
. make_resolver ( ) ?;
195
192
196
- assert ! ( resolver
197
- . ensure_required_variables_resolvable( )
198
- . await
199
- . is_err( ) ) ;
193
+ assert ! ( resolver. ensure_required_variables_resolvable( ) . is_err( ) ) ;
200
194
201
195
Ok ( ( ) )
202
196
}
203
197
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 < ( ) > {
207
200
let resolver = ResolverTester :: new ( )
208
201
. with_variable ( "api_key" , None )
209
202
. make_resolver ( ) ?;
210
203
211
- assert ! ( resolver
212
- . ensure_required_variables_resolvable( )
213
- . await
214
- . is_err( ) ) ;
204
+ assert ! ( resolver. ensure_required_variables_resolvable( ) . is_err( ) ) ;
215
205
216
206
Ok ( ( ) )
217
207
}
218
208
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
+ {
222
212
let resolver = ResolverTester :: new ( )
223
213
. with_variable ( "api_key" , Some ( "super-secret-key" ) )
224
214
. make_resolver ( ) ?;
225
215
226
- resolver. ensure_required_variables_resolvable ( ) . await ?;
216
+ resolver. ensure_required_variables_resolvable ( ) ?;
227
217
228
218
Ok ( ( ) )
229
219
}
@@ -247,8 +237,8 @@ impl Provider for StaticProvider {
247
237
Ok ( self . variables . get ( key. as_str ( ) ) . cloned ( ) . flatten ( ) )
248
238
}
249
239
250
- fn kind ( & self ) -> ProviderVariableKind {
251
- ProviderVariableKind :: Static
240
+ fn may_resolve ( & self , key : & Key ) -> bool {
241
+ self . variables . contains_key ( key . as_str ( ) )
252
242
}
253
243
}
254
244
@@ -260,8 +250,4 @@ impl Provider for DynamicProvider {
260
250
async fn get ( & self , _key : & Key ) -> anyhow:: Result < Option < String > > {
261
251
panic ! ( "validation should never call get for a dynamic provider" )
262
252
}
263
-
264
- fn kind ( & self ) -> ProviderVariableKind {
265
- ProviderVariableKind :: Dynamic
266
- }
267
253
}
0 commit comments