2016-09-29 18:11:04 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const assert = require('assert');
|
|
|
|
const fs = require('fs');
|
2016-03-04 15:11:05 -05:00
|
|
|
|
|
|
|
module.exports = function () {
|
2016-09-19 17:13:44 -04:00
|
|
|
this.resetOptionsOutput = () => {
|
|
|
|
this.stdout = null;
|
|
|
|
this.stderr = null;
|
|
|
|
this.exitCode = null;
|
|
|
|
this.termSignal = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.runAndSafeOutput = (binary, options, callback) => {
|
|
|
|
this.runBin(binary, this.expandOptions(options), this.environment, (err, stdout, stderr) => {
|
|
|
|
this.stdout = stdout;
|
|
|
|
this.stderr = stderr;
|
|
|
|
this.exitCode = err && err.code || 0;
|
|
|
|
this.termSignal = err && err.signal || '';
|
|
|
|
callback(err);
|
2016-03-04 15:11:05 -05:00
|
|
|
});
|
2016-09-19 17:13:44 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
this.When(/^I run "osrm\-routed\s?(.*?)"$/, { timeout: this.TIMEOUT }, (options, callback) => {
|
|
|
|
this.runAndSafeOutput('osrm-routed', options, callback);
|
2016-03-04 15:11:05 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
this.When(/^I run "osrm\-extract\s?(.*?)"$/, (options, callback) => {
|
2016-09-29 18:11:04 -04:00
|
|
|
const stamp = this.processedCacheFile + '.extract';
|
|
|
|
this.runAndSafeOutput('osrm-extract', options, (err) => {
|
|
|
|
if (err) return callback(err);
|
|
|
|
fs.writeFile(stamp, 'ok', callback);
|
|
|
|
});
|
2016-03-04 15:11:05 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
this.When(/^I run "osrm\-contract\s?(.*?)"$/, (options, callback) => {
|
2016-09-29 18:11:04 -04:00
|
|
|
const stamp = this.processedCacheFile + '.contract';
|
|
|
|
this.runAndSafeOutput('osrm-contract', options, (err) => {
|
|
|
|
if (err) return callback(err);
|
|
|
|
fs.writeFile(stamp, 'ok', callback);
|
|
|
|
});
|
2016-09-19 17:13:44 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
this.When(/^I try to run "osrm\-routed\s?(.*?)"$/, (options, callback) => {
|
|
|
|
this.runAndSafeOutput('osrm-routed', options, () => { callback(); });
|
|
|
|
});
|
|
|
|
|
|
|
|
this.When(/^I try to run "osrm\-extract\s?(.*?)"$/, (options, callback) => {
|
|
|
|
this.runAndSafeOutput('osrm-extract', options, () => { callback(); });
|
|
|
|
});
|
|
|
|
|
|
|
|
this.When(/^I try to run "osrm\-contract\s?(.*?)"$/, (options, callback) => {
|
|
|
|
this.runAndSafeOutput('osrm-contract', options, () => { callback(); });
|
2016-03-04 15:11:05 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
this.When(/^I run "osrm\-datastore\s?(.*?)"$/, (options, callback) => {
|
2016-09-19 17:13:44 -04:00
|
|
|
this.runAndSafeOutput('osrm-datastore', options, callback);
|
2016-03-04 15:11:05 -05:00
|
|
|
});
|
|
|
|
|
2016-09-19 17:13:44 -04:00
|
|
|
this.Then(/^it should exit successfully$/, () => {
|
|
|
|
assert.equal(this.exitCode, 0);
|
|
|
|
assert.equal(this.termSignal, '');
|
2016-03-04 15:11:05 -05:00
|
|
|
});
|
|
|
|
|
2016-09-19 17:13:44 -04:00
|
|
|
this.Then(/^it should exit with an error$/, () => {
|
|
|
|
assert.ok(this.exitCode !== 0 || this.termSignal);
|
2016-08-05 17:19:22 -04:00
|
|
|
});
|
|
|
|
|
2016-03-04 15:11:05 -05:00
|
|
|
this.Then(/^stdout should contain "(.*?)"$/, (str) => {
|
|
|
|
assert.ok(this.stdout.indexOf(str) > -1);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.Then(/^stderr should contain "(.*?)"$/, (str) => {
|
|
|
|
assert.ok(this.stderr.indexOf(str) > -1);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.Then(/^stdout should contain \/(.*)\/$/, (regexStr) => {
|
2016-09-29 18:11:04 -04:00
|
|
|
const re = new RegExp(regexStr);
|
2016-03-04 15:11:05 -05:00
|
|
|
assert.ok(this.stdout.match(re));
|
|
|
|
});
|
|
|
|
|
|
|
|
this.Then(/^stderr should contain \/(.*)\/$/, (regexStr) => {
|
2016-09-29 18:11:04 -04:00
|
|
|
const re = new RegExp(regexStr);
|
2016-03-04 15:11:05 -05:00
|
|
|
assert.ok(this.stdout.match(re));
|
|
|
|
});
|
|
|
|
|
|
|
|
this.Then(/^stdout should be empty$/, () => {
|
|
|
|
assert.equal(this.stdout.trim(), '');
|
|
|
|
});
|
|
|
|
|
|
|
|
this.Then(/^stderr should be empty$/, () => {
|
|
|
|
assert.equal(this.stderr.trim(), '');
|
|
|
|
});
|
|
|
|
|
|
|
|
this.Then(/^stdout should contain (\d+) lines?$/, (lines) => {
|
|
|
|
assert.equal(this.stdout.split('\n').length - 1, parseInt(lines));
|
|
|
|
});
|
|
|
|
|
2016-09-12 12:16:56 -04:00
|
|
|
this.Then(/^stderr should contain (\d+) lines?$/, (lines) => {
|
|
|
|
assert.equal(this.stderr.split('\n').length - 1, parseInt(lines));
|
|
|
|
});
|
|
|
|
|
2016-05-23 18:10:50 -04:00
|
|
|
this.Then(/^datasource names should contain "(.+)"$/, (expectedData) => {
|
2016-09-29 18:11:04 -04:00
|
|
|
const actualData = fs.readFileSync(this.processedCacheFile + '.datasource_names', {encoding:'UTF-8'}).trim().split('\n').join(',');
|
2016-05-23 18:10:50 -04:00
|
|
|
assert.equal(actualData, expectedData);
|
|
|
|
});
|
|
|
|
|
2016-03-04 15:11:05 -05:00
|
|
|
this.Given(/^the query options$/, (table, callback) => {
|
2016-03-29 13:35:56 -04:00
|
|
|
table.raw().forEach(tuple => {
|
2016-03-29 13:39:48 -04:00
|
|
|
this.queryParams[tuple[0]] = tuple[1];
|
2016-03-04 15:11:05 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
};
|