vercel-community / rust

🦀 Rust runtime for ▲ Vercel Serverless Functions
https://rust-runtime.vercel.app
MIT License
816 stars 50 forks source link

Is that possible to write intergration test? #118

Open Zxilly opened 10 months ago

Zxilly commented 10 months ago

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

dglsparsons commented 10 months ago

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

Zxilly commented 10 months ago

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.

dglsparsons commented 10 months ago

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.

Zxilly commented 10 months ago

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?

dglsparsons commented 10 months ago

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 🤔