Skip to content

How to write a test for query_string_parameters #252

@johansmitsnl

Description

@johansmitsnl

I want to write a test for example: https://github.com/awslabs/aws-lambda-rust-runtime/blob/a9de2fcb24030a00e402348aba3c368b717feb6d/lambda-http/examples/hello-http-without-macros.rs#L15-L23

But until now it does not work.

#[cfg(test)]
mod tests {
    use super::*;
    use lambda_http::http::StatusCode;
    use lambda_http::{http, Body};

    #[tokio::test]
    async fn main_handles() {

        let request = http::Request::builder()
            .uri("https://api.com/?first_name=John")
            .expect("failed to build request");

        let expected = json!({"first_name": "John"}).into_response();
        let response = func(request, Context::default())
            .await
            .expect("expected Ok(_) value")
            .into_response();
        assert_eq!(response.body(), expected.body());
        assert_eq!(response.status(), StatusCode::OK)
    }
}

How can I stub the request?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions