我正在尝试对使用中间件将数据传递到其中的请求处理程序进行单元测试。在实现中间件测试相当简单之前,我可以使用
web::Data::new(data)
将测试数据传递到处理程序中。然而,现在数据被包装在 web::ReqData
中,我无法弄清楚如何传递数据进行测试。
示例:
pub async fn handler(
some_data: web::Data<SomeDataType>,
req_data: web::ReqData<ReqestDataType>
) -> HttpResponse {
// some code
}
#[actix_rt::test]
async fn test_fn() {
let resp = handler(
web::Data::new(someData),
// what can I put here?
).await;
assert_eq!(resp.status(), status_code::OKAY);
}