Skip to content

Commit 4db09b5

Browse files
committed
test: Add handler test functions to reduce boilerplate on tests
1 parent cb906ad commit 4db09b5

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

mgmtd/src/bee_msg.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ impl AppExt for App {
218218
#[cfg(test)]
219219
mod test {
220220
use super::*;
221-
use crate::app::test::TestApp;
221+
pub(super) use crate::app::test::*;
222+
use shared::conn::msg_dispatch::test::TestRequest;
222223

223224
impl AppExt for TestApp {
224225
fn fail_on_pre_shutdown(&self) -> Result<()> {
@@ -229,4 +230,20 @@ mod test {
229230
}
230231
}
231232
}
233+
234+
pub(super) async fn test_handler_resp<M: Msg + HandleWithResponse>(
235+
msg: M,
236+
app: &impl AppExt,
237+
) -> Result<M::Response> {
238+
let mut req = TestRequest::new(M::ID);
239+
msg.handle(app, &mut req).await
240+
}
241+
242+
pub(super) async fn test_handler_no_resp<M: Msg + HandleNoResponse>(
243+
msg: M,
244+
app: &impl AppExt,
245+
) -> Result<()> {
246+
let mut req = TestRequest::new(M::ID);
247+
msg.handle(app, &mut req).await
248+
}
232249
}

0 commit comments

Comments
 (0)