Skip to content

Commit

Permalink
Test context headers
Browse files Browse the repository at this point in the history
  • Loading branch information
hayd committed Nov 9, 2019
1 parent aa6fa6c commit 6fcdb2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
24 changes: 13 additions & 11 deletions tests/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const p = Deno.run({

const events = eventsGen();

let reqId = 1;
let reqId = 0;
for await (const req of s) {
if (req.method == "POST") {
if (req.url.endsWith("/response")) {
Expand All @@ -44,31 +44,33 @@ for await (const req of s) {
} else if (req.url.endsWith("/init/error")) {
const body = decode.decode(await req.body());
console.log(JSON.stringify({ status: "error", content: body }));
await req.respond({ body: statusOK });
p.kill(9);
s.close();
Deno.exit();
} else if (req.url.endsWith("/null/error")) {
// req.url.endsWith(`${reqId}/error`
} else if (req.url.endsWith(`/${reqId}/error`)) {
const body = decode.decode(await req.body());
console.log(JSON.stringify({ status: "error", content: body }));
} else {
throw new Error("Unreachable!")
}
// handle initError
// raise on other?
await req.respond({ body: statusOK });
} else {
// assert endsWith /next
const e = events.next();
if (e.done) {
p.kill(9);
s.close();
Deno.exit();
} else {
// TODO add this back in (currently it breaks the tests!):
// const headers = new Headers({
// 'lambda-runtime-invoked-function-arn': "arn:aws:lambda:us-east-1:776893852117:function:test",
// 'lambda-runtime-aws-request-id': reqId.toString(),
// 'lambda-runtime-deadline-ms': (Date.now() + 300000).toString()
// })
await req.respond({ body: encode(JSON.stringify(e.value)) });
reqId++;
const headers = new Headers({
'lambda-runtime-invoked-function-arn': "arn:aws:lambda:us-east-1:776893852117:function:test",
'lambda-runtime-aws-request-id': reqId.toString(),
'lambda-runtime-deadline-ms': (Date.now() + 300000).toString()
})
await req.respond({ body: encode(JSON.stringify(e.value)), headers });
}
}
}
4 changes: 2 additions & 2 deletions tests/test_context.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"expected": [
{
"status": "ok",
"content": "{\"name\":\"test\",\"awsRequestId\":null}"
"content": "{\"name\":\"test\",\"awsRequestId\":\"1\"}"
},
{
"status": "ok",
"content": "{\"name\":\"test\",\"awsRequestId\":null}"
"content": "{\"name\":\"test\",\"awsRequestId\":\"2\"}"
}
],
"files": ["handlers.ts"],
Expand Down

0 comments on commit 6fcdb2e

Please sign in to comment.