File tree 4 files changed +23
-7
lines changed
4 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -118,10 +118,10 @@ fn expand_factors(input: &DeriveInput) -> syn::Result<TokenStream> {
118
118
Ok ( #ConfiguredApp :: new( app, app_state) )
119
119
}
120
120
121
- fn build_instance_state (
121
+ fn prepare (
122
122
& self , configured_app: & #ConfiguredApp <Self >,
123
123
component_id: & str ,
124
- ) -> #Result <Self :: InstanceState > {
124
+ ) -> #Result <Self :: InstanceBuilders > {
125
125
let app_component = configured_app. app( ) . get_component( component_id) . ok_or_else( || {
126
126
#factors_path:: Error :: UnknownComponent ( component_id. to_string( ) )
127
127
} ) ?;
@@ -140,6 +140,13 @@ fn expand_factors(input: &DeriveInput) -> syn::Result<TokenStream> {
140
140
) . map_err( #Error :: factor_prepare_error:: <#factor_types>) ?
141
141
) ;
142
142
) *
143
+ Ok ( builders)
144
+ }
145
+
146
+ fn build_instance_state(
147
+ & self ,
148
+ builders: Self :: InstanceBuilders ,
149
+ ) -> #Result <Self :: InstanceState > {
143
150
Ok ( #state_name {
144
151
#(
145
152
#factor_names: #FactorInstanceBuilder :: build(
Original file line number Diff line number Diff line change @@ -69,7 +69,9 @@ impl TestEnvironment {
69
69
configured_app. app ( ) . components ( ) . next ( ) . context (
70
70
"expected configured app to have at least one component, but it did not" ,
71
71
) ?;
72
- Ok ( factors. build_instance_state ( & configured_app, component. id ( ) ) ?)
72
+ let builders = factors. prepare ( & configured_app, component. id ( ) ) ?;
73
+
74
+ Ok ( factors. build_instance_state ( builders) ?)
73
75
}
74
76
75
77
pub fn new_linker < T : RuntimeFactors > ( ) -> Linker < T > {
Original file line number Diff line number Diff line change @@ -46,11 +46,17 @@ pub trait RuntimeFactors: Sized + 'static {
46
46
runtime_config : impl RuntimeConfigSource ,
47
47
) -> crate :: Result < ConfiguredApp < Self > > ;
48
48
49
- /// Build the instance state for the factors .
50
- fn build_instance_state (
49
+ /// Prepare the factors' instance state builders .
50
+ fn prepare (
51
51
& self ,
52
52
configured_app : & ConfiguredApp < Self > ,
53
53
component_id : & str ,
54
+ ) -> crate :: Result < Self :: InstanceBuilders > ;
55
+
56
+ /// Build the instance state for the factors.
57
+ fn build_instance_state (
58
+ & self ,
59
+ builders : Self :: InstanceBuilders ,
54
60
) -> crate :: Result < Self :: InstanceState > ;
55
61
56
62
/// Get the app state related to a particular factor.
Original file line number Diff line number Diff line change @@ -5,13 +5,13 @@ use http_body_util::BodyExt;
5
5
use serde:: Deserialize ;
6
6
use spin_app:: App ;
7
7
use spin_factor_key_value:: { KeyValueFactor , MakeKeyValueStore } ;
8
+ use spin_factor_key_value_redis:: RedisKeyValueStore ;
8
9
use spin_factor_outbound_http:: OutboundHttpFactor ;
9
10
use spin_factor_outbound_networking:: OutboundNetworkingFactor ;
10
11
use spin_factor_variables:: { StaticVariables , VariablesFactor } ;
11
12
use spin_factor_wasi:: { DummyFilesMounter , WasiFactor } ;
12
13
use spin_factors:: { FactorRuntimeConfig , RuntimeConfigSource , RuntimeFactors } ;
13
14
use spin_key_value_sqlite:: { DatabaseLocation , KeyValueSqlite } ;
14
- use spin_factor_key_value_redis:: RedisKeyValueStore ;
15
15
use wasmtime_wasi_http:: WasiHttpView ;
16
16
17
17
#[ derive( RuntimeFactors ) ]
@@ -53,7 +53,8 @@ async fn smoke_test_works() -> anyhow::Result<()> {
53
53
factors. init ( & mut linker) . unwrap ( ) ;
54
54
55
55
let configured_app = factors. configure_app ( app, TestSource ) ?;
56
- let data = factors. build_instance_state ( & configured_app, "smoke-app" ) ?;
56
+ let builders = factors. prepare ( & configured_app, "smoke-app" ) ?;
57
+ let data = factors. build_instance_state ( builders) ?;
57
58
58
59
assert_eq ! (
59
60
data. variables
You can’t perform that action at this time.
0 commit comments