Skip to content

Commit

Permalink
Merge pull request #366 from benetis/feature/move-away-from-event-stream
Browse files Browse the repository at this point in the history
tests(streams) change event-stream to stream-mock
  • Loading branch information
orangejulius authored Jul 12, 2019
2 parents b0b4a52 + abc9424 commit 47ac37f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"devDependencies": {
"deep-diff": "^1.0.0",
"event-stream": "^4.0.0",
"stream-mock": "^2.0.3",
"pelias-mock-logger": "^1.1.0",
"precommit-hook": "^3.0.0",
"proxyquire": "^2.0.0",
Expand Down
48 changes: 26 additions & 22 deletions test/importTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,20 @@ var fs = require( 'fs' );
var path = require( 'path');

var tape = require( 'tape' );
var event_stream = require( 'event-stream' );
var deep = require( 'deep-diff' );
const proxyquire = require('proxyquire').noCallThru();
const through = require('through2');
const stream_mock = require('stream-mock');

tape('functional test importing Singapore', function(t) {
var basePath = path.resolve(__dirname);
var expectedPath = path.join(basePath, 'data', 'expected.json');
var inputFile = path.join(basePath, 'data', 'SG.zip');
const basePath = path.resolve(__dirname);
const expectedPath = path.join(basePath, 'data', 'expected.json');
const inputFile = path.join(basePath, 'data', 'SG.zip');

var sourceStream = fs.createReadStream(inputFile);
var expected = JSON.parse(fs.readFileSync(expectedPath));
const sourceStream = fs.createReadStream(inputFile);
const expected = JSON.parse(fs.readFileSync(expectedPath));

var endStream = event_stream.writeArray(function(err, results) {
// uncomment this to write the actual results to the expected file
// make sure they look ok though. comma left off so jshint reminds you
// not to commit this line
// fs.writeFileSync(expectedPath, JSON.stringify(results, null, 2))

var diff = deep(expected, results);

if (diff) {
t.fail('expected and actual output are the same');
console.error(diff);
} else {
t.pass('expected and actual output are the same');
}
t.end();
});
const endStream = new stream_mock.ObjectWritableMock();

// need to mock out pelias-wof-admin-lookup because it reads its own config
// and we don't want an actual adminLookup stream
Expand All @@ -43,4 +28,23 @@ tape('functional test importing Singapore', function(t) {
} );

importModule(sourceStream, endStream);

endStream.on('finish', function() {
const actual = endStream.data;

// uncomment this to write the actual results to the expected file
// make sure they look ok though. semicolon left off so jshint reminds you
// not to commit this line
// fs.writeFileSync(expectedPath, JSON.stringify(actual, null, 2))

const diff = deep(expected, actual);

if (diff) {
t.fail('expected and actual output are the same');
console.error(diff);
} else {
t.pass('expected and actual output are the same');
}
t.end();
});
});
12 changes: 7 additions & 5 deletions test/streams/layerMappingStreamTest.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
var tape = require('tape');
var event_stream = require('event-stream');

var layerMappingStream = require('../../lib/streams/layerMappingStream');
var featureCodeToLayer = layerMappingStream.featureCodeToLayer;

function test_stream(input, testedStream, callback) {
var input_stream = event_stream.readArray(input);
var destination_stream = event_stream.writeArray(callback);
const stream_mock = require('stream-mock');

input_stream.pipe(testedStream).pipe(destination_stream);
function test_stream(input, testedStream, callback) {
const reader = new stream_mock.ObjectReadableMock(input);
const writer = new stream_mock.ObjectWritableMock();
writer.on('error', (e) => callback(e));
writer.on('finish', () => callback(null, writer.data));
reader.pipe(testedStream).pipe(writer);
}

tape('featureCodeToLayer', function(test) {
Expand Down
13 changes: 8 additions & 5 deletions test/streams/overrideLookedUpLocalityAndLocaladmin.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
var tape = require('tape');
var event_stream = require('event-stream');
var Document = require('pelias-model').Document;

var overrideLookedUpLocalityAndLocaladmin = require('../../lib/streams/overrideLookedUpLocalityAndLocaladmin');

function test_stream(input, testedStream, callback) {
var input_stream = event_stream.readArray(input);
var destination_stream = event_stream.writeArray(callback);
const stream_mock = require('stream-mock');

input_stream.pipe(testedStream).pipe(destination_stream);
function test_stream(input, testedStream, callback) {
const reader = new stream_mock.ObjectReadableMock(input);
const writer = new stream_mock.ObjectWritableMock();
writer.on('error', (e) => callback(e));
writer.on('finish', () => callback(null, writer.data));
reader.pipe(testedStream).pipe(writer);
}


tape('peliasDocGenerator', function(test) {
test.test('document with layer=locality should overwrite locality parent with name and id', function(t) {
var input = new Document( 'geonames', 'locality', '17' )
Expand Down
12 changes: 7 additions & 5 deletions test/streams/peliasDocGeneratorTest.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
var tape = require('tape');
var Document = require('pelias-model').Document;
var peliasDocGenerator = require('../../lib/streams/peliasDocGenerator');
var event_stream = require('event-stream');
const proxyquire = require('proxyquire').noCallThru();
const stream_mock = require('stream-mock');

function test_stream(input, testedStream, callback) {
var input_stream = event_stream.readArray(input);
var destination_stream = event_stream.writeArray(callback);

input_stream.pipe(testedStream).pipe(destination_stream);
const reader = new stream_mock.ObjectReadableMock(input);
const writer = new stream_mock.ObjectWritableMock();
writer.on('error', (e) => callback(e));
writer.on('finish', () => callback(null, writer.data));
reader.pipe(testedStream).pipe(writer);
}


tape('peliasDocGenerator', function(test) {
test.test('basic data should should be returned as Document objects with only ' +
'name and centroid supplied', function(t) {
Expand Down

0 comments on commit 47ac37f

Please sign in to comment.