From d071fe6d0c418959b4efb6440b4205e1303867bc Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Wed, 8 Jul 2015 00:12:32 +0200 Subject: [PATCH] Ports windshaft server unit tests --- Makefile | 1 + test/support/test_helper.js | 1 + .../cartodb/ported/windshaft_server.test.js | 59 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 test/unit/cartodb/ported/windshaft_server.test.js diff --git a/Makefile b/Makefile index f8c485c7..b572bb2b 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,7 @@ test: config/environments/test.js test-ported: config/environments/test.js @echo "***tests ported***" @$(SHELL) ./run_tests.sh ${RUNTESTFLAGS} \ + test/unit/cartodb/ported/*.js \ test/acceptance/ported/*.js test-unit: config/environments/test.js diff --git a/test/support/test_helper.js b/test/support/test_helper.js index 6bd63af3..f7924dad 100644 --- a/test/support/test_helper.js +++ b/test/support/test_helper.js @@ -12,6 +12,7 @@ var lzmaWorker = new LZMA(); // set environment specific variables global.environment = require(__dirname + '/../../config/environments/test'); +global.environment.name = 'test'; process.env.NODE_ENV = 'test'; diff --git a/test/unit/cartodb/ported/windshaft_server.test.js b/test/unit/cartodb/ported/windshaft_server.test.js new file mode 100644 index 00000000..0e70e27b --- /dev/null +++ b/test/unit/cartodb/ported/windshaft_server.test.js @@ -0,0 +1,59 @@ +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(); + }, /Cannot read property 'mapnik_version' of undefined/ + ); + }); + + it('options are set on main windshaft object', function(){ + var ws = cartodbServer(serverOptions); + assert.ok(_.isFunction(ws.req2params)); + assert.equal(ws.base_url, '/tiles/:table'); + }); + + it('different formats for postgis plugin error returns 400 as status code', function() { + var ws = cartodbServer(serverOptions); + var expectedStatusCode = 400; + assert.equal( + ws.findStatusCode("Postgis Plugin: ERROR: column \"missing\" does not exist\n"), + expectedStatusCode, + "Error status code for single line does not match" + ); + + assert.equal( + ws.findStatusCode("Postgis Plugin: PSQL error:\nERROR: column \"missing\" does not exist\n"), + expectedStatusCode, + "Error status code for multiline/PSQL does not match" + ); + }); + +});