@@ -18,7 +18,7 @@ struct DeploymentStatusResponse {
18
18
indexing_statuses : Option < Vec < DeploymentStatus > > ,
19
19
}
20
20
21
- #[ derive( Clone , Deserialize , Eq , PartialEq ) ]
21
+ #[ derive( Clone , Debug , Deserialize , Eq , PartialEq ) ]
22
22
pub struct DeploymentStatus {
23
23
pub synced : bool ,
24
24
pub health : String ,
@@ -96,3 +96,165 @@ pub fn monitor_deployment_status(
96
96
} ,
97
97
)
98
98
}
99
+
100
+ #[ cfg( test) ]
101
+ mod tests {
102
+ use std:: str:: FromStr ;
103
+
104
+ use wiremock:: matchers:: { method, path} ;
105
+ use wiremock:: { Mock , MockServer , ResponseTemplate } ;
106
+
107
+ use super :: * ;
108
+
109
+ #[ tokio:: test]
110
+ async fn test_parses_synced_and_healthy_response ( ) {
111
+ let mock_server = MockServer :: start ( ) . await ;
112
+ let status_url: Url = mock_server
113
+ . uri ( )
114
+ . parse :: < Url > ( )
115
+ . unwrap ( )
116
+ . join ( "/status" )
117
+ . unwrap ( ) ;
118
+ let deployment =
119
+ DeploymentId :: from_str ( "QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" ) . unwrap ( ) ;
120
+
121
+ Mock :: given ( method ( "POST" ) )
122
+ . and ( path ( "/status" ) )
123
+ . respond_with ( ResponseTemplate :: new ( 200 ) . set_body_json ( json ! ( {
124
+ "data" : {
125
+ "indexingStatuses" : [
126
+ {
127
+ "synced" : true ,
128
+ "health" : "healthy"
129
+ }
130
+ ]
131
+ }
132
+ } ) ) )
133
+ . mount ( & mock_server)
134
+ . await ;
135
+
136
+ let status = monitor_deployment_status ( deployment, status_url) ;
137
+
138
+ assert_eq ! (
139
+ status. value( ) . await . unwrap( ) ,
140
+ DeploymentStatus {
141
+ synced: true ,
142
+ health: "healthy" . to_string( )
143
+ }
144
+ ) ;
145
+ }
146
+
147
+ #[ tokio:: test]
148
+ async fn test_parses_not_synced_and_healthy_response ( ) {
149
+ let mock_server = MockServer :: start ( ) . await ;
150
+ let status_url: Url = mock_server
151
+ . uri ( )
152
+ . parse :: < Url > ( )
153
+ . unwrap ( )
154
+ . join ( "/status" )
155
+ . unwrap ( ) ;
156
+ let deployment =
157
+ DeploymentId :: from_str ( "QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" ) . unwrap ( ) ;
158
+
159
+ Mock :: given ( method ( "POST" ) )
160
+ . and ( path ( "/status" ) )
161
+ . respond_with ( ResponseTemplate :: new ( 200 ) . set_body_json ( json ! ( {
162
+ "data" : {
163
+ "indexingStatuses" : [
164
+ {
165
+ "synced" : false ,
166
+ "health" : "healthy"
167
+ }
168
+ ]
169
+ }
170
+ } ) ) )
171
+ . mount ( & mock_server)
172
+ . await ;
173
+
174
+ let status = monitor_deployment_status ( deployment, status_url) ;
175
+
176
+ assert_eq ! (
177
+ status. value( ) . await . unwrap( ) ,
178
+ DeploymentStatus {
179
+ synced: false ,
180
+ health: "healthy" . to_string( )
181
+ }
182
+ ) ;
183
+ }
184
+
185
+ #[ tokio:: test]
186
+ async fn test_parses_synced_and_unhealthy_response ( ) {
187
+ let mock_server = MockServer :: start ( ) . await ;
188
+ let status_url: Url = mock_server
189
+ . uri ( )
190
+ . parse :: < Url > ( )
191
+ . unwrap ( )
192
+ . join ( "/status" )
193
+ . unwrap ( ) ;
194
+ let deployment =
195
+ DeploymentId :: from_str ( "QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" ) . unwrap ( ) ;
196
+
197
+ Mock :: given ( method ( "POST" ) )
198
+ . and ( path ( "/status" ) )
199
+ . respond_with ( ResponseTemplate :: new ( 200 ) . set_body_json ( json ! ( {
200
+ "data" : {
201
+ "indexingStatuses" : [
202
+ {
203
+ "synced" : true ,
204
+ "health" : "unhealthy"
205
+ }
206
+ ]
207
+ }
208
+ } ) ) )
209
+ . mount ( & mock_server)
210
+ . await ;
211
+
212
+ let status = monitor_deployment_status ( deployment, status_url) ;
213
+
214
+ assert_eq ! (
215
+ status. value( ) . await . unwrap( ) ,
216
+ DeploymentStatus {
217
+ synced: true ,
218
+ health: "unhealthy" . to_string( )
219
+ }
220
+ ) ;
221
+ }
222
+
223
+ #[ tokio:: test]
224
+ async fn test_parses_synced_and_failed_response ( ) {
225
+ let mock_server = MockServer :: start ( ) . await ;
226
+ let status_url: Url = mock_server
227
+ . uri ( )
228
+ . parse :: < Url > ( )
229
+ . unwrap ( )
230
+ . join ( "/status" )
231
+ . unwrap ( ) ;
232
+ let deployment =
233
+ DeploymentId :: from_str ( "QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" ) . unwrap ( ) ;
234
+
235
+ Mock :: given ( method ( "POST" ) )
236
+ . and ( path ( "/status" ) )
237
+ . respond_with ( ResponseTemplate :: new ( 200 ) . set_body_json ( json ! ( {
238
+ "data" : {
239
+ "indexingStatuses" : [
240
+ {
241
+ "synced" : true ,
242
+ "health" : "failed"
243
+ }
244
+ ]
245
+ }
246
+ } ) ) )
247
+ . mount ( & mock_server)
248
+ . await ;
249
+
250
+ let status = monitor_deployment_status ( deployment, status_url) ;
251
+
252
+ assert_eq ! (
253
+ status. value( ) . await . unwrap( ) ,
254
+ DeploymentStatus {
255
+ synced: true ,
256
+ health: "failed" . to_string( )
257
+ }
258
+ ) ;
259
+ }
260
+ }
0 commit comments