-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathlog-stream.js
More file actions
56 lines (46 loc) · 1.55 KB
/
Copy pathlog-stream.js
File metadata and controls
56 lines (46 loc) · 1.55 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
'use strict'
const { mockClient } = require('aws-sdk-client-mock');
const { CloudWatchLogs, GetLogEventsCommand } = require("@aws-sdk/client-cloudwatch-logs");
const expect = require('expect.js');
const LogsStream = require('../lib/log-stream');
describe('LogStream', function () {
this.timeout(5000);
let cwlMock ;
beforeEach(() => {
cwlMock = mockClient(CloudWatchLogs);
});
const options = {
logGroup: 'yee',
logStream: `yo`,
endOfStreamIdentifier: 'ohiv09vaepnjpasv'
}
const staticLogs = [
{ timestamp: 1477346285562, message: 'Weee logs' },
{ timestamp: 1477346285563, message: 'more logs' },
{ timestamp: 1477346285565, message: `TASK FINISHED: ${Buffer.from(options.endOfStreamIdentifier).toString('base64')}, EXITCODE: 44` }
];
it('should fetch logs from AWS Cloudwatch ', function (done) {
let invocationCount = 0;
cwlMock.on(GetLogEventsCommand).callsFake((params) => {
expect(params.logGroupName).to.equal(options.logGroup);
expect(params.logStreamName).to.equal(options.logStream);
const response = { events: [staticLogs[invocationCount]] };
invocationCount++;
return new Promise((resolve) => {
setTimeout(() => {
resolve(response)
}, 200);
});
});
const stream = new LogsStream(options);
let logsCollection = [];
stream.on('data', (data) => {
logsCollection.push(data);
});
stream.on('end', () => {
expect(logsCollection).to.eql(staticLogs);
expect(stream.exitCode).to.eql(44);
done();
});
});
});