From 9f947394546e7f16141feb3e826119e81adc6a0c Mon Sep 17 00:00:00 2001 From: softprops Date: Sat, 20 Oct 2018 13:17:16 -0400 Subject: [PATCH 1/2] add a unit test for parsing proxy events --- src/request.rs | 11 +++++-- tests/data/proxy_request.json | 55 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 tests/data/proxy_request.json diff --git a/src/request.rs b/src/request.rs index 2a700a4..dcad0ff 100644 --- a/src/request.rs +++ b/src/request.rs @@ -75,12 +75,17 @@ where #[cfg(test)] mod tests { - use std::collections::HashMap; - use serde_json; + use super::*; - use super::{nullable_default, GatewayRequest}; + #[test] + fn deserializes_request_events() { + // from the docs + // https://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-api-gateway-request + let input = include_str!("../tests/data/proxy_request.json"); + assert!(serde_json::from_str::(&input).is_ok()) + } #[test] fn implements_default() { diff --git a/tests/data/proxy_request.json b/tests/data/proxy_request.json new file mode 100644 index 0000000..496553d --- /dev/null +++ b/tests/data/proxy_request.json @@ -0,0 +1,55 @@ +{ + "path": "/test/hello", + "headers": { + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Accept-Encoding": "gzip, deflate, lzma, sdch, br", + "Accept-Language": "en-US,en;q=0.8", + "CloudFront-Forwarded-Proto": "https", + "CloudFront-Is-Desktop-Viewer": "true", + "CloudFront-Is-Mobile-Viewer": "false", + "CloudFront-Is-SmartTV-Viewer": "false", + "CloudFront-Is-Tablet-Viewer": "false", + "CloudFront-Viewer-Country": "US", + "Host": "wt6mne2s9k.execute-api.us-west-2.amazonaws.com", + "Upgrade-Insecure-Requests": "1", + "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48", + "Via": "1.1 fb7cca60f0ecd82ce07790c9c5eef16c.cloudfront.net (CloudFront)", + "X-Amz-Cf-Id": "nBsWBOrSHMgnaROZJK1wGCZ9PcRcSpq_oSXZNQwQ10OTZL4cimZo3g==", + "X-Forwarded-For": "192.168.100.1, 192.168.1.1", + "X-Forwarded-Port": "443", + "X-Forwarded-Proto": "https" + }, + "pathParameters": { + "proxy": "hello" + }, + "requestContext": { + "accountId": "123456789012", + "resourceId": "us4z18", + "stage": "test", + "requestId": "41b45ea3-70b5-11e6-b7bd-69b5aaebc7d9", + "identity": { + "cognitoIdentityPoolId": "", + "accountId": "", + "cognitoIdentityId": "", + "caller": "", + "apiKey": "", + "sourceIp": "192.168.100.1", + "cognitoAuthenticationType": "", + "cognitoAuthenticationProvider": "", + "userArn": "", + "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48", + "user": "" + }, + "resourcePath": "/{proxy+}", + "httpMethod": "GET", + "apiId": "wt6mne2s9k" + }, + "resource": "/{proxy+}", + "httpMethod": "GET", + "queryStringParameters": { + "name": "me" + }, + "stageVariables": { + "stageVarName": "stageVarValue" + } +} From 1df9c7eaa085361d1d9be9eef7a353f0fe1f257f Mon Sep 17 00:00:00 2001 From: softprops Date: Sat, 20 Oct 2018 13:28:55 -0400 Subject: [PATCH 2/2] fmt --- src/request.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/request.rs b/src/request.rs index dcad0ff..0c3603c 100644 --- a/src/request.rs +++ b/src/request.rs @@ -75,9 +75,9 @@ where #[cfg(test)] mod tests { - use std::collections::HashMap; - use serde_json; use super::*; + use serde_json; + use std::collections::HashMap; #[test] fn deserializes_request_events() {