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 pathInvokeContextTest.js
More file actions
66 lines (53 loc) · 1.91 KB
/
InvokeContextTest.js
File metadata and controls
66 lines (53 loc) · 1.91 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*/
'use strict';
require('should');
const sleep = require('util').promisify(setTimeout);
let InvokeContext = require('lambda-runtime/InvokeContext');
describe('Getting remaining invoke time', () => {
it('should reduce by at least elapsed time', async () => {
let ctx = new InvokeContext({
'lambda-runtime-deadline-ms': Date.now() + 1000,
});
const timeout = 100;
let before = ctx._headerData().getRemainingTimeInMillis();
await sleep(timeout + 10);
let after = ctx._headerData().getRemainingTimeInMillis();
(before - after).should.greaterThanOrEqual(
timeout - 1 /* Timers are not precise, allow 1 ms drift */,
);
});
it('should be within range', () => {
let ctx = new InvokeContext({
'lambda-runtime-deadline-ms': Date.now() + 1000,
});
let remainingTime = ctx._headerData().getRemainingTimeInMillis();
remainingTime.should.greaterThan(0);
remainingTime.should.lessThanOrEqual(1000);
});
});
describe('Verifying tenant id', () => {
it('should return undefined if tenant id is not set', () => {
let ctx = new InvokeContext({});
(ctx._headerData().tenantId === undefined).should.be.true();
});
it('should return undefined if tenant id is set to undefined', () => {
let ctx = new InvokeContext({
'lambda-runtime-aws-tenant-id': undefined,
});
(ctx._headerData().tenantId === undefined).should.be.true();
});
it('should return empty if tenant id is set to empty string', () => {
let ctx = new InvokeContext({
'lambda-runtime-aws-tenant-id': '',
});
(ctx._headerData().tenantId === '').should.be.true();
});
it('should return the same id if a valid tenant id is set', () => {
let ctx = new InvokeContext({
'lambda-runtime-aws-tenant-id': 'blue',
});
ctx._headerData().tenantId.should.equal('blue');
});
});