rust icon indicating copy to clipboard operation
rust copied to clipboard

Is that possible to write intergration test?

Open Zxilly opened this issue 2 years ago • 5 comments

AWS Lambda provides such support, but I didn't know how to implement it with vercel runtime

Zxilly avatar Aug 28 '23 08:08 Zxilly

Hi @Zxilly, can you link to the documentation of what this would mean, in the context of AWS Lambda?

dglsparsons avatar Aug 28 '23 14:08 dglsparsons

https://github.com/awslabs/aws-lambda-rust-runtime/tree/main?tab=readme-ov-file#local-development-and-testing

I want to mock a request and ensure the response met the requirement.

Zxilly avatar Aug 28 '23 15:08 Zxilly

Thanks for linking that. The same logic applies - your handler function in the Vercel runtime world is simply an async fn, so it can be called in a #[test] the same way any other function can.

dglsparsons avatar Aug 28 '23 15:08 dglsparsons

I want something like

#[test]
fn test_my_lambda_handler() {
  let input = include_str!("apigw_proxy_request.json");

  let request = lambda_http::request::from_str(input)
    .expect("failed to create request");

  let response = my_lambda_handler(request).await.expect("failed to handle request");
}

Is that also possible right now?

Zxilly avatar Aug 28 '23 16:08 Zxilly

I don't think the from_str part is exposed at the moment, so there's no super convenient way to achieve what you're attempting to there.

CC @ecklf we might want to consider exposing the Request::builder APIs or similar 🤔

dglsparsons avatar Aug 28 '23 17:08 dglsparsons