2015-07-08 06:12:32 +08:00
|
|
|
require('../../../support/test_helper.js');
|
|
|
|
|
|
|
|
var _ = require('underscore');
|
|
|
|
var assert = require('assert');
|
|
|
|
var cartodbServer = require('../../../../lib/cartodb/server');
|
|
|
|
var serverOptions = require('../../../../lib/cartodb/server_options');
|
|
|
|
|
|
|
|
|
|
|
|
describe('windshaft', function() {
|
|
|
|
|
|
|
|
it('should have valid global environment', function() {
|
|
|
|
assert.equal(global.environment.name, 'test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can instantiate a Windshaft object (configured express instance)', function(){
|
|
|
|
var ws = cartodbServer(serverOptions);
|
|
|
|
assert.ok(ws);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can spawn a new server on the global listen port', function(done){
|
|
|
|
var ws = cartodbServer(serverOptions);
|
|
|
|
ws.listen(global.environment.windshaft_port, function() {
|
|
|
|
assert.ok(ws);
|
|
|
|
ws.close(done); /* allow proper tear down */
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws exception if incorrect options passed in', function(){
|
|
|
|
assert.throws(
|
|
|
|
function(){
|
|
|
|
var ws = cartodbServer({unbuffered_logging:true});
|
|
|
|
ws.listen();
|
2015-07-11 01:10:55 +08:00
|
|
|
}, /Cannot read property 'mapnik' of undefined/
|
2015-07-08 06:12:32 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('options are set on main windshaft object', function(){
|
|
|
|
var ws = cartodbServer(serverOptions);
|
2015-09-17 00:09:39 +08:00
|
|
|
assert.ok(_.isObject(ws.bind));
|
|
|
|
assert.ok(_.isObject(ws.grainstore));
|
2015-07-08 06:12:32 +08:00
|
|
|
assert.equal(ws.base_url, '/tiles/:table');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('different formats for postgis plugin error returns 400 as status code', function() {
|
2015-09-16 08:49:18 +08:00
|
|
|
|
2015-07-08 06:12:32 +08:00
|
|
|
var expectedStatusCode = 400;
|
|
|
|
assert.equal(
|
2015-09-16 08:49:18 +08:00
|
|
|
cartodbServer.findStatusCode("Postgis Plugin: ERROR: column \"missing\" does not exist\n"),
|
2015-07-08 06:12:32 +08:00
|
|
|
expectedStatusCode,
|
|
|
|
"Error status code for single line does not match"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
2015-09-16 08:49:18 +08:00
|
|
|
cartodbServer.findStatusCode("Postgis Plugin: PSQL error:\nERROR: column \"missing\" does not exist\n"),
|
2015-07-08 06:12:32 +08:00
|
|
|
expectedStatusCode,
|
|
|
|
"Error status code for multiline/PSQL does not match"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|