From ffe19827fd85fd0e9e6708ec0c4f0696ffa0e129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Tue, 2 Jun 2020 11:57:11 +0200 Subject: [PATCH] Rename factory and don't use the keyword 'new' to create server while testing --- test/acceptance/analysis/named-maps-test.js | 4 ++-- .../auth/authorization-basic-use-cases-test.js | 4 ++-- test/acceptance/cache/cache-headers-test.js | 4 ++-- .../cache/surrogate-keys-invalidation-test.js | 4 ++-- test/acceptance/health-check-test.js | 10 +++++----- test/acceptance/multilayer-server-test.js | 4 ++-- test/acceptance/multilayer-test.js | 10 +++++----- test/acceptance/named-layers-test.js | 4 ++-- test/acceptance/named-layers-visibility-test.js | 4 ++-- test/acceptance/named-maps-authentication-test.js | 4 ++-- test/acceptance/named-maps-cache-test.js | 4 ++-- test/acceptance/named-maps-static-view-test.js | 6 +++--- test/acceptance/named-maps-stats-test.js | 4 ++-- test/acceptance/overviews-metadata-named-maps-test.js | 4 ++-- test/acceptance/overviews-metadata-test.js | 6 +++--- test/acceptance/regressions-test.js | 4 ++-- test/acceptance/server-test.js | 6 +++--- test/acceptance/templates-test.js | 4 ++-- test/acceptance/turbo-carto/named-maps-test.js | 4 ++-- test/acceptance/widgets/named-maps-test.js | 4 ++-- test/support/test-client.js | 8 ++++---- 21 files changed, 53 insertions(+), 53 deletions(-) diff --git a/test/acceptance/analysis/named-maps-test.js b/test/acceptance/analysis/named-maps-test.js index d04beadd..a0181ffe 100644 --- a/test/acceptance/analysis/named-maps-test.js +++ b/test/acceptance/analysis/named-maps-test.js @@ -4,7 +4,7 @@ var assert = require('../../support/assert'); var helper = require('../../support/test-helper'); -var CartodbWindshaft = require('../../../lib/server'); +const createServer = require('../../../lib/server'); var serverOptions = require('../../../lib/server-options'); var TestClient = require('../../support/test-client'); @@ -14,7 +14,7 @@ describe('named-maps analysis', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); }); var IMAGE_TOLERANCE_PER_MIL = 20; diff --git a/test/acceptance/auth/authorization-basic-use-cases-test.js b/test/acceptance/auth/authorization-basic-use-cases-test.js index 9e48077b..a58ad9ad 100644 --- a/test/acceptance/auth/authorization-basic-use-cases-test.js +++ b/test/acceptance/auth/authorization-basic-use-cases-test.js @@ -2,7 +2,7 @@ const assert = require('../../support/assert'); const testHelper = require('../../support/test-helper'); -const CartodbWindshaft = require('../../../lib/server'); +const createServer = require('../../../lib/server'); const serverOptions = require('../../../lib/server-options'); var LayergroupToken = require('../../../lib/models/layergroup-token'); @@ -47,7 +47,7 @@ describe('Basic authorization use cases', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); }); beforeEach(function () { diff --git a/test/acceptance/cache/cache-headers-test.js b/test/acceptance/cache/cache-headers-test.js index d96bada7..6a00a7eb 100644 --- a/test/acceptance/cache/cache-headers-test.js +++ b/test/acceptance/cache/cache-headers-test.js @@ -5,7 +5,7 @@ var testHelper = require('../../support/test-helper'); var assert = require('../../support/assert'); var qs = require('querystring'); -var CartodbWindshaft = require('../../../lib/server'); +const createServer = require('../../../lib/server'); var serverOptions = require('../../../lib/server-options'); var LayergroupToken = require('../../../lib/models/layergroup-token'); @@ -14,7 +14,7 @@ describe('get requests with cache headers', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); server.setMaxListeners(0); }); diff --git a/test/acceptance/cache/surrogate-keys-invalidation-test.js b/test/acceptance/cache/surrogate-keys-invalidation-test.js index 4e33947b..675dab1a 100644 --- a/test/acceptance/cache/surrogate-keys-invalidation-test.js +++ b/test/acceptance/cache/surrogate-keys-invalidation-test.js @@ -7,7 +7,7 @@ var step = require('step'); var FastlyPurge = require('fastly-purge'); var _ = require('underscore'); var NamedMapsCacheEntry = require('../../../lib/cache/model/named-maps-entry'); -var CartodbWindshaft = require('../../../lib/server'); +const createServer = require('../../../lib/server'); var nock = require('nock'); describe('templates surrogate keys', function () { @@ -33,7 +33,7 @@ describe('templates surrogate keys', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); nock.disableNetConnect(); nock.enableNetConnect(/(127.0.0.1|cartocdn.com)/); }); diff --git a/test/acceptance/health-check-test.js b/test/acceptance/health-check-test.js index 53ac76f7..c08c626e 100644 --- a/test/acceptance/health-check-test.js +++ b/test/acceptance/health-check-test.js @@ -5,7 +5,7 @@ require('../support/test-helper'); var fs = require('fs'); var assert = require('../support/assert'); -var CartodbWindshaft = require('../../lib/server'); +const createServer = require('../../lib/server'); var serverOptions = require('../../lib/server-options'); describe('health checks', function () { @@ -41,7 +41,7 @@ describe('health checks', function () { }; it('returns 200 and ok=true with enabled configuration', function (done) { - var server = new CartodbWindshaft(serverOptions); + var server = createServer(serverOptions); assert.response(server, healthCheckRequest, RESPONSE_OK, function (res, err) { assert.ok(!err); @@ -62,7 +62,7 @@ describe('health checks', function () { fs.readFile = function (filename, callback) { callback(null, errorMessage); }; - var server = new CartodbWindshaft(serverOptions); + var server = createServer(serverOptions); assert.response(server, healthCheckRequest, RESPONSE_FAIL, function (res, err) { fs.readFile = readFileFn; @@ -82,7 +82,7 @@ describe('health checks', function () { fs.readFile = function (filename, callback) { callback(null, ''); }; - var server = new CartodbWindshaft(serverOptions); + var server = createServer(serverOptions); assert.response(server, healthCheckRequest, RESPONSE_FAIL, function (res, err) { fs.readFile = readFileFn; @@ -100,7 +100,7 @@ describe('health checks', function () { it('not err if disabled file does not exist', function (done) { global.environment.disabled_file = '/tmp/ftreftrgtrccre'; - var server = new CartodbWindshaft(serverOptions); + var server = createServer(serverOptions); assert.response(server, healthCheckRequest, RESPONSE_OK, function (res, err) { assert.ok(!err); diff --git a/test/acceptance/multilayer-server-test.js b/test/acceptance/multilayer-server-test.js index 04a281e1..5e621aa7 100644 --- a/test/acceptance/multilayer-server-test.js +++ b/test/acceptance/multilayer-server-test.js @@ -10,14 +10,14 @@ var LayergroupToken = require('../../lib/models/layergroup-token'); var PgQueryRunner = require('../../lib/backends/pg-query-runner'); var QueryTables = require('cartodb-query-tables').queryTables; -var CartodbWindshaft = require('../../lib/server'); +const createServer = require('../../lib/server'); var serverOptions = require('../../lib/server-options'); describe('tests from old api translated to multilayer', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); server.setMaxListeners(0); }); diff --git a/test/acceptance/multilayer-test.js b/test/acceptance/multilayer-test.js index 91868751..d291d86e 100644 --- a/test/acceptance/multilayer-test.js +++ b/test/acceptance/multilayer-test.js @@ -19,7 +19,7 @@ var windshaftFixtures = path.join(__dirname, '/../../node_modules/windshaft/test var IMAGE_EQUALS_TOLERANCE_PER_MIL = 20; var IMAGE_EQUALS_HIGHER_TOLERANCE_PER_MIL = 25; -var CartodbWindshaft = require('../../lib/server'); +const createServer = require('../../lib/server'); var serverOptions = require('../../lib/server-options'); var QueryTables = require('cartodb-query-tables').queryTables; @@ -30,7 +30,7 @@ var QueryTables = require('cartodb-query-tables').queryTables; var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); server.setMaxListeners(0); }); @@ -851,7 +851,7 @@ var QueryTables = require('cartodb-query-tables').queryTables; function doRestartServer (err/*, res */) { assert.ifError(err); // hack simulating restart... - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); return null; }, function doGet1 (err) { @@ -1274,7 +1274,7 @@ var QueryTables = require('cartodb-query-tables').queryTables; it('cache control for layergroup default value', function (done) { global.environment.varnish.layergroupTtl = null; - var server = new CartodbWindshaft(serverOptions); + var server = createServer(serverOptions); assert.response(server, layergroupTtlRequest, layergroupTtlResponseExpectation, function (res) { @@ -1291,7 +1291,7 @@ var QueryTables = require('cartodb-query-tables').queryTables; var layergroupTtl = 300; global.environment.varnish.layergroupTtl = layergroupTtl; - var server = new CartodbWindshaft(serverOptions); + var server = createServer(serverOptions); assert.response(server, layergroupTtlRequest, layergroupTtlResponseExpectation, function (res) { diff --git a/test/acceptance/named-layers-test.js b/test/acceptance/named-layers-test.js index 1ea33e31..edfc8067 100644 --- a/test/acceptance/named-layers-test.js +++ b/test/acceptance/named-layers-test.js @@ -3,7 +3,7 @@ var testHelper = require('../support/test-helper'); var assert = require('../support/assert'); -var CartodbWindshaft = require('../../lib/server'); +const createServer = require('../../lib/server'); var serverOptions = require('../../lib/server-options'); var LayergroupToken = require('../../lib/models/layergroup-token'); @@ -17,7 +17,7 @@ describe('named_layers', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); }); // configure redis pool instance to use in tests diff --git a/test/acceptance/named-layers-visibility-test.js b/test/acceptance/named-layers-visibility-test.js index a9b0624c..51ad979e 100644 --- a/test/acceptance/named-layers-visibility-test.js +++ b/test/acceptance/named-layers-visibility-test.js @@ -4,7 +4,7 @@ var step = require('step'); var testHelper = require('../support/test-helper'); var assert = require('../support/assert'); -var CartodbWindshaft = require('../../lib/server'); +const createServer = require('../../lib/server'); var serverOptions = require('../../lib/server-options'); var RedisPool = require('redis-mpool'); @@ -17,7 +17,7 @@ describe('layers visibility for previews', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); }); // configure redis pool instance to use in tests diff --git a/test/acceptance/named-maps-authentication-test.js b/test/acceptance/named-maps-authentication-test.js index cd1e20eb..f559bbbd 100644 --- a/test/acceptance/named-maps-authentication-test.js +++ b/test/acceptance/named-maps-authentication-test.js @@ -6,7 +6,7 @@ var querystring = require('querystring'); var assert = require('../support/assert'); const mapnik = require('@carto/mapnik'); -var CartodbWindshaft = require('../../lib/server'); +const createServer = require('../../lib/server'); var serverOptions = require('../../lib/server-options'); var TemplateMaps = require('../../lib/backends/template-maps'); var NamedMapsCacheEntry = require('../../lib/cache/model/named-maps-entry'); @@ -15,7 +15,7 @@ describe('named maps authentication', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); }); // configure redis pool instance to use in tests diff --git a/test/acceptance/named-maps-cache-test.js b/test/acceptance/named-maps-cache-test.js index 4c036858..712d859e 100644 --- a/test/acceptance/named-maps-cache-test.js +++ b/test/acceptance/named-maps-cache-test.js @@ -5,14 +5,14 @@ require('../support/test-helper'); const helper = require('../support/test-helper'); var assert = require('../support/assert'); const mapnik = require('@carto/mapnik'); -var CartodbWindshaft = require('../../lib/server'); +const createServer = require('../../lib/server'); var serverOptions = require('../../lib/server-options'); describe('named maps provider cache', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); }); var username = 'localhost'; diff --git a/test/acceptance/named-maps-static-view-test.js b/test/acceptance/named-maps-static-view-test.js index 08d5ac82..8ffad2e9 100644 --- a/test/acceptance/named-maps-static-view-test.js +++ b/test/acceptance/named-maps-static-view-test.js @@ -6,7 +6,7 @@ var RedisPool = require('redis-mpool'); var assert = require('../support/assert'); const mapnik = require('@carto/mapnik'); -var CartodbWindshaft = require('../../lib/server'); +const createServer = require('../../lib/server'); var serverOptions = require('../../lib/server-options'); var TemplateMaps = require('../../lib/backends/template-maps'); @@ -86,7 +86,7 @@ describe('named maps static view', function () { }; // this could be removed once named maps are invalidated, otherwise you hits the cache - var server = new CartodbWindshaft(serverOptions); + var server = createServer(serverOptions); assert.response(server, requestOptions, expectedResponse, function (res, err) { testHelper.deleteRedisKeys({ 'user:localhost:mapviews:global': 5 }, function () { @@ -323,7 +323,7 @@ describe('named maps static view', function () { }; // this could be removed once named maps are invalidated, otherwise you hits the cache - var server = new CartodbWindshaft(serverOptions); + var server = createServer(serverOptions); assert.response(server, requestOptions, expectedResponse, function (res, err) { assert.ifError(err); diff --git a/test/acceptance/named-maps-stats-test.js b/test/acceptance/named-maps-stats-test.js index c7a1ded7..bd6b474c 100644 --- a/test/acceptance/named-maps-stats-test.js +++ b/test/acceptance/named-maps-stats-test.js @@ -6,7 +6,7 @@ var querystring = require('querystring'); var assert = require('../support/assert'); const mapnik = require('@carto/mapnik'); -var CartodbWindshaft = require('../../lib/server'); +const createServer = require('../../lib/server'); var serverOptions = require('../../lib/server-options'); var TemplateMaps = require('../../lib/backends/template-maps'); var NamedMapsCacheEntry = require('../../lib/cache/model/named-maps-entry'); @@ -15,7 +15,7 @@ describe('named maps preview stats', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); }); var redisPool = new RedisPool(global.environment.redis); diff --git a/test/acceptance/overviews-metadata-named-maps-test.js b/test/acceptance/overviews-metadata-named-maps-test.js index 60712ec6..10dc2458 100644 --- a/test/acceptance/overviews-metadata-named-maps-test.js +++ b/test/acceptance/overviews-metadata-named-maps-test.js @@ -3,7 +3,7 @@ var testHelper = require('../support/test-helper'); var assert = require('../support/assert'); -var CartodbWindshaft = require('../../lib/server'); +const createServer = require('../../lib/server'); var serverOptions = require('../../lib/server-options'); var LayergroupToken = require('../../lib/models/layergroup-token'); @@ -18,7 +18,7 @@ describe('overviews metadata for named maps', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); }); // configure redis pool instance to use in tests diff --git a/test/acceptance/overviews-metadata-test.js b/test/acceptance/overviews-metadata-test.js index d06b8cdf..828c34e3 100644 --- a/test/acceptance/overviews-metadata-test.js +++ b/test/acceptance/overviews-metadata-test.js @@ -3,7 +3,7 @@ var testHelper = require('../support/test-helper'); var assert = require('../support/assert'); -var CartodbWindshaft = require('../../lib/server'); +const createServer = require('../../lib/server'); var serverOptions = require('../../lib/server-options'); var LayergroupToken = require('../../lib/models/layergroup-token'); @@ -18,7 +18,7 @@ describe('overviews metadata', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); }); // configure redis pool instance to use in tests @@ -193,7 +193,7 @@ describe('overviews metadata with filters', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); }); // configure redis pool instance to use in tests diff --git a/test/acceptance/regressions-test.js b/test/acceptance/regressions-test.js index b777d729..a4c8672b 100644 --- a/test/acceptance/regressions-test.js +++ b/test/acceptance/regressions-test.js @@ -5,7 +5,7 @@ var assert = require('../support/assert'); const helper = require('../support/test-helper'); var TestClient = require('../support/test-client'); const LayergroupToken = require('../../lib/models/layergroup-token'); -const CartodbWindshaft = require('../../lib/server'); +const createServer = require('../../lib/server'); const serverOptions = require('../../lib/server-options'); describe('regressions', function () { @@ -44,7 +44,7 @@ describe('regressions', function () { // See: https://github.com/CartoDB/Windshaft-cartodb/pull/956 it('"/user/localhost/api/v1/map" should create an anonymous map', function (done) { - const server = new CartodbWindshaft(serverOptions); + const server = createServer(serverOptions); const layergroup = { version: '1.7.0', layers: [ diff --git a/test/acceptance/server-test.js b/test/acceptance/server-test.js index 7fb16e4d..245529aa 100644 --- a/test/acceptance/server-test.js +++ b/test/acceptance/server-test.js @@ -6,14 +6,14 @@ var assert = require('../support/assert'); var querystring = require('querystring'); var step = require('step'); -var CartodbWindshaft = require('../../lib/server'); +const createServer = require('../../lib/server'); var serverOptions = require('../../lib/server-options'); describe('server', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); server.setMaxListeners(0); }); @@ -45,7 +45,7 @@ describe('server old_api', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); server.setMaxListeners(0); }); diff --git a/test/acceptance/templates-test.js b/test/acceptance/templates-test.js index c7926fe3..fb4dca0b 100644 --- a/test/acceptance/templates-test.js +++ b/test/acceptance/templates-test.js @@ -21,7 +21,7 @@ var http = require('http'); var helper = require('../support/test-helper'); -var CartodbWindshaft = require('../../lib/server'); +const createServer = require('../../lib/server'); var serverOptions = require('../../lib/server-options'); var LayergroupToken = require('../../lib/models/layergroup-token'); @@ -30,7 +30,7 @@ describe('template_api', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); server.setMaxListeners(0); // FIXME: we need a better way to reset cache while running tests server.layergroupAffectedTablesCache.cache.reset(); diff --git a/test/acceptance/turbo-carto/named-maps-test.js b/test/acceptance/turbo-carto/named-maps-test.js index 5076b66f..67d40a54 100644 --- a/test/acceptance/turbo-carto/named-maps-test.js +++ b/test/acceptance/turbo-carto/named-maps-test.js @@ -4,7 +4,7 @@ var assert = require('../../support/assert'); var step = require('step'); var LayergroupToken = require('../../../lib/models/layergroup-token'); var testHelper = require('../../support/test-helper'); -var CartodbWindshaft = require('../../../lib/server'); +const createServer = require('../../../lib/server'); var serverOptions = require('../../../lib/server-options'); const mapnik = require('@carto/mapnik'); var IMAGE_TOLERANCE_PER_MIL = 10; @@ -13,7 +13,7 @@ describe('turbo-carto for named maps', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); }); var keysToDelete; diff --git a/test/acceptance/widgets/named-maps-test.js b/test/acceptance/widgets/named-maps-test.js index b93f26eb..e91d71a4 100644 --- a/test/acceptance/widgets/named-maps-test.js +++ b/test/acceptance/widgets/named-maps-test.js @@ -8,7 +8,7 @@ var queue = require('queue-async'); var helper = require('../../support/test-helper'); -var CartodbWindshaft = require('../../../lib/server'); +const createServer = require('../../../lib/server'); var serverOptions = require('../../../lib/server-options'); var LayergroupToken = require('../../../lib/models/layergroup-token'); @@ -17,7 +17,7 @@ describe('named-maps widgets', function () { var server; before(function () { - server = new CartodbWindshaft(serverOptions); + server = createServer(serverOptions); }); var username = 'localhost'; diff --git a/test/support/test-client.js b/test/support/test-client.js index 45fb198e..ffe71ef3 100644 --- a/test/support/test-client.js +++ b/test/support/test-client.js @@ -12,7 +12,7 @@ var LayergroupToken = require('../../lib/models/layergroup-token'); var assert = require('./assert'); var helper = require('./test-helper'); -var CartodbWindshaft = require('../../lib/server'); +const createServer = require('../../lib/server'); var serverOptions = require('../../lib/server-options'); serverOptions.analysis.batch.inlineExecution = true; @@ -30,7 +30,7 @@ function TestClient (config, apiKey, extraHeaders = {}, overrideServerOptions = this.extraHeaders = extraHeaders; this.keysToDelete = {}; this.serverOptions = Object.assign({}, serverOptions, overrideServerOptions); - this.server = new CartodbWindshaft(this.serverOptions); + this.server = createServer(this.serverOptions); } module.exports = TestClient; @@ -1348,7 +1348,7 @@ TestClient.prototype.drain = function (callback) { module.exports.getStaticMap = function getStaticMap (templateName, params, callback) { var self = this; - self.server = new CartodbWindshaft(serverOptions); + self.server = createServer(serverOptions); if (!callback) { callback = params; @@ -1378,7 +1378,7 @@ module.exports.getStaticMap = function getStaticMap (templateName, params, callb }; // this could be removed once named maps are invalidated, otherwise you hits the cache - var server = new CartodbWindshaft(serverOptions); + var server = createServer(serverOptions); assert.response(server, requestOptions, expectedResponse, function (res, err) { helper.deleteRedisKeys({ 'user:localhost:mapviews:global': 5 }, function () {