Skip to content

Commit

Permalink
Merge pull request #83 from pelias/tag-generation-tests
Browse files Browse the repository at this point in the history
Improve tag generation
  • Loading branch information
orangejulius authored Aug 21, 2019
2 parents d0da681 + 2a1be89 commit 07352d8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 12 deletions.
5 changes: 3 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"node": true,
"curly": true,
"eqeqeq": true,
"esversion": 6,
"freeze": true,
"immed": true,
"indent": 2,
Expand All @@ -14,8 +15,8 @@
"plusplus": false,
"quotmark": "single",
"undef": true,
"unused": true,
"unused": false,
"maxparams": 4,
"maxdepth": 4,
"maxlen": 120
"maxlen": 140
}
12 changes: 4 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var util = require('util'),
split = require('split'),
through = require('through2'),
child = require('child_process'),
exec = path.join(__dirname, 'build', util.format( 'pbf2json.%s-%s', os.platform(), os.arch() ) );
exec = path.join(__dirname, 'build', util.format( 'pbf2json.%s-%s', os.platform(), os.arch() ) ),
generateParams = require('./lib/generateParams');

// custom log levels can be detected for lines with the format:
// [level] message
Expand All @@ -29,14 +30,9 @@ function errorHandler( name, level ){

function createReadStream( config ){

var flags = [];
flags.push( util.format( '-tags=%s', config.tags ) );
if( config.hasOwnProperty( 'leveldb' ) ){
flags.push( util.format( '-leveldb=%s', config.leveldb ) );
}
flags.push( config.file );
const params = generateParams(config);

var proc = child.spawn( exec, flags );
var proc = child.spawn( exec, params );

// propagate signals from parent to child
process.on('SIGINT', function(){ proc.kill(); });
Expand Down
17 changes: 17 additions & 0 deletions lib/generateParams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function generateParams(config) {
const flags = [];

if (config.tags) {
const tags = config.tags.join(',');
flags.push( `-tags=${tags}` );
}
if( config.hasOwnProperty( 'leveldb' ) ){
flags.push( `-leveldb=${config.leveldb}` );
}

flags.push( config.file );

return flags;
}

module.exports = generateParams;
43 changes: 43 additions & 0 deletions test/lib/generateParams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const generateParams = require('../../lib/generateParams');

module.exports.tests = {};

module.exports.tests.params = function(test) {
test('PBF file', function(t) {
const config = {
file: '/some/path/to/osm.pbf'
};

const params = generateParams(config);

t.equal(params[params.length - 1], '/some/path/to/osm.pbf', 'final parameter is path to PBF file');
t.end();
});
test('PBF file', function(t) {
const config = {
tags: [
'tag:one',
'tag:two',
'combination~tags'
]
};

const params = generateParams(config);

const expected = '-tags=tag:one,tag:two,combination~tags';

t.equal(params[0], expected, 'tag array is serialized into parameter');
t.end();
});
};

module.exports.all = function (tape, common) {

function test(name, testFunction) {
return tape('generateParams: ' + name, testFunction);
}

for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};
5 changes: 3 additions & 2 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ var tape = require('tape');
var common = {};

var tests = [
require('./index.js')
require('./index.js'),
require('./lib/generateParams.js')
];

tests.map(function(t) {
t.all(tape, common);
});
});

0 comments on commit 07352d8

Please sign in to comment.