From 1dac18f0ba07ab29ecced4cd2f090e180b008d74 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Tue, 21 Aug 2018 18:48:03 -0400 Subject: [PATCH] feat(test): use connection strings for all calls to `newClient` We have been inconsistently testing our code for some time using a deprecated form of creating a `MongoClient` by passing in a topology to the constructor. Now we take the passed in variables and construct a connection string to connect to the server, just like users of the module would. --- test/config.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/test/config.js b/test/config.js index 33a5add7ec..00bd5b0eea 100644 --- a/test/config.js +++ b/test/config.js @@ -1,7 +1,8 @@ 'use strict'; const ConfigurationBase = require('mongodb-test-runner').ConfigurationBase; const f = require('util').format; - +const url = require('url'); +const qs = require('querystring'); class NativeConfiguration extends ConfigurationBase { constructor(options) { super(options); @@ -59,17 +60,23 @@ class NativeConfiguration extends ConfigurationBase { if (keys.indexOf('sslOnNormalPorts') !== -1) serverOptions.ssl = true; // Fall back - const dbHost = (serverOptions && serverOptions.host) || 'localhost'; + let dbHost = (serverOptions && serverOptions.host) || 'localhost'; const dbPort = (serverOptions && serverOptions.port) || this.options.port || 27017; - // Default topology - const DbTopology = this.options.topology ? this.options.topology : this.mongo.Server; + if (dbHost.indexOf('.sock') !== -1) { + dbHost = qs.escape(dbHost); + } + + const connectionString = url.format({ + protocol: 'mongodb', + slashes: true, + hostname: dbHost, + port: dbPort, + query: dbOptions, + pathname: '/' + }); - // Return a new MongoClient instance - return new this.mongo.MongoClient( - new DbTopology(dbHost, dbPort, serverOptions, this.mongo), - dbOptions - ); + return new this.mongo.MongoClient(connectionString, serverOptions); } url(username, password) {