lambda-stash
Version:
AWS Lambda script for shipping data from S3 or other cloud data sources to data stores, like Elasticsearch
43 lines (36 loc) • 1.31 kB
JavaScript
/* global before, describe, it */
var assert = require("assert");
var fs = require("fs");
var handler = require("../handlers/parseTabs");
describe('handler/parseTabs.js', function() {
describe('#process()', function() {
var dataSource;
var dataJson;
before(function() {
dataSource = fs.readFileSync("test/assets/tabs.source.txt");
dataJson = JSON.parse(fs.readFileSync("test/assets/table.json"));
});
it('should parse tab separated data',
function(done) {
var config = {data: dataSource, setting: true};
handler.process(config)
.then(function(result) {
assert.ok(result.hasOwnProperty('setting'),
'process returns config object');
assert.deepStrictEqual(result.data, dataJson,
'tab separated data parsed successfully');
done();
});
});
it('should fail if malformed tab separated data is provided',
function(done) {
// An unclosed quote should throw an error when processed by csv-parse.
const badData = '"test test\t';
handler.process({data: badData})
.catch(function(err) {
assert.ok(err, 'failure reported for malformed tab separated data');
done();
});
});
});
});