Skip to content

Commit 94b1824

Browse files
committed
add test for minimmal httpApi payload
1 parent 6b71850 commit 94b1824

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

lambda-http/src/request.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ pub enum LambdaRequest<'a> {
2929
route_key: Cow<'a, str>,
3030
raw_path: Cow<'a, str>,
3131
raw_query_string: Cow<'a, str>,
32-
cookies: Vec<Cow<'a, str>>,
32+
cookies: Option<Vec<Cow<'a, str>>>,
3333
#[serde(deserialize_with = "deserialize_headers")]
3434
headers: http::HeaderMap,
35-
#[serde(deserialize_with = "nullable_default")]
35+
#[serde(default)]
3636
query_string_parameters: StrMap,
37-
#[serde(default, deserialize_with = "nullable_default")]
37+
#[serde(default)]
3838
path_parameters: StrMap,
39-
#[serde(default, deserialize_with = "nullable_default")]
39+
#[serde(default)]
4040
stage_variables: StrMap,
4141
body: Option<Cow<'a, str>>,
4242
#[serde(default)]
@@ -546,6 +546,21 @@ mod tests {
546546
assert!(result.is_ok(), format!("event was not parsed as expected {:?}", result));
547547
}
548548

549+
#[test]
550+
fn deserializes_minimal_apigw_v2_request_events() {
551+
// from the docs
552+
// https://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-api-gateway-request
553+
let input = include_str!("../tests/data/apigw_v2_proxy_request_minimal.json");
554+
let result = from_str(input);
555+
assert!(
556+
result.is_ok(),
557+
format!("event was not parsed as expected {:?} given {}", result, input)
558+
);
559+
let req = result.expect("failed to parse request");
560+
assert_eq!(req.method(), "GET");
561+
assert_eq!(req.uri(), "https://xxx.execute-api.us-east-1.amazonaws.com/");
562+
}
563+
549564
#[test]
550565
fn deserializes_apigw_v2_request_events() {
551566
// from the docs
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"headers": {
3+
"accept": "*/*",
4+
"content-length": "0",
5+
"host": "xxx.execute-api.us-east-1.amazonaws.com",
6+
"user-agent": "curl/7.64.1",
7+
"x-amzn-trace-id": "Root=1-5eb33c07-de25b420912dee103a5db434",
8+
"x-forwarded-for": "65.78.31.245",
9+
"x-forwarded-port": "443",
10+
"x-forwarded-proto": "https"
11+
},
12+
"isBase64Encoded": false,
13+
"rawPath": "/",
14+
"rawQueryString": "",
15+
"requestContext": {
16+
"accountId": "123456789012",
17+
"apiId": "xxx",
18+
"domainName": "xxx.execute-api.us-east-1.amazonaws.com",
19+
"domainPrefix": "xxx",
20+
"http": {
21+
"method": "GET",
22+
"path": "/",
23+
"protocol": "HTTP/1.1",
24+
"sourceIp": "65.78.31.245",
25+
"userAgent": "curl/7.64.1"
26+
},
27+
"requestId": "MIZRNhJtIAMEMDw=",
28+
"routeKey": "$default",
29+
"stage": "$default",
30+
"time": "06/May/2020:22:36:55 +0000",
31+
"timeEpoch": 1588804615616
32+
},
33+
"routeKey": "$default",
34+
"version": "2.0"
35+
}

0 commit comments

Comments
 (0)