forked from aws/aws-lambda-nodejs-runtime-interface-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuntimeClient.test.ts
More file actions
49 lines (42 loc) · 1.54 KB
/
RuntimeClient.test.ts
File metadata and controls
49 lines (42 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
"use strict";
require("should");
import RuntimeClient from "../../../src/RuntimeClient";
import * as runtimeErrors from "../../../src/Errors";
import { StubHttp } from "../utils/StubHttp";
import { NoOpNativeHttp } from "../utils/NoOpNativeHttp";
class EvilError extends Error {
get name(): string {
throw "gotcha";
}
}
const EXPECTED_ERROR_HEADER = "Lambda-Runtime-Function-Error-Type";
describe("building error requests with the RuntimeClient", () => {
const stubHttp = new StubHttp();
const client = new RuntimeClient(
"notUsed:1337",
stubHttp,
new NoOpNativeHttp()
);
const errors: Array<[Error, string]> = [
[new Error("generic failure"), "Error"],
[new runtimeErrors.ImportModuleError(), "Runtime.ImportModuleError"],
[new runtimeErrors.HandlerNotFound(), "Runtime.HandlerNotFound"],
[new runtimeErrors.MalformedHandlerName(), "Runtime.MalformedHandlerName"],
[new runtimeErrors.UserCodeSyntaxError(), "Runtime.UserCodeSyntaxError"],
[({ data: "some random object" } as unknown) as Error, "object"],
[new EvilError(), "handled"],
];
describe("the error header in postInitError", () => {
errors.forEach(([error, name]) => {
it(`should be ${name} for ${error.constructor.name}`, () => {
client.postInitError(error, () => {
// No op
});
stubHttp.lastUsedOptions.should.have
.property("headers")
.have.property(EXPECTED_ERROR_HEADER, name);
});
});
});
});