Permalink
Browse files

Add some unit tests.

  • Loading branch information...
connormanning committed Feb 9, 2017
1 parent 067a90a commit 8a0d3bf838ae07b0376282ae799918e12f91d1a1
Showing with 738 additions and 45 deletions.
  1. +1 −1 .gitignore
  2. BIN data/autzen.las
  3. +12 −1 package.json
  4. +19 −0 scripts/generate-test-data.sh
  5. +0 −43 test.js
  6. +5 −0 test/common.js
  7. +189 −0 test/files.js
  8. +169 −0 test/filter.js
  9. +77 −0 test/info.js
  10. +170 −0 test/read.js
  11. +96 −0 test/util.js
View
@@ -6,4 +6,4 @@ build/*
*.gypi
data/*
-!data/autzen.las
+
View
Binary file not shown.
View
@@ -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",
@@ -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"
}
}
@@ -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
+
View
43 test.js
@@ -1,43 +0,0 @@
-var requests = JSON.parse(require('fs').readFileSync('requests.json'));
-var _ = require('lodash');
-
-var Controller = require('./src/controller').Controller;
-var config = JSON.parse(require('fs').readFileSync('csmannin/uncommented.json'));
-
-var controller = new Controller(config);
-var bytes = 0;
-var dones = 0;
-var a = 0;
-
-console.log('Requests:', requests.length);
-
-var go = () => {
- requests.forEach((v, i) => {
- controller.read(
- v.resource,
- _.merge({ }, v.query),
- (err) => {
- if (err) console.log('INIT ERR:', err);
- },
- (err, data, done) => {
- if (err) console.log('DATA ERR:', err);
- else bytes += data.length;
-
- if (done) {
- ++dones;
- if (dones == requests.length) {
- dones = 0;
- console.log('all done');
- global.gc();
- ++a;
- }
- }
-
- return true;
- });
- });
-};
-
-go();
-setTimeout(go, 12000);
-
View
@@ -0,0 +1,5 @@
+module.exports = {
+ server: 'http://localhost:8080',
+ resource: '/resource/ellipsoid'
+};
+
View
@@ -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();
+ });
+ });
+});
+
Oops, something went wrong.

0 comments on commit 8a0d3bf

Please sign in to comment.