diff --git a/README.md b/README.md index 51941cf3..a66aa0ed 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ # mongodb-data-service [![][travis_img]][travis_url] [![][npm_img]][npm_url] -> MongoDB Data Service - -The data service provides an API on top of [currently] the MongoDB Node Driver and -[in the future] mongodb-scout-client. +> MongoDB Data Service: an API on top of (currently) the [MongoDB Node Driver][driver] and (some day) [mongodb-scope-client][scope-client]. ## Installation @@ -16,65 +13,60 @@ npm install --save mongodb-data-service ### Instantiating the service. ```javascript - const Connection = require('mongodb-connection-model'); - const DataService = require('mongodb-data-service'); - - var model = new Connection({ hostname: '127.0.0.1', port: 27018, ns: 'data-service' }); - var service = new DataService(model); +const Connection = require('mongodb-connection-model'); +const DataService = require('mongodb-data-service'); + +var service = new DataService(new Connection({ + hostname: '127.0.0.1', + port: 27018, + ns: 'data-service' +})); ``` ### Connecting to the server. -Once the service is ready, it will also emit a `DataService.Events.Readble` event. +Once the service is ready, it will also emit a `readable` event. ```javascript - service.connect((error) => { - assert.equal(null, error); - }); - - function handleReadable() { - console.log('Connected!'); - } - - service.on(DataService.Events.Readable, handleReadable); +service.connect((err) => assert.equal(null, err)}) + .on('readable', () => console.log('Connected!')); ``` ### API ```javascript - - // Get information for a collection. - service.collection('database.collection', {}, (error, result) => { - assert.equal(null, error); - }); - - // Get a document count. - service.count('database.collection', { a: 1 }, {}, (error, count) => { - assert.equal(null, error); - }); - - // Get information for a database. - service.database('database', {}, (error, result) => { - assert.equal(null, error); - }); - - // Find documents in a collection. - service.find('database.collection', { a: 1 }, {}, (error, documents) => { - assert.equal(null, error); - }); - - // Get a result for a RESTful endpoint. - service.get('/collection/database.test', {}, (error, result) => { - assert.equal(null, error); - }); - - // Get instance details. - service.instance({}, (error, result) => { - assert.equal(null, error); - }); - - // Get a sample stream of documents from a collection. - service.sample('database.collection', {}); +// Get information for a collection. +service.collection('database.collection', {}, (error, result) => { + assert.equal(null, error); +}); + +// Get a document count. +service.count('database.collection', { a: 1 }, {}, (error, count) => { + assert.equal(null, error); +}); + +// Get information for a database. +service.database('database', {}, (error, result) => { + assert.equal(null, error); +}); + +// Find documents in a collection. +service.find('database.collection', { a: 1 }, {}, (error, documents) => { + assert.equal(null, error); +}); + +// Get a result for a RESTful endpoint. +service.get('/collection/database.test', {}, (error, result) => { + assert.equal(null, error); +}); + +// Get instance details. +service.instance({}, (error, result) => { + assert.equal(null, error); +}); + +// Get a sample stream of documents from a collection. +service.sample('database.collection', {}); ``` ## License @@ -85,3 +77,5 @@ Apache 2.0 [travis_url]: https://travis-ci.org/mongodb-js/data-service [npm_img]: https://img.shields.io/npm/v/mongodb-data-service.svg?style=flat-square [npm_url]: https://www.npmjs.org/package/mongodb-data-service +[scope-client]: https://github.com/mongodb-js/scope-client +[driver]: https://github.com/mongodb/node-mongodb-native diff --git a/lib/data-service.js b/lib/data-service.js index d16aab53..67517e5b 100644 --- a/lib/data-service.js +++ b/lib/data-service.js @@ -2,19 +2,9 @@ const debug = require('debug')('mongodb-data-service:data-service'); const NativeClient = require('./native-client'); -const SshTunnelConnector = require('./ssh-tunnel-connector'); const Router = require('./router'); const EventEmitter = require('events'); -/** - * Constants for generated events. - */ -const Events = { - Connecting: 'DataService:Connecting', - Readable: 'DataService:Readable', - Error: 'DataService:Error' -}; - /** * Instantiate a new DataService object. * @@ -31,21 +21,8 @@ class DataService extends EventEmitter { */ constructor(model) { super(); - this.connector = new SshTunnelConnector(model.ssh_tunnel_options); - this.client = new NativeClient(model); + this.client = new NativeClient(model).on('status', (evt) => this.emit('status', evt)); this.router = new Router(); - - this.connector.on(SshTunnelConnector.Events.Connecting, (message) => { - process.nextTick(() => { - this.emit(Events.Connecting, message); - }); - }); - - this.connector.on(SshTunnelConnector.Events.Error, (message) => { - process.nextTick(() => { - this.emit(Events.Error, message); - }); - }); } /** @@ -63,21 +40,16 @@ class DataService extends EventEmitter { /** * Connect to the server. * - * @param {function} callback - The callback function. + * @param {function} done - The callback function. */ - connect(callback) { - debug('Connecting to MongoDB.'); - this.connector.connect((tunnelError) => { - if (tunnelError) { - return callback(tunnelError, this); + connect(done) { + debug('Connecting...'); + this.client.connect((err) => { + if (err) { + return done(err); } - this.client.connect((error) => { - debug('Data Service is readable.'); - process.nextTick(() => { - this.emit(Events.Readable); - }); - return callback(error, this); - }); + done(null, this); + this.emit('readable'); }); } @@ -337,4 +309,3 @@ class DataService extends EventEmitter { } module.exports = DataService; -module.exports.Events = Events; diff --git a/lib/native-client.js b/lib/native-client.js index 06f2e7c9..39ff6d5c 100644 --- a/lib/native-client.js +++ b/lib/native-client.js @@ -2,17 +2,19 @@ const _ = require('lodash'); const async = require('async'); -const createConnection = require('mongodb-connection-model').connect; +const EventEmitter = require('events'); +const connect = require('mongodb-connection-model').connect; const getInstance = require('mongodb-instance-model').get; const getIndexes = require('mongodb-index-model').fetch; const createSampleStream = require('mongodb-collection-sample'); const parseNamespace = require('mongodb-ns'); const translate = require('mongodb-js-errors').translate; +const debug = require('debug')('mongodb-data-service:native-client'); /** * The native client class. */ -class NativeClient { +class NativeClient extends EventEmitter { /** * Instantiate a new NativeClient object. @@ -21,19 +23,28 @@ class NativeClient { * @param {Connection} model - The Connection model. */ constructor(model) { + super(); this.model = model; } /** * Connect to the server. * - * @param {function} callback - The callback function. + * @param {function} done - The callback function. + * @return {NativeClient} */ - connect(callback) { - createConnection(this.model, (error, database) => { + connect(done) { + debug('connecting...'); + this.client = connect(this.model, (err, database) => { + if (err) { + return done(this._translateMessage(err)); + } + debug('connected!'); this.database = database; - callback(this._translateMessage(error), this); + done(null, this); }); + this.client.on('status', (evt) => this.emit('status', evt)); + return this; } /** diff --git a/lib/ssh-tunnel-connector.js b/lib/ssh-tunnel-connector.js deleted file mode 100644 index 38d46e81..00000000 --- a/lib/ssh-tunnel-connector.js +++ /dev/null @@ -1,118 +0,0 @@ -'use strict'; - -const debug = require('debug')('mongodb-data-service:ssh-tunnel-connector'); -const tunnel = require('tunnel-ssh'); -const EventEmitter = require('events'); -const net = require('net'); - -const Events = { - Connecting: 'SshTunnelConnector:Connecting', - Testing: 'SshTunnelConnector:Testing', - Ready: 'SshTunnelConnector:Ready', - Error: 'SshTunnelConnector:Error' -}; - -/** - * Instantiate a new SshTunnelConnector object. - * - * @constructor - * @param {Object} options - The ssh tunnel options. - */ -class SshTunnelConnector extends EventEmitter { - - /** - * Instantiate a new SshTunnelConnector object. - * - * @constructor - * @param {Object} options - The ssh tunnel options. - */ - constructor(options) { - super(); - this.options = options; - } - - /** - * Connect to the SSH tunnel and execute the callback. - * - * @param {Function} done - The callback. - * - * @returns {Object} The executed callback. - */ - connect(done) { - if (!this.options.host) { - debug('No SSH tunnel host option found - using direct connection.'); - return done(); - } - - const connectMessage = this._connectMessage(); - debug(connectMessage); - this.emit(Events.Connecting, connectMessage); - - tunnel(this.options, (err) => { - if (err) { - this.emit(Events.Error, this._errorMessage()); - debug('error setting up tunnel', err); - return done(err); - } - debug('tunnel opened - testing'); - this.test(done); - }).on('error', (err) => { - this.emit(Events.Error, this._errorMessage()); - debug('tunnel write failed', err); - done(err); - }); - } - /** - * Test that a tunnel can actually be created by opening a socket - * to it and writing some data. - * - * @param {Function} done - The callback. - */ - test(done) { - this.emit(Events.Testing); - var client = new net.Socket(); - client.on('error', function(err) { - debug('test client got an error', err); - client.end(); - done(err); - }); - - debug('test client connecting to %s:%s', this.options.dstHost, this.options.dstPort); - client.connect(this.options.dstPort, this.options.dstHost, () => { - debug('writing test message'); - try { - client.write('mongodb-data-service:ssh-tunnel-connector: ping'); - } catch (err) { - debug('write to test client failed with error', err); - return done(err); - } - setTimeout(() => { - client.end(); - debug('test successful - emitting %s', Events.Ready); - this.emit(Events.Ready); - done(null, true); - }, 300); - }); - } - - /** - * Get the connecting message. - * - * @returns {String} The connecting message. - */ - _connectMessage() { - return `Attempting SSH connection to server at ${this.options.host}`; - } - - /** - * Get the error message. - * - * @returns {String} The error message. - */ - _errorMessage() { - return `Failed to connect to ${this.options.host} via SSH tunnel.`; - } -} - -module.exports = SshTunnelConnector; -module.exports.Events = Events; diff --git a/package.json b/package.json index 6a6c604b..83c55f77 100644 --- a/package.json +++ b/package.json @@ -29,13 +29,12 @@ "lodash": "^4.6.1", "mongodb": "^2.1.10", "mongodb-collection-sample": "^1.2.0", - "mongodb-connection-model": "^4.3.0", + "mongodb-connection-model": "^5.0.0", "mongodb-index-model": "^0.5.3", "mongodb-instance-model": "^3.1.0", "mongodb-js-errors": "^0.2.1", "mongodb-ns": "^1.0.3", - "mongodb-url": "^1.0.2", - "tunnel-ssh": "^2.1.1" + "mongodb-url": "^1.0.2" }, "devDependencies": { "chai": "^3.4.1", diff --git a/test/data-service.test.js b/test/data-service.test.js index 15516bcc..a2705069 100644 --- a/test/data-service.test.js +++ b/test/data-service.test.js @@ -10,7 +10,9 @@ var DataService = require('../lib/data-service'); describe('DataService', function() { var service = new DataService(helper.connection); - before(require('mongodb-runner/mocha/before')({ port: 27018 })); + before(require('mongodb-runner/mocha/before')({ + port: 27018 + })); after(require('mongodb-runner/mocha/after')()); before(function(done) { @@ -19,11 +21,17 @@ describe('DataService', function() { describe('#deleteOne', function() { it('deletes the document from the collection', function(done) { - service.insertOne('data-service.test', { a: 500 }, {}, function(err) { + service.insertOne('data-service.test', { + a: 500 + }, {}, function(err) { assert.equal(null, err); - service.deleteOne('data-service.test', { a: 500 }, {}, function(er) { + service.deleteOne('data-service.test', { + a: 500 + }, {}, function(er) { assert.equal(null, er); - service.find('data-service.test', { a: 500 }, {}, function(error, docs) { + service.find('data-service.test', { + a: 500 + }, {}, function(error, docs) { assert.equal(null, error); expect(docs.length).to.equal(0); done(); @@ -35,11 +43,17 @@ describe('DataService', function() { describe('#deleteMany', function() { it('deletes the document from the collection', function(done) { - service.insertOne('data-service.test', { a: 500 }, {}, function(err) { + service.insertOne('data-service.test', { + a: 500 + }, {}, function(err) { assert.equal(null, err); - service.deleteMany('data-service.test', { a: 500 }, {}, function(er) { + service.deleteMany('data-service.test', { + a: 500 + }, {}, function(er) { assert.equal(null, er); - service.find('data-service.test', { a: 500 }, {}, function(error, docs) { + service.find('data-service.test', { + a: 500 + }, {}, function(error, docs) { assert.equal(null, error); expect(docs.length).to.equal(0); done(); @@ -63,7 +77,9 @@ describe('DataService', function() { }); it('returns a cursor for the documents', function(done) { - service.find('data-service.test', {}, { skip: 1 }, function(error, docs) { + service.find('data-service.test', {}, { + skip: 1 + }, function(error, docs) { assert.equal(null, error); expect(docs.length).to.equal(1); done(); @@ -81,16 +97,24 @@ describe('DataService', function() { var id = new ObjectId(); it('returns the updated document', function(done) { - service.insertOne('data-service.test', { _id: id, a: 500 }, {}, function(err) { + service.insertOne('data-service.test', { + _id: id, + a: 500 + }, {}, function(err) { assert.equal(null, err); service.findOneAndReplace( 'data-service.test', - { _id: id }, - { b: 5 }, - { returnOriginal: false }, - function(error, result) { + { + _id: id + }, + { + b: 5 + }, + { + returnOriginal: false + }, function(error, result) { expect(error).to.equal(null); - expect(result._id).to.deep.equal(id); + expect(result._id.toString()).to.deep.equal(id.toString()); expect(result.b).to.equal(5); expect(result.hasOwnProperty('a')).to.equal(false); done(); @@ -114,7 +138,9 @@ describe('DataService', function() { describe('#count', function() { context('when a filter is provided', function() { it('returns a count for the matching documents', function(done) { - service.count('data-service.test', { a: 1 }, {}, function(error, count) { + service.count('data-service.test', { + a: 1 + }, {}, function(error, count) { assert.equal(null, error); expect(count).to.equal(0); done(); @@ -228,9 +254,13 @@ describe('DataService', function() { }); it('inserts the document into the collection', function(done) { - service.insertOne('data-service.test', { a: 500 }, {}, function(err) { + service.insertOne('data-service.test', { + a: 500 + }, {}, function(err) { assert.equal(null, err); - service.find('data-service.test', { a: 500 }, {}, function(error, docs) { + service.find('data-service.test', { + a: 500 + }, {}, function(error, docs) { assert.equal(null, error); expect(docs.length).to.equal(1); done(); @@ -247,9 +277,15 @@ describe('DataService', function() { }); it('inserts the documents into the collection', function(done) { - service.insertMany('data-service.test', [{ a: 500 }, { a: 500 }], {}, function(err) { + service.insertMany('data-service.test', [{ + a: 500 + }, { + a: 500 + }], {}, function(err) { assert.equal(null, err); - service.find('data-service.test', { a: 500 }, {}, function(error, docs) { + service.find('data-service.test', { + a: 500 + }, {}, function(error, docs) { assert.equal(null, error); expect(docs.length).to.equal(2); done(); @@ -295,11 +331,21 @@ describe('DataService', function() { }); it('updates the document', function(done) { - service.insertOne('data-service.test', { a: 500 }, {}, function(err) { + service.insertOne('data-service.test', { + a: 500 + }, {}, function(err) { assert.equal(null, err); - service.updateOne('data-service.test', { a: 500 }, { '$set': { a: 600 }}, {}, function(er) { + service.updateOne('data-service.test', { + a: 500 + }, { + $set: { + a: 600 + } + }, {}, function(er) { assert.equal(null, er); - service.find('data-service.test', { a: 600 }, {}, function(error, docs) { + service.find('data-service.test', { + a: 600 + }, {}, function(error, docs) { assert.equal(null, error); expect(docs.length).to.equal(1); done(); @@ -317,11 +363,23 @@ describe('DataService', function() { }); it('updates the documents', function(done) { - service.insertMany('data-service.test', [{ a: 500 }, { a: 500 }], {}, function(err) { + service.insertMany('data-service.test', [{ + a: 500 + }, { + a: 500 + }], {}, function(err) { assert.equal(null, err); - service.updateMany('data-service.test', { a: 500 }, { '$set': { a: 600 }}, {}, function(er) { + service.updateMany('data-service.test', { + a: 500 + }, { + $set: { + a: 600 + } + }, {}, function(er) { assert.equal(null, er); - service.find('data-service.test', { a: 600 }, {}, function(error, docs) { + service.find('data-service.test', { + a: 600 + }, {}, function(error, docs) { assert.equal(null, error); expect(docs.length).to.equal(2); done(); diff --git a/test/helper.js b/test/helper.js index 7e17cc51..1b7dafaa 100644 --- a/test/helper.js +++ b/test/helper.js @@ -9,12 +9,19 @@ module.exports.assert = assert; module.exports.expect = expect; module.exports.eventStream = es; -module.exports.connection = - new Connection({ hostname: '127.0.0.1', port: 27018, ns: 'data-service' }); +module.exports.connection = new Connection({ + hostname: '127.0.0.1', + port: 27018, + ns: 'data-service' +}); module.exports.insertTestDocuments = function(client, callback) { var collection = client.database.collection('test'); - collection.insertMany([{ a: 1 }, { a: 2 }], callback); + collection.insertMany([{ + a: 1 + }, { + a: 2 + }], callback); }; module.exports.deleteTestDocuments = function(client, callback) { diff --git a/test/native-client.test.js b/test/native-client.test.js index 975f173e..296b5e90 100644 --- a/test/native-client.test.js +++ b/test/native-client.test.js @@ -25,10 +25,14 @@ describe('NativeClient', function() { describe('#connect', function() { context('when an invalid connection was provided', function() { - var badConnection = - new Connection({ hostname: '127.0.0.1', port: 27050, ns: 'data-service' }); + var badConnection = new Connection({ + hostname: '127.0.0.1', + port: 27050, + ns: 'data-service' + }); var badClient = new NativeClient(badConnection); - var message = 'MongoDB not running on the provided host and port'; + // var message = 'MongoDB not running on the provided host and port'; + var message = 'Could not connect to MongoDB on the provided host and port'; it('maps the error message', function(done) { badClient.connect(function(error) { expect(error.message).to.equal(message); @@ -59,7 +63,9 @@ describe('NativeClient', function() { context('when a filter is provided', function() { it('returns a cursor for the matching documents', function(done) { - client.find('data-service.test', { a: 1 }, {}, function(error, docs) { + client.find('data-service.test', { + a: 1 + }, {}, function(error, docs) { assert.equal(null, error); expect(docs.length).to.equal(1); done(); @@ -79,7 +85,9 @@ describe('NativeClient', function() { context('when options are provided', function() { it('returns a cursor for the documents', function(done) { - client.find('data-service.test', {}, { skip: 1 }, function(error, docs) { + client.find('data-service.test', {}, { + skip: 1 + }, function(error, docs) { assert.equal(null, error); expect(docs.length).to.equal(1); done(); @@ -189,7 +197,9 @@ describe('NativeClient', function() { describe('#count', function() { context('when a filter is provided', function() { it('returns a count for the matching documents', function(done) { - client.count('data-service.test', { a: 1 }, {}, function(error, count) { + client.count('data-service.test', { + a: 1 + }, {}, function(error, count) { assert.equal(null, error); expect(count).to.equal(0); done(); @@ -201,7 +211,9 @@ describe('NativeClient', function() { describe('#explain', function() { context('when a filter is provided', function() { it('returns an explain object for the provided filter', function(done) { - client.explain('data-service.test', { a: 1 }, {}, function(error, explanation) { + client.explain('data-service.test', { + a: 1 + }, {}, function(error, explanation) { assert.equal(null, error); expect(explanation).to.be.an('object'); done(); @@ -212,11 +224,17 @@ describe('NativeClient', function() { describe('#deleteOne', function() { it('deletes the document from the collection', function(done) { - client.insertOne('data-service.test', { a: 500 }, {}, function(err) { + client.insertOne('data-service.test', { + a: 500 + }, {}, function(err) { assert.equal(null, err); - client.deleteOne('data-service.test', { a: 500 }, {}, function(er) { + client.deleteOne('data-service.test', { + a: 500 + }, {}, function(er) { assert.equal(null, er); - client.find('data-service.test', { a: 500 }, {}, function(error, docs) { + client.find('data-service.test', { + a: 500 + }, {}, function(error, docs) { assert.equal(null, error); expect(docs.length).to.equal(0); done(); @@ -228,11 +246,19 @@ describe('NativeClient', function() { describe('#deleteMany', function() { it('deletes the documents from the collection', function(done) { - client.insertMany('data-service.test', [{ a: 500 }, { a: 500 }], {}, function(err) { + client.insertMany('data-service.test', [{ + a: 500 + }, { + a: 500 + }], {}, function(err) { assert.equal(null, err); - client.deleteMany('data-service.test', { a: 500 }, {}, function(er) { + client.deleteMany('data-service.test', { + a: 500 + }, {}, function(er) { assert.equal(null, er); - client.find('data-service.test', { a: 500 }, {}, function(error, docs) { + client.find('data-service.test', { + a: 500 + }, {}, function(error, docs) { assert.equal(null, error); expect(docs.length).to.equal(0); done(); @@ -253,16 +279,24 @@ describe('NativeClient', function() { var id = new ObjectId(); it('returns the updated document', function(done) { - client.insertOne('data-service.test', { _id: id, a: 500 }, {}, function(err) { + client.insertOne('data-service.test', { + _id: id, + a: 500 + }, {}, function(err) { assert.equal(null, err); client.findOneAndReplace( 'data-service.test', - { _id: id }, - { b: 5 }, - { returnOriginal: false }, - function(error, result) { + { + _id: id + }, + { + b: 5 + }, + { + returnOriginal: false + }, function(error, result) { expect(error).to.equal(null); - expect(result._id).to.deep.equal(id); + expect(result._id.toString()).to.deep.equal(id.toString()); expect(result.b).to.equal(5); expect(result.hasOwnProperty('a')).to.equal(false); done(); @@ -276,14 +310,22 @@ describe('NativeClient', function() { var id = new ObjectId(); it('returns the updated document', function(done) { - client.insertOne('data-service.test', { _id: id, a: 500 }, {}, function(err) { + client.insertOne('data-service.test', { + _id: id, + a: 500 + }, {}, function(err) { assert.equal(null, err); client.findOneAndReplace( 'data-service.test', - { _id: id }, - { '$b': 5 }, - { returnOriginal: false }, - function(error) { + { + _id: id + }, + { + $b: 5 + }, + { + returnOriginal: false + }, function(error) { expect(error.message).to.not.equal(null); done(); } @@ -337,9 +379,13 @@ describe('NativeClient', function() { }); it('inserts the document into the collection', function(done) { - client.insertOne('data-service.test', { a: 500 }, {}, function(err) { + client.insertOne('data-service.test', { + a: 500 + }, {}, function(err) { assert.equal(null, err); - client.find('data-service.test', { a: 500 }, {}, function(error, docs) { + client.find('data-service.test', { + a: 500 + }, {}, function(error, docs) { assert.equal(null, error); expect(docs.length).to.equal(1); done(); @@ -356,9 +402,15 @@ describe('NativeClient', function() { }); it('inserts the documents into the collection', function(done) { - client.insertMany('data-service.test', [{ a: 500 }, { a: 500 }], {}, function(err) { + client.insertMany('data-service.test', [{ + a: 500 + }, { + a: 500 + }], {}, function(err) { assert.equal(null, err); - client.find('data-service.test', { a: 500 }, {}, function(error, docs) { + client.find('data-service.test', { + a: 500 + }, {}, function(error, docs) { assert.equal(null, error); expect(docs.length).to.equal(2); done(); @@ -418,11 +470,21 @@ describe('NativeClient', function() { }); it('updates the document', function(done) { - client.insertOne('data-service.test', { a: 500 }, {}, function(err) { + client.insertOne('data-service.test', { + a: 500 + }, {}, function(err) { assert.equal(null, err); - client.updateOne('data-service.test', { a: 500 }, { '$set': { a: 600 }}, {}, function(er) { + client.updateOne('data-service.test', { + a: 500 + }, { + $set: { + a: 600 + } + }, {}, function(er) { assert.equal(null, er); - client.find('data-service.test', { a: 600 }, {}, function(error, docs) { + client.find('data-service.test', { + a: 600 + }, {}, function(error, docs) { assert.equal(null, error); expect(docs.length).to.equal(1); done(); @@ -440,11 +502,23 @@ describe('NativeClient', function() { }); it('updates the documents', function(done) { - client.insertMany('data-service.test', [{ a: 500 }, { a: 500 }], {}, function(err) { + client.insertMany('data-service.test', [{ + a: 500 + }, { + a: 500 + }], {}, function(err) { assert.equal(null, err); - client.updateMany('data-service.test', { a: 500 }, { '$set': { a: 600 }}, {}, function(er) { + client.updateMany('data-service.test', { + a: 500 + }, { + $set: { + a: 600 + } + }, {}, function(er) { assert.equal(null, er); - client.find('data-service.test', { a: 600 }, {}, function(error, docs) { + client.find('data-service.test', { + a: 600 + }, {}, function(error, docs) { assert.equal(null, error); expect(docs.length).to.equal(2); done(); diff --git a/test/ssh-tunnel-connector.test.js b/test/ssh-tunnel-connector.test.js deleted file mode 100644 index 32024a6c..00000000 --- a/test/ssh-tunnel-connector.test.js +++ /dev/null @@ -1,60 +0,0 @@ -'use strict'; - -const helper = require('./helper'); -const assert = helper.assert; -const expect = helper.expect; - -const NativeClient = require('../lib/native-client'); -const fixture = require('mongodb-connection-fixture'); -const Connection = require('mongodb-connection-model'); -const SshTunnelConnector = require('../lib/ssh-tunnel-connector'); -const _ = require('lodash'); - -describe('SshTunnelConnector', function() { - this.timeout(15000); - - if (fixture.SSH_TUNNEL_MATRIX.length > 0) { - _.map(fixture.SSH_TUNNEL_MATRIX, function(model) { - var connection = new Connection(model); - var client = new NativeClient(connection); - - describe('#connect', function() { - var connector = new SshTunnelConnector(connection.ssh_tunnel_options); - - it('connects to the ssh tunnel', function(done) { - connector.connect(function() { - client.connect(function(err) { - expect(err).to.equal(null); - client.find('mongodb.fanclub', {}, { limit: 10 }, function(error, docs) { - assert.equal(null, error); - expect(docs.length).to.equal(10); - done(); - }); - }); - }); - }); - }); - }); - } - describe('#regression', function() { - /** - * @see https://jira.mongodb.org/browse/INT-1510 - */ - it('should error when ssh fails', function(done) { - var connector = new SshTunnelConnector({ - dstHost: 'localhost', - dstPort: 27107, - username: 'foo', - password: 'bar', - host: 'remotehost', - sshPort: 22 - }); - - connector.connect(function(err) { - expect(err).not.to.equal(null, 'should have an error'); - expect(err).not.to.equal(undefined, 'should have an error'); - done(); - }); - }); - }); -});