github.com/orteth01/up@v0.2.0/internal/proxy/event_test.go (about) 1 package proxy 2 3 import ( 4 "encoding/json" 5 "fmt" 6 ) 7 8 var getEvent = `{ 9 "resource": "/{proxy+}", 10 "path": "/pets/tobi", 11 "httpMethod": "GET", 12 "headers": { 13 "Accept": "*/*", 14 "CloudFront-Forwarded-Proto": "https", 15 "CloudFront-Is-Desktop-Viewer": "true", 16 "CloudFront-Is-Mobile-Viewer": "false", 17 "CloudFront-Is-SmartTV-Viewer": "false", 18 "CloudFront-Is-Tablet-Viewer": "false", 19 "CloudFront-Viewer-Country": "CA", 20 "Host": "apex-ping.com", 21 "User-Agent": "curl/7.48.0", 22 "Via": "2.0 a44b4468444ef3ee67472bd5c5016098.cloudfront.net (CloudFront)", 23 "X-Amz-Cf-Id": "VRxPGF8rOXD7xpRjAjseXfRrFD3wg-QPUHY6chzB9bR7pXlct1NTpg==", 24 "X-Amzn-Trace-Id": "Root=1-59554c99-4375fc8705ccb554008b3aad", 25 "X-Forwarded-For": "207.102.57.26, 54.182.214.69", 26 "X-Forwarded-Port": "443", 27 "X-Forwarded-Proto": "https" 28 }, 29 "queryStringParameters": { 30 "format": "json" 31 }, 32 "pathParameters": { 33 "proxy": "pets/tobi" 34 }, 35 "stageVariables": { 36 "env": "prod" 37 }, 38 "requestContext": { 39 "path": "/pets/tobi", 40 "accountId": "111111111", 41 "resourceId": "jcl9w3", 42 "stage": "prod", 43 "requestId": "344b184b-5cfc-11e7-8483-27dbb2d30a77", 44 "identity": { 45 "cognitoIdentityPoolId": null, 46 "accountId": null, 47 "cognitoIdentityId": null, 48 "caller": null, 49 "apiKey": "", 50 "sourceIp": "207.102.57.26", 51 "accessKey": null, 52 "cognitoAuthenticationType": null, 53 "cognitoAuthenticationProvider": null, 54 "userArn": null, 55 "userAgent": "curl/7.48.0", 56 "user": null 57 }, 58 "resourcePath": "/{proxy+}", 59 "httpMethod": "GET", 60 "apiId": "iwcgwgigca" 61 }, 62 "body": null, 63 "isBase64Encoded": false 64 }` 65 66 var postEvent = `{ 67 "resource": "/{proxy+}", 68 "path": "/pets/tobi", 69 "httpMethod": "POST", 70 "headers": { 71 "Accept": "*/*", 72 "CloudFront-Forwarded-Proto": "https", 73 "CloudFront-Is-Desktop-Viewer": "true", 74 "CloudFront-Is-Mobile-Viewer": "false", 75 "CloudFront-Is-SmartTV-Viewer": "false", 76 "CloudFront-Is-Tablet-Viewer": "false", 77 "CloudFront-Viewer-Country": "CA", 78 "content-type": "application/json", 79 "Host": "apex-ping.com", 80 "User-Agent": "curl/7.48.0", 81 "Via": "2.0 b790a9f06b09414fec5d8b87e81d4b7f.cloudfront.net (CloudFront)", 82 "X-Amz-Cf-Id": "_h1jFD3wjq6ZIyr8be6RS7Y7665jF9SjACmVodBMRefoQCs7KwTxMw==", 83 "X-Amzn-Trace-Id": "Root=1-59554cc9-35de2f970f0fdf017f16927f", 84 "X-Forwarded-For": "207.102.57.26, 54.182.214.86", 85 "X-Forwarded-Port": "443", 86 "X-Forwarded-Proto": "https" 87 }, 88 "queryStringParameters": null, 89 "pathParameters": { 90 "proxy": "pets/tobi" 91 }, 92 "requestContext": { 93 "path": "/pets/tobi", 94 "accountId": "111111111", 95 "resourceId": "jcl9w3", 96 "stage": "prod", 97 "requestId": "50f6e0ce-5cfc-11e7-ada1-4f5cfe727f01", 98 "identity": { 99 "cognitoIdentityPoolId": null, 100 "accountId": null, 101 "cognitoIdentityId": null, 102 "caller": null, 103 "apiKey": "", 104 "sourceIp": "207.102.57.26", 105 "accessKey": null, 106 "cognitoAuthenticationType": null, 107 "cognitoAuthenticationProvider": null, 108 "userArn": null, 109 "userAgent": "curl/7.48.0", 110 "user": null 111 }, 112 "resourcePath": "/{proxy+}", 113 "httpMethod": "POST", 114 "apiId": "iwcgwgigca" 115 }, 116 "body": "{ \"name\": \"Tobi\" }", 117 "isBase64Encoded": false 118 }` 119 120 var postEventBinary = `{ 121 "resource": "/{proxy+}", 122 "path": "/pets/tobi", 123 "httpMethod": "POST", 124 "headers": { 125 "Accept": "*/*", 126 "CloudFront-Forwarded-Proto": "https", 127 "CloudFront-Is-Desktop-Viewer": "true", 128 "CloudFront-Is-Mobile-Viewer": "false", 129 "CloudFront-Is-SmartTV-Viewer": "false", 130 "CloudFront-Is-Tablet-Viewer": "false", 131 "CloudFront-Viewer-Country": "CA", 132 "content-type": "text/plain", 133 "Host": "apex-ping.com", 134 "User-Agent": "curl/7.48.0", 135 "Via": "2.0 b790a9f06b09414fec5d8b87e81d4b7f.cloudfront.net (CloudFront)", 136 "X-Amz-Cf-Id": "_h1jFD3wjq6ZIyr8be6RS7Y7665jF9SjACmVodBMRefoQCs7KwTxMw==", 137 "X-Amzn-Trace-Id": "Root=1-59554cc9-35de2f970f0fdf017f16927f", 138 "X-Forwarded-For": "207.102.57.26, 54.182.214.86", 139 "X-Forwarded-Port": "443", 140 "X-Forwarded-Proto": "https" 141 }, 142 "queryStringParameters": null, 143 "pathParameters": { 144 "proxy": "pets/tobi" 145 }, 146 "requestContext": { 147 "path": "/pets/tobi", 148 "accountId": "111111111", 149 "resourceId": "jcl9w3", 150 "stage": "prod", 151 "requestId": "50f6e0ce-5cfc-11e7-ada1-4f5cfe727f01", 152 "identity": { 153 "cognitoIdentityPoolId": null, 154 "accountId": null, 155 "cognitoIdentityId": null, 156 "caller": null, 157 "apiKey": "", 158 "sourceIp": "207.102.57.26", 159 "accessKey": null, 160 "cognitoAuthenticationType": null, 161 "cognitoAuthenticationProvider": null, 162 "userArn": null, 163 "userAgent": "curl/7.48.0", 164 "user": null 165 }, 166 "resourcePath": "/{proxy+}", 167 "httpMethod": "POST", 168 "apiId": "iwcgwgigca" 169 }, 170 "body": "SGVsbG8gV29ybGQ=", 171 "isBase64Encoded": true 172 }` 173 174 func output(v interface{}) { 175 b, _ := json.MarshalIndent(v, "", " ") 176 fmt.Printf("%s\n", string(b)) 177 } 178 179 func ExampleInput_get() { 180 var in Input 181 json.Unmarshal([]byte(getEvent), &in) 182 output(in) 183 // Output: 184 // { 185 // "HTTPMethod": "GET", 186 // "Headers": { 187 // "Accept": "*/*", 188 // "CloudFront-Forwarded-Proto": "https", 189 // "CloudFront-Is-Desktop-Viewer": "true", 190 // "CloudFront-Is-Mobile-Viewer": "false", 191 // "CloudFront-Is-SmartTV-Viewer": "false", 192 // "CloudFront-Is-Tablet-Viewer": "false", 193 // "CloudFront-Viewer-Country": "CA", 194 // "Host": "apex-ping.com", 195 // "User-Agent": "curl/7.48.0", 196 // "Via": "2.0 a44b4468444ef3ee67472bd5c5016098.cloudfront.net (CloudFront)", 197 // "X-Amz-Cf-Id": "VRxPGF8rOXD7xpRjAjseXfRrFD3wg-QPUHY6chzB9bR7pXlct1NTpg==", 198 // "X-Amzn-Trace-Id": "Root=1-59554c99-4375fc8705ccb554008b3aad", 199 // "X-Forwarded-For": "207.102.57.26, 54.182.214.69", 200 // "X-Forwarded-Port": "443", 201 // "X-Forwarded-Proto": "https" 202 // }, 203 // "Resource": "/{proxy+}", 204 // "PathParameters": { 205 // "proxy": "pets/tobi" 206 // }, 207 // "Path": "/pets/tobi", 208 // "QueryStringParameters": { 209 // "format": "json" 210 // }, 211 // "Body": "", 212 // "IsBase64Encoded": false, 213 // "StageVariables": { 214 // "env": "prod" 215 // }, 216 // "RequestContext": { 217 // "APIID": "iwcgwgigca", 218 // "ResourceID": "jcl9w3", 219 // "RequestID": "344b184b-5cfc-11e7-8483-27dbb2d30a77", 220 // "HTTPMethod": "GET", 221 // "ResourcePath": "/{proxy+}", 222 // "AccountID": "111111111", 223 // "Stage": "prod", 224 // "Identity": { 225 // "APIKey": "", 226 // "AccountID": "", 227 // "UserAgent": "curl/7.48.0", 228 // "SourceIP": "207.102.57.26", 229 // "AccessKey": "", 230 // "Caller": "", 231 // "User": "", 232 // "UserARN": "", 233 // "CognitoIdentityID": "", 234 // "CognitoIdentityPoolID": "", 235 // "CognitoAuthenticationType": "", 236 // "CognitoAuthenticationProvider": "" 237 // } 238 // } 239 // } 240 } 241 242 func ExampleInput_post() { 243 var in Input 244 json.Unmarshal([]byte(postEvent), &in) 245 output(in) 246 // Output: 247 // { 248 // "HTTPMethod": "POST", 249 // "Headers": { 250 // "Accept": "*/*", 251 // "CloudFront-Forwarded-Proto": "https", 252 // "CloudFront-Is-Desktop-Viewer": "true", 253 // "CloudFront-Is-Mobile-Viewer": "false", 254 // "CloudFront-Is-SmartTV-Viewer": "false", 255 // "CloudFront-Is-Tablet-Viewer": "false", 256 // "CloudFront-Viewer-Country": "CA", 257 // "Host": "apex-ping.com", 258 // "User-Agent": "curl/7.48.0", 259 // "Via": "2.0 b790a9f06b09414fec5d8b87e81d4b7f.cloudfront.net (CloudFront)", 260 // "X-Amz-Cf-Id": "_h1jFD3wjq6ZIyr8be6RS7Y7665jF9SjACmVodBMRefoQCs7KwTxMw==", 261 // "X-Amzn-Trace-Id": "Root=1-59554cc9-35de2f970f0fdf017f16927f", 262 // "X-Forwarded-For": "207.102.57.26, 54.182.214.86", 263 // "X-Forwarded-Port": "443", 264 // "X-Forwarded-Proto": "https", 265 // "content-type": "application/json" 266 // }, 267 // "Resource": "/{proxy+}", 268 // "PathParameters": { 269 // "proxy": "pets/tobi" 270 // }, 271 // "Path": "/pets/tobi", 272 // "QueryStringParameters": null, 273 // "Body": "{ \"name\": \"Tobi\" }", 274 // "IsBase64Encoded": false, 275 // "StageVariables": null, 276 // "RequestContext": { 277 // "APIID": "iwcgwgigca", 278 // "ResourceID": "jcl9w3", 279 // "RequestID": "50f6e0ce-5cfc-11e7-ada1-4f5cfe727f01", 280 // "HTTPMethod": "POST", 281 // "ResourcePath": "/{proxy+}", 282 // "AccountID": "111111111", 283 // "Stage": "prod", 284 // "Identity": { 285 // "APIKey": "", 286 // "AccountID": "", 287 // "UserAgent": "curl/7.48.0", 288 // "SourceIP": "207.102.57.26", 289 // "AccessKey": "", 290 // "Caller": "", 291 // "User": "", 292 // "UserARN": "", 293 // "CognitoIdentityID": "", 294 // "CognitoIdentityPoolID": "", 295 // "CognitoAuthenticationType": "", 296 // "CognitoAuthenticationProvider": "" 297 // } 298 // } 299 // } 300 }