@@ -16,7 +16,7 @@ use spin_app::{
16
16
AppComponent , Loader ,
17
17
} ;
18
18
use spin_core:: { Module , StoreBuilder } ;
19
- use spin_http:: { HttpExecutorType , HttpTrigger , HttpTriggerConfig , WagiTriggerConfig } ;
19
+ use spin_http:: { HttpExecutorType , HttpTriggerConfig , WagiTriggerConfig } ;
20
20
use spin_trigger:: { TriggerExecutor , TriggerExecutorBuilder } ;
21
21
22
22
pub use tokio;
@@ -37,13 +37,18 @@ macro_rules! from_json {
37
37
}
38
38
39
39
#[ derive( Default ) ]
40
- pub struct TestConfig {
40
+ pub struct HttpTestConfig {
41
41
module_path : Option < PathBuf > ,
42
42
http_trigger_config : HttpTriggerConfig ,
43
+ }
44
+
45
+ #[ derive( Default ) ]
46
+ pub struct RedisTestConfig {
47
+ module_path : Option < PathBuf > ,
43
48
redis_channel : String ,
44
49
}
45
50
46
- impl TestConfig {
51
+ impl HttpTestConfig {
47
52
pub fn module_path ( & mut self , path : impl Into < PathBuf > ) -> & mut Self {
48
53
init_tracing ( ) ;
49
54
self . module_path = Some ( path. into ( ) ) ;
@@ -80,9 +85,22 @@ impl TestConfig {
80
85
self
81
86
}
82
87
83
- pub fn redis_trigger ( & mut self , channel : impl Into < String > ) -> & mut Self {
84
- self . redis_channel = channel. into ( ) ;
85
- self
88
+ pub fn build_loader ( & self ) -> impl Loader {
89
+ init_tracing ( ) ;
90
+ TestLoader {
91
+ app : self . build_locked_app ( ) ,
92
+ module_path : self . module_path . clone ( ) . expect ( "module path to be set" ) ,
93
+ }
94
+ }
95
+
96
+ pub async fn build_trigger < Executor : TriggerExecutor > ( & self ) -> Executor
97
+ where
98
+ Executor :: TriggerConfig : DeserializeOwned ,
99
+ {
100
+ TriggerExecutorBuilder :: new ( self . build_loader ( ) )
101
+ . build ( TEST_APP_URI . to_string ( ) )
102
+ . await
103
+ . unwrap ( )
86
104
}
87
105
88
106
pub fn build_locked_app ( & self ) -> LockedApp {
@@ -100,7 +118,7 @@ impl TestConfig {
100
118
"trigger_config" : self . http_trigger_config,
101
119
} ,
102
120
] ) ;
103
- let metadata = from_json ! ( { "name" : "test-app" , "trigger" : { "address " : "test-redis-host " , "type " : "redis " } } ) ;
121
+ let metadata = from_json ! ( { "name" : "test-app" , "trigger" : { "type " : "http " , "base " : "/ " } } ) ;
104
122
let variables = Default :: default ( ) ;
105
123
LockedApp {
106
124
spin_lock_version : spin_app:: locked:: FixedVersion ,
@@ -110,6 +128,22 @@ impl TestConfig {
110
128
variables,
111
129
}
112
130
}
131
+ }
132
+
133
+ impl RedisTestConfig {
134
+ pub fn module_path ( & mut self , path : impl Into < PathBuf > ) -> & mut Self {
135
+ init_tracing ( ) ;
136
+ self . module_path = Some ( path. into ( ) ) ;
137
+ self
138
+ }
139
+
140
+ pub fn test_program ( & mut self , name : impl AsRef < Path > ) -> & mut Self {
141
+ self . module_path (
142
+ PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) )
143
+ . join ( "../../target/test-programs" )
144
+ . join ( name) ,
145
+ )
146
+ }
113
147
114
148
pub fn build_loader ( & self ) -> impl Loader {
115
149
init_tracing ( ) ;
@@ -119,18 +153,42 @@ impl TestConfig {
119
153
}
120
154
}
121
155
122
- pub async fn build_trigger < Executor : TriggerExecutor > ( & self ) -> Executor
156
+ pub async fn build_trigger < Executor : TriggerExecutor > ( & mut self , channel : & str ) -> Executor
123
157
where
124
158
Executor :: TriggerConfig : DeserializeOwned ,
125
159
{
160
+ self . redis_channel = channel. into ( ) ;
161
+
126
162
TriggerExecutorBuilder :: new ( self . build_loader ( ) )
127
163
. build ( TEST_APP_URI . to_string ( ) )
128
164
. await
129
165
. unwrap ( )
130
166
}
131
167
132
- pub async fn build_http_trigger ( & self ) -> HttpTrigger {
133
- self . build_trigger ( ) . await
168
+ pub fn build_locked_app ( & self ) -> LockedApp {
169
+ let components = from_json ! ( [ {
170
+ "id" : "test-component" ,
171
+ "source" : {
172
+ "content_type" : "application/wasm" ,
173
+ "digest" : "test-source" ,
174
+ } ,
175
+ } ] ) ;
176
+ let triggers = from_json ! ( [
177
+ {
178
+ "id" : "trigger--test-app" ,
179
+ "trigger_type" : "redis" ,
180
+ "trigger_config" : { "channel" : self . redis_channel, "component" : "test-component" } ,
181
+ } ,
182
+ ] ) ;
183
+ let metadata = from_json ! ( { "name" : "test-app" , "trigger" : { "address" : "test-redis-host" , "type" : "redis" } } ) ;
184
+ let variables = Default :: default ( ) ;
185
+ LockedApp {
186
+ spin_lock_version : spin_app:: locked:: FixedVersion ,
187
+ components,
188
+ triggers,
189
+ metadata,
190
+ variables,
191
+ }
134
192
}
135
193
}
136
194
0 commit comments