Skip to content

Commit 46b4de8

Browse files
committed
Up coverage
1 parent f291311 commit 46b4de8

File tree

6 files changed

+128
-0
lines changed

6 files changed

+128
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"Invalid":data}

test/fixtures/data/valid_json.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"foo":1,"bar":true,"baz":"Hi"}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"Records": [
3+
{
4+
"kinesis": {
5+
"kinesisSchemaVersion": "1.0",
6+
"partitionKey": "a",
7+
"sequenceNumber": "49565441425403787852263465772251211695429557620804943874",
8+
"data": "84mawgogMWRiYjgxMGFhNjQwYTRjYzRkNDM3ZjFjOTk1ZDE5MDkKIDM4OGE1YjExYjFhNDA4ZTNiNWRmOGI4YTVhY2MzMGM5CiBlYzZmODc3MmNjYjQyMzM0NmFkYWJhNjE1ZTc4N2RmNwogODQzMDRjN2RhNjE5MmJmNDAxYmI0YTNkOTZkNGUyZGYKIDllYjUzNzljNGNjNjM4YmU5Nzc0NGEzYjhiZjUxOGI3GnsIABp3eyJuYW1lIjoiaW5mby1sb2ciLCJob3N0bmFtZSI6InRrMi0yMTgtMTg3OTYiLCJwaWQiOjI0MjY4LCJsZXZlbCI6MzAsImNvdW50ZXIiOjExLCJtc2ciOiJUaGlzIGlzIGEgaW5mbyBtZXNzYWdlIiwidiI6MH0aewgBGnd7Im5hbWUiOiJpbmZvLWxvZyIsImhvc3RuYW1lIjoidGsyLTIxOC0xODc5NiIsInBpZCI6MjQyNjgsImxldmVsIjozMCwiY291bnRlciI6MTEsIm1zZyI6IlRoaXMgaXMgYSBpbmZvIG1lc3NhZ2UiLCJ2IjowfRp9CAIaeXsibmFtZSI6ImVycm9yLWxvZyIsImhvc3RuYW1lIjoidGsyLTIxOC0xODc5NiIsInBpZCI6MjQyNjgsImxldmVsIjo1MCwiY291bnRlciI6MTIsIm1zZyI6IlRoaXMgaXMgYSBlcnJvciBtZXNzYWdlIiwidiI6MH0angEIAxqZAXsibmFtZSI6ImRlYnVnLWxvZyIsImhvc3RuYW1lIjoidGsyLTIxOC0xODc5NiIsInBpZCI6MjQyNjgsImxldmVsIjoyMCwiY291bnRlciI6MywiZGF0YSI6eyJmb28iOiJiaXoiLCJiYXIiOmZhbHNlfSwibXNnIjoiVGhpcyBpcyBhIGRlYnVnIG1lc3NhZ2UiLCJ2IjowfRqeAQgEGpkBeyJuYW1lIjoiZGVidWctbG9nIiwiaG9zdG5hbWUiOiJ0azItMjE4LTE4Nzk2IiwicGlkIjoyNDI2OCwibGV2ZWwiOjIwLCJjb3VudGVyIjoxLCJkYXRhIjp7ImZvbyI6ImJpeiIsImJhciI6ZmFsc2V9LCJtc2ciOiJUaGlzIGlzIGEgZGVidWcgbWVzc2FnZSIsInYiOjB99KaxOTkRznQJVnwdxryJ5$==",
9+
"approximateArrivalTimestamp": 1473001463.638
10+
},
11+
"eventSource": "aws:kinesis",
12+
"eventVersion": "1.0",
13+
"eventID": "shardId-000000000000:49565441425403787852263465772251211695429557620804943874",
14+
"eventName": "aws:kinesis:record",
15+
"invokeIdentityArn": "arn:aws:iam::986450800000:role/lambda_basic_execution",
16+
"awsRegion": "ap-northeast-1",
17+
"eventSourceARN": "arn:aws:kinesis:ap-northeast-1:986450800000:stream/kpl-stream"
18+
}
19+
]
20+
}

test/fixtures/events/data-0.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"Records": [
3+
{
4+
"kinesis": {
5+
"kinesisSchemaVersion": "1.0",
6+
"partitionKey": "485bd0f3c7f8b6ec3ddc6ada18abcf8d",
7+
"sequenceNumber": "49565441425403787852263465772329791873704550161163747330",
8+
"data": "ZGF0YQ==",
9+
"approximateArrivalTimestamp": 1473002069.264
10+
},
11+
"eventSource": "aws:kinesis",
12+
"eventVersion": "1.0",
13+
"eventID": "shardId-000000000000:49565441425403787852263465772329791873704550161163747330",
14+
"eventName": "aws:kinesis:record",
15+
"invokeIdentityArn": "arn:aws:iam::986450800000:role/lambda_basic_execution",
16+
"awsRegion": "ap-northeast-1",
17+
"eventSourceARN": "arn:aws:kinesis:ap-northeast-1:986450800000:stream/kpl-stream"
18+
}
19+
]
20+
}

test/json_stream.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const chai = require('chai');
5+
const assert = chai.assert;
6+
7+
const JSONTransform = require('../lib/json_transform');
8+
9+
10+
describe('KinesisLambda.parseJSON', () => {
11+
context('passed valid JSON', () => {
12+
it('raises finish event', (done) => {
13+
const readStream = fs.createReadStream(__dirname + '/fixtures/data/valid_json.txt');
14+
const jsonStream = JSONTransform()
15+
.on('finish', function() {
16+
assert.isOk(true);
17+
done();
18+
})
19+
.on('error', function(err) {
20+
assert.ifError(err);
21+
done();
22+
});
23+
24+
readStream.pipe(jsonStream);
25+
});
26+
});
27+
28+
context('passed invalid JSON', () => {
29+
it('raises error event', (done) => {
30+
const readStream = fs.createReadStream(__dirname + '/fixtures/data/invalid_json.txt');
31+
const jsonStream = JSONTransform()
32+
.on('finish', function() {
33+
assert.isOk(false);
34+
done();
35+
})
36+
.on('error', function(err) {
37+
assert.instanceOf(err, SyntaxError);
38+
done();
39+
});
40+
41+
readStream.pipe(jsonStream);
42+
});
43+
});
44+
});

test/read_stream.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
const es = require('event-stream');
4+
const chai = require('chai');
5+
const assert = chai.assert;
6+
7+
const KLReader = require('../lib/read_stream');
8+
9+
10+
describe('KinesisLambda.reader', () => {
11+
context('called function', () => {
12+
it('OK', () => {
13+
const event = require('./fixtures/events/data-0');
14+
const readStream = KLReader(event);
15+
16+
readStream
17+
.pipe(es.writeArray(function(err, array) {
18+
assert.equal(array[0].toString(), 'data');
19+
}))
20+
.on('end', function() {
21+
assert.isOk(true);
22+
done();
23+
});
24+
});
25+
});
26+
27+
context('aggregation mode', () => {
28+
context('data is invalid base64', () => {
29+
it('raises error event', (done) => {
30+
const event = require('./fixtures/events/agg-data-invalid');
31+
const readStream = KLReader(event, { isAgg: true });
32+
33+
readStream.on('error', function(err) {
34+
assert.instanceOf(err, Error);
35+
done();
36+
});
37+
38+
readStream.pipe(process.stdout);
39+
});
40+
});
41+
});
42+
});

0 commit comments

Comments
 (0)