Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
a bunch more tests for failure states + some disabled due to Project-…
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Aug 7, 2013
1 parent 7ca1a7b commit 6e832b4
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 4 deletions.
Empty file added test/data/blank.edges
Empty file.
Empty file added test/data/blank.fileIndex
Empty file.
Empty file added test/data/blank.hsgr
Empty file.
Empty file added test/data/blank.names
Empty file.
Empty file added test/data/blank.nodes
Empty file.
Empty file added test/data/blank.ramIndex
Empty file.
Empty file added test/data/blank.timestamp
Empty file.
Empty file added test/data/bogus.ini
Empty file.
11 changes: 11 additions & 0 deletions test/data/references-corrupt-files.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Threads = 8
IP = 0.0.0.0
Port = 9000

hsgrData=blank.hsgr
nodesData=blank.nodes
edgesData=blank.edges
ramIndex=blank.ramIndex
fileIndex=blank.fileIndex
namesData=blank.names
timestamp=blank.timestamp
11 changes: 11 additions & 0 deletions test/data/references-missing-files.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Threads = 8
IP = 0.0.0.0
Port = 5000

hsgrData=doesnotexist.hsgr
nodesData=doesnotexist.nodes
edgesData=doesnotexist.edges
ramIndex=doesnotexist.ramIndex
fileIndex=doesnotexist.fileIndex
namesData=doesnotexist.names
timestamp=doesnotexist.timestamp
60 changes: 56 additions & 4 deletions test/osrm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,63 @@ var osrm = require('osrm');
var assert = require('assert');

describe('osrm', function() {

it('should throw if new keyword is not used', function(done) {
assert.throws(function() { osrm.Engine("../server.ini"); },
/Cannot call constructor as function, you need to use 'new' keyword/);
done();
});

it('should throw if invalid args are passed', function(done) {
assert.throws(function() { new osrm.Engine(99999); },
/OSRM config path must be a string/);
done();
});

// @TODO not safe yet to test: https://github.com/DennisOSRM/Project-OSRM/issues/692
it.skip('should throw if ini file does not exist', function(done) {
assert.throws(function() { new osrm.Engine("./test/data/bogus.ini"); },
/@TODO/);
done();
});

// @TODO - should provide better error:
// https://github.com/DennisOSRM/Project-OSRM/commit/34735b8aad06098d09d3fb907137697799a281e4#commitcomment-3809465
it('should throw if ini file does not exist', function(done) {
assert.throws(function() { new osrm.Engine("doesnotexist.ini"); },
/server.ini not found/);
done();
});

it('should throw if files referenced by ini do not exist', function(done) {
assert.throws(function() { new osrm.Engine("./test/data/references-missing-files.ini"); },
/hsgr not found/);
done();
});


// @TODO not safe yet to test: https://github.com/DennisOSRM/Project-OSRM/issues/693
it.skip('should throw if ini port option is invalid', function(done) {
assert.throws(function() { new osrm.Engine("./test/data/references-corrupt-files.ini"); },
/hsgr not found/);
done();
});

it('should be initialized', function(done) {
var engine = new osrm.Engine("../server.ini");
var query = new osrm.Query( { start: [ 47.68757916850813,-122.38494873046875 ],
end: [ 47.674635091761616, -122.2943115234375 ]
});
var engine = new osrm.Engine("./test/data/berlin.ini");
assert.ok(engine);
done();
});

it('should return results for berlin using sync api', function(done) {
var engine = new osrm.Engine("./test/data/berlin.ini");
// http://geojson.io/#6177953 | https://gist.github.com/anonymous/6177953
var start = [13.362293243408203,52.502429681191614];
var end = [13.405036926269531,52.54347705679033];
// ugh, lat/lon not lon/lat?
start.reverse();
end.reverse();
var query = new osrm.Query( { start: start, end: end });
var sync_result = engine.run(query);
engine.run(query,function(err,async_result) {
assert.equal(sync_result,async_result);
Expand Down

0 comments on commit 6e832b4

Please sign in to comment.