From 1c3734fde769f9ad689e36145e22de637aafa898 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 19 Feb 2014 06:45:29 +0100 Subject: [PATCH] Make server_option a callable function, to reduce globals Updates acceptance test for #152 to not mess wit internals --- app.js | 2 +- lib/cartodb/server_options.js | 2 +- test/acceptance/multilayer.js | 11 ++++++----- test/acceptance/server.js | 2 +- test/acceptance/templates.js | 2 +- test/unit/cartodb/req2params.test.js | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app.js b/app.js index 66692a85..444ffc40 100755 --- a/app.js +++ b/app.js @@ -36,7 +36,7 @@ log4js.configure({ // Include cartodb_windshaft only _after_ the "global" variable is set // See https://github.com/Vizzuality/Windshaft-cartodb/issues/28 var CartodbWindshaft = require('./lib/cartodb/cartodb_windshaft'); -var serverOptions = require('./lib/cartodb/server_options'); +var serverOptions = require('./lib/cartodb/server_options')(); ws = CartodbWindshaft(serverOptions); diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index 473432ae..dc19b84d 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -793,4 +793,4 @@ module.exports = function(){ }; return me; -}(); +}; diff --git a/test/acceptance/multilayer.js b/test/acceptance/multilayer.js index 15949ad8..81a6065a 100644 --- a/test/acceptance/multilayer.js +++ b/test/acceptance/multilayer.js @@ -15,7 +15,8 @@ require(__dirname + '/../support/test_helper'); var windshaft_fixtures = __dirname + '/../../node_modules/windshaft/test/fixtures'; var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/cartodb_windshaft'); -var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); +var ServerOptions = require(__dirname + '/../../lib/cartodb/server_options'); +serverOptions = ServerOptions(); var server = new CartodbWindshaft(serverOptions); server.setMaxListeners(0); @@ -726,7 +727,7 @@ suite('multilayer', function() { // Check X-Cache-Channel var cc = res.headers['x-cache-channel']; - assert.ok(cc); + assert.ok(cc, "Missing X-Cache-Channel"); var dbname = 'test_cartodb_user_1_db' assert.equal(cc.substring(0, dbname.length), dbname); return null; @@ -734,8 +735,8 @@ suite('multilayer', function() { function do_restart_server(err, res) { if ( err ) throw err; // hack simulating restart... - assert.equal(typeof(serverOptions.channelCache), 'object'); - serverOptions.channelCache = []; + serverOptions = ServerOptions(); + server = new CartodbWindshaft(serverOptions); return null; }, function do_get1(err) @@ -756,7 +757,7 @@ suite('multilayer', function() { // Check X-Cache-Channel var cc = res.headers['x-cache-channel']; - assert.ok(cc); + assert.ok(cc, "Missing X-Cache-Channel on restart"); var dbname = 'test_cartodb_user_1_db' assert.equal(cc.substring(0, dbname.length), dbname); return null; diff --git a/test/acceptance/server.js b/test/acceptance/server.js index ab10375c..0140f9b1 100644 --- a/test/acceptance/server.js +++ b/test/acceptance/server.js @@ -12,7 +12,7 @@ var SQLAPIEmu = require(__dirname + '/../support/SQLAPIEmu.js'); var helper = require(__dirname + '/../support/test_helper'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/cartodb_windshaft'); -var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); +var serverOptions = require(__dirname + '/../../lib/cartodb/server_options')(); var server = new CartodbWindshaft(serverOptions); server.setMaxListeners(0); diff --git a/test/acceptance/templates.js b/test/acceptance/templates.js index 83591d1d..b411836f 100644 --- a/test/acceptance/templates.js +++ b/test/acceptance/templates.js @@ -15,7 +15,7 @@ require(__dirname + '/../support/test_helper'); var windshaft_fixtures = __dirname + '/../../node_modules/windshaft/test/fixtures'; var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/cartodb_windshaft'); -var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); +var serverOptions = require(__dirname + '/../../lib/cartodb/server_options')(); var server = new CartodbWindshaft(serverOptions); server.setMaxListeners(0); diff --git a/test/unit/cartodb/req2params.test.js b/test/unit/cartodb/req2params.test.js index bd2cdb6a..163b72c0 100644 --- a/test/unit/cartodb/req2params.test.js +++ b/test/unit/cartodb/req2params.test.js @@ -7,7 +7,7 @@ var assert = require('assert') suite('req2params', function() { // configure redis pool instance to use in tests - var opts = require('../../../lib/cartodb/server_options'); + var opts = require('../../../lib/cartodb/server_options')(); test('can be found in server_options', function(){ assert.ok(_.isFunction(opts.req2params));