Skip to content

Commit

Permalink
Add some unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
connormanning committed Feb 9, 2017
1 parent 067a90a commit 8a0d3bf
Show file tree
Hide file tree
Showing 11 changed files with 738 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -6,4 +6,4 @@ build/*
*.gypi

data/*
!data/autzen.las

Binary file removed data/autzen.las
Binary file not shown.
13 changes: 12 additions & 1 deletion package.json
Expand Up @@ -8,12 +8,17 @@
"engines": {
"node": ">=4.0.0"
},
"scripts": {
"start": "./src/forever.js",
"debug": "NODE_ENV=debug node-gyp build --debug && ./src/app.js --debug",
"test": "mocha ./test --recursive --slow 5000 --timeout 5000"
},
"bin": {
"greyhound": "./src/forever.js",
"greyhound-solo": "./src/app.js"
},
"dependencies": {
"bluebird": "^3.2.2",
"bluebird": "^3.4.7",
"body-parser": "^1.14.2",
"bytes": "^2.4.0",
"clim": "^1.0.0",
Expand All @@ -29,5 +34,11 @@
"morgan": "^1.6.1",
"node-uuid": "^1.4.7",
"request": "^2.69.0"
},
"devDependencies": {
"chai": "^3.5.0",
"chai-http": "^3.0.0",
"mocha": "^3.2.0",
"sync-request": "^4.0.1"
}
}
19 changes: 19 additions & 0 deletions scripts/generate-test-data.sh
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
cd $DIR/../data

# Normally we'd glob here, but that's not possible with the HTTP interface.
TESTING_SHALLOW=true entwine build \
-i \
"https://s3.amazonaws.com/hobu-lidar/greyhound-test-data/ellipsoid/ned.laz" \
"https://s3.amazonaws.com/hobu-lidar/greyhound-test-data/ellipsoid/neu.laz" \
"https://s3.amazonaws.com/hobu-lidar/greyhound-test-data/ellipsoid/nwd.laz" \
"https://s3.amazonaws.com/hobu-lidar/greyhound-test-data/ellipsoid/nwu.laz" \
"https://s3.amazonaws.com/hobu-lidar/greyhound-test-data/ellipsoid/sed.laz" \
"https://s3.amazonaws.com/hobu-lidar/greyhound-test-data/ellipsoid/seu.laz" \
"https://s3.amazonaws.com/hobu-lidar/greyhound-test-data/ellipsoid/swd.laz" \
"https://s3.amazonaws.com/hobu-lidar/greyhound-test-data/ellipsoid/swu.laz" \
-o \
ellipsoid

43 changes: 0 additions & 43 deletions test.js

This file was deleted.

5 changes: 5 additions & 0 deletions test/common.js
@@ -0,0 +1,5 @@
module.exports = {
server: 'http://localhost:8080',
resource: '/resource/ellipsoid'
};

189 changes: 189 additions & 0 deletions test/files.js
@@ -0,0 +1,189 @@
var common = require('./common');
var server = common.server;
var resource = common.resource;

var chai = require('chai');
var chaiHttp = require('chai-http');
var should = chai.should();
var expect = chai.expect;
chai.use(chaiHttp);

describe('files', () => {
it('404s nonexistent resources', (done) => {
chai.request(server).get('/resource/asdf/files/0')
.end((err, res) => {
res.should.have.status(404);
done();
});
});

it('400s empty searches', (done) => {
chai.request(server).get(resource + '/files')
.end((err, res) => {
res.should.have.status(400);
done();
});
});

it('400s searches with both bounds and files', (done) => {
var q = '/files?bounds=[0,0,0,1,1,1]&search=0'
chai.request(server).get(resource + q)
.end((err, res) => {
res.should.have.status(400);
done();
});
});

var check = (r, origin, path) => {
r.should.have.property('bounds');
r.bounds.should.be.an('array');
r.bounds.should.have.lengthOf(6);

r.should.have.property('metadata');
r.metadata.should.be.an('object');

r.should.have.property('numPoints');
r.numPoints.should.be.a('number');

r.should.have.property('origin');
r.origin.should.be.a('number');
if (origin != null) r.origin.should.equal(origin);

r.should.have.property('path');
r.path.should.be.a('string');
if (path != null) r.path.should.match(new RegExp(path));

r.should.have.property('pointStats');
r.pointStats.should.be.an('object');
r.pointStats.should.have.property('inserts');
r.pointStats.should.have.property('outOfBounds');
r.pointStats.should.have.property('overflows');

r.should.have.property('status');
r.status.should.equal('inserted');
};

it('returns file info by origin ID', (done) => {
chai.request(server).get(resource + '/files/0')
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.an('object');
check(res.body, 0);
done();
});
});

it('returns file info by query-parameters origin ID', (done) => {
chai.request(server).get(resource + '/files?search=0')
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.an('object');
check(res.body, 0);
done();
});
});

it('returns file info by filename match', (done) => {
chai.request(server).get(resource + '/files/nwd')
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.an('object');
check(res.body, null, 'nwd');
done();
});
});

it('returns file info by query-parameter filename match', (done) => {
chai.request(server).get(resource + '/files?search="nwd"')
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.an('object');
check(res.body, null, 'nwd');
done();
});
});

it('returns multiple file-info entries array of origins', (done) => {
chai.request(server).get(resource + '/files?search=[0,1,2,3,4,5,6,7]')
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.an('array');
res.body.should.have.lengthOf(8);
res.body.forEach((v, i) => check(v, i));
done();
});
});

it('returns multiple file-info entries from array of matches', (done) => {
var order = ['nwd', 'nwu', 'ned', 'neu', 'swd', 'swu', 'sed', 'seu'];
chai.request(server).get(
resource + '/files?search=' + JSON.stringify(order))
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.an('array');
res.body.should.have.lengthOf(8);
res.body.forEach((v, i) => check(v, null, order[i]));
done();
});
});

it('returns multiple file-info entries from mixed searches', (done) => {
var search = ['nwd', 0, 4, 'swu'];
chai.request(server).get(
resource + '/files?search=' + JSON.stringify(search))
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.an('array');
res.body.should.have.lengthOf(4);
res.body.forEach((v, i) => {
if (typeof(search[i]) == 'number') check(v, search[i]);
else check(v, null, search[i]);
});
done();
});
});

it('returns null for not-found origin IDs', (done) => {
chai.request(server).get(resource + '/files/8')
.end((err, res) => {
res.should.have.status(200);
expect(res.body).to.be.null;
done();
});
});

it('returns null for not-found paths', (done) => {
chai.request(server).get(resource + '/files/asdf')
.end((err, res) => {
res.should.have.status(200);
expect(res.body).to.be.null;
done();
});
});

it('inserts nulls for not-found search array entries', (done) => {
var search = ['nwd', 'asdf', 0, 4, 8, 'swu'];

chai.request(server).get(
resource + '/files?search=' + JSON.stringify(search))
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.an('array');
res.body.should.have.lengthOf(6);
res.body.forEach((v, i) => {
if (typeof(search[i]) == 'number') {
if (search[i] >= 0 && search[i] < 8) {
check(v, search[i]);
}
else expect(v).to.be.null;
}
else {
if (search[i] != 'asdf') check(v, null, search[i]);
else expect(v).to.be.null;
}
});
done();
});
});
});

0 comments on commit 8a0d3bf

Please sign in to comment.