Skip to content

Commit f000154

Browse files
committed
[refactor] Explicit testing
Signed-off-by: dd di cesare <[email protected]>
1 parent 753d41d commit f000154

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

src/operation_dispatcher.rs

+37-11
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ mod tests {
212212
use crate::envoy::RateLimitRequest;
213213
use std::time::Duration;
214214

215-
fn grpc_call_fn_stub(
215+
fn default_grpc_call_fn_stub(
216216
_upstream_name: &str,
217217
_service_name: &str,
218218
_method_name: &str,
@@ -244,7 +244,7 @@ mod tests {
244244
}
245245
}
246246

247-
fn build_operation() -> Operation {
247+
fn build_operation(grpc_call_fn_stub: GrpcCallFn) -> Operation {
248248
Operation {
249249
state: State::Pending,
250250
result: Ok(0),
@@ -260,7 +260,7 @@ mod tests {
260260

261261
#[test]
262262
fn operation_getters() {
263-
let operation = build_operation();
263+
let operation = build_operation(default_grpc_call_fn_stub);
264264

265265
assert_eq!(*operation.get_state(), State::Pending);
266266
assert_eq!(*operation.get_extension_type(), ExtensionType::RateLimit);
@@ -270,7 +270,7 @@ mod tests {
270270

271271
#[test]
272272
fn operation_transition() {
273-
let mut operation = build_operation();
273+
let mut operation = build_operation(default_grpc_call_fn_stub);
274274
assert_eq!(operation.result, Ok(0));
275275
assert_eq!(*operation.get_state(), State::Pending);
276276
let mut res = operation.trigger();
@@ -287,15 +287,15 @@ mod tests {
287287
let operation_dispatcher = OperationDispatcher::default();
288288

289289
assert_eq!(operation_dispatcher.operations.borrow().len(), 0);
290-
operation_dispatcher.push_operations(vec![build_operation()]);
290+
operation_dispatcher.push_operations(vec![build_operation(default_grpc_call_fn_stub)]);
291291

292292
assert_eq!(operation_dispatcher.operations.borrow().len(), 1);
293293
}
294294

295295
#[test]
296296
fn operation_dispatcher_get_current_action_state() {
297297
let operation_dispatcher = OperationDispatcher::default();
298-
operation_dispatcher.push_operations(vec![build_operation()]);
298+
operation_dispatcher.push_operations(vec![build_operation(default_grpc_call_fn_stub)]);
299299
assert_eq!(
300300
operation_dispatcher.get_current_operation_state(),
301301
Some(State::Pending)
@@ -305,7 +305,33 @@ mod tests {
305305
#[test]
306306
fn operation_dispatcher_next() {
307307
let operation_dispatcher = OperationDispatcher::default();
308-
operation_dispatcher.push_operations(vec![build_operation(), build_operation()]);
308+
309+
fn grpc_call_fn_stub_66(
310+
_upstream_name: &str,
311+
_service_name: &str,
312+
_method_name: &str,
313+
_initial_metadata: Vec<(&str, &[u8])>,
314+
_message: Option<&[u8]>,
315+
_timeout: Duration,
316+
) -> Result<u32, Status> {
317+
Ok(66)
318+
}
319+
320+
fn grpc_call_fn_stub_77(
321+
_upstream_name: &str,
322+
_service_name: &str,
323+
_method_name: &str,
324+
_initial_metadata: Vec<(&str, &[u8])>,
325+
_message: Option<&[u8]>,
326+
_timeout: Duration,
327+
) -> Result<u32, Status> {
328+
Ok(77)
329+
}
330+
331+
operation_dispatcher.push_operations(vec![
332+
build_operation(grpc_call_fn_stub_66),
333+
build_operation(grpc_call_fn_stub_77),
334+
]);
309335

310336
assert_eq!(operation_dispatcher.get_current_operation_result(), Ok(0));
311337
assert_eq!(
@@ -318,27 +344,27 @@ mod tests {
318344
);
319345

320346
let mut op = operation_dispatcher.next();
321-
assert_eq!(op.clone().unwrap().get_result(), Ok(200));
347+
assert_eq!(op.clone().unwrap().get_result(), Ok(66));
322348
assert_eq!(*op.unwrap().get_state(), State::Waiting);
323349
assert_eq!(
324350
operation_dispatcher.waiting_operations.borrow_mut().len(),
325351
1
326352
);
327353

328354
op = operation_dispatcher.next();
329-
assert_eq!(op.clone().unwrap().get_result(), Ok(200));
355+
assert_eq!(op.clone().unwrap().get_result(), Ok(66));
330356
assert_eq!(*op.unwrap().get_state(), State::Done);
331357

332358
op = operation_dispatcher.next();
333-
assert_eq!(op.clone().unwrap().get_result(), Ok(200));
359+
assert_eq!(op.clone().unwrap().get_result(), Ok(77));
334360
assert_eq!(*op.unwrap().get_state(), State::Waiting);
335361
assert_eq!(
336362
operation_dispatcher.waiting_operations.borrow_mut().len(),
337363
1
338364
);
339365

340366
op = operation_dispatcher.next();
341-
assert_eq!(op.clone().unwrap().get_result(), Ok(200));
367+
assert_eq!(op.clone().unwrap().get_result(), Ok(77));
342368
assert_eq!(*op.unwrap().get_state(), State::Done);
343369
assert_eq!(
344370
operation_dispatcher.waiting_operations.borrow_mut().len(),

0 commit comments

Comments
 (0)