Skip to content

Commit

Permalink
fix(client-ops): return transform map to map rather than function
Browse files Browse the repository at this point in the history
During the refactor of MongoClient operations a mapping variable
was mistaken to be a function expression, and we silently broke
using the new url parser. This corrects that, renames the mapping
variable to make it very clearly that, and adds a test to prove
that the new url parser is working again.

NODE-1542
  • Loading branch information
mbroadst committed Jul 5, 2018
1 parent a983817 commit b8b4bfa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
14 changes: 6 additions & 8 deletions lib/operations/mongo_client_ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,15 @@ function replayEvents(mongoClient, events) {
}
}

const LEGACY_OPTIONS_MAP = validOptionNames.reduce((obj, name) => {
obj[name.toLowerCase()] = name;
return obj;
}, {});

function transformUrlOptions(_object) {
let object = Object.assign({ servers: _object.hosts }, _object.options);
for (let name in object) {
const camelCaseName = validOptionsLowerCaseToCamelCase[name];
const camelCaseName = LEGACY_OPTIONS_MAP[name];
if (camelCaseName) {
object[camelCaseName] = object[name];
}
Expand Down Expand Up @@ -595,11 +600,4 @@ function validOptions(options) {
}
}

function validOptionsLowerCaseToCamelCase() {
validOptionNames.reduce((obj, name) => {
obj[name.toLowerCase()] = name;
return obj;
}, {});
}

module.exports = { connectOp, logout, validOptions };
29 changes: 21 additions & 8 deletions test/functional/uri_tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';
var expect = require('chai').expect;

const expect = require('chai').expect;
const MongoClient = require('../..').MongoClient;

describe('URI', function() {
/**
Expand All @@ -15,7 +17,6 @@ describe('URI', function() {
// The actual test we wish to run
test: function(done) {
var self = this;
var MongoClient = self.configuration.require.MongoClient;

// Connect using the connection string
MongoClient.connect(
Expand Down Expand Up @@ -57,7 +58,6 @@ describe('URI', function() {
// The actual test we wish to run
test: function(done) {
var self = this;
var MongoClient = self.configuration.require.MongoClient;

// Connect using the connection string
MongoClient.connect('mongodb://localhost:27017/integration_tests?w=0', function(err, client) {
Expand Down Expand Up @@ -89,8 +89,6 @@ describe('URI', function() {

// The actual test we wish to run
test: function(done) {
var MongoClient = this.configuration.require.MongoClient;

if (process.platform !== 'win32') {
MongoClient.connect('mongodb://%2Ftmp%2Fmongodb-27017.sock?safe=false', function(
err,
Expand All @@ -114,8 +112,6 @@ describe('URI', function() {
// The actual test we wish to run
test: function(done) {
var self = this;
var MongoClient = self.configuration.require.MongoClient;

MongoClient.connect('mongodb://127.0.0.1:27017/?fsync=true', function(err, client) {
var db = client.db(self.configuration.db);
expect(db.writeConcern.fsync).to.be.true;
Expand All @@ -133,7 +129,6 @@ describe('URI', function() {
// The actual test we wish to run
test: function(done) {
var self = this;
var MongoClient = self.configuration.require.MongoClient;

MongoClient.connect(
'mongodb://localhost:27017/integration_tests',
Expand Down Expand Up @@ -164,4 +159,22 @@ describe('URI', function() {
);
}
});

it('should correctly translate uri options using new parser', {
metadata: { requires: { topology: 'replicaset' } },
test: function(done) {
const config = this.configuration;
const uri = `mongodb://${config.host}:${config.port}/${config.db}?replicaSet=${
config.replicasetName
}`;

MongoClient.connect(uri, { useNewUrlParser: true }, (err, client) => {
if (err) console.dir(err);
expect(err).to.not.exist;
expect(client).to.exist;
expect(client.s.options.replicaSet).to.exist.and.equal(config.replicasetName);
done();
});
}
});
});

0 comments on commit b8b4bfa

Please sign in to comment.