|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -var expect = require('chai').expect, |
4 |
| - f = require('util').format, |
5 |
| - locateAuthMethod = require('./shared').locateAuthMethod, |
6 |
| - executeCommand = require('./shared').executeCommand, |
7 |
| - Server = require('../../../lib/topologies/server'), |
8 |
| - Bson = require('bson'), |
9 |
| - Connection = require('../../../lib/connection/connection'); |
| 3 | +const expect = require('chai').expect; |
| 4 | +const f = require('util').format; |
| 5 | +const locateAuthMethod = require('./shared').locateAuthMethod; |
| 6 | +const executeCommand = require('./shared').executeCommand; |
| 7 | +const Server = require('../../../lib/topologies/server'); |
| 8 | +const Bson = require('bson'); |
| 9 | +const Connection = require('../../../lib/connection/connection'); |
| 10 | +const mock = require('../../mock'); |
10 | 11 |
|
11 | 12 | describe('Server tests', function() {
|
12 | 13 | it('should correctly connect server to single instance', {
|
@@ -1043,4 +1044,36 @@ describe('Server tests', function() {
|
1043 | 1044 | }
|
1044 | 1045 | }
|
1045 | 1046 | );
|
| 1047 | + |
| 1048 | + describe('Unsupported wire protocols', function() { |
| 1049 | + let server; |
| 1050 | + beforeEach(() => mock.createServer().then(_server => (server = _server))); |
| 1051 | + afterEach(() => mock.cleanup()); |
| 1052 | + |
| 1053 | + it('errors when unsupported wire protocol is returned from isMaster', { |
| 1054 | + metadata: { requires: { topology: ['single'] } }, |
| 1055 | + |
| 1056 | + test: function(done) { |
| 1057 | + server.setMessageHandler(request => { |
| 1058 | + request.reply({ ok: 1 }); |
| 1059 | + }); |
| 1060 | + |
| 1061 | + const client = new Server(server.address()); |
| 1062 | + client.on('error', error => { |
| 1063 | + let err; |
| 1064 | + try { |
| 1065 | + expect(error).to.be.an.instanceOf(Error); |
| 1066 | + expect(error.message).to.have.string('but this version of Node.js Driver requires'); |
| 1067 | + } catch (e) { |
| 1068 | + err = e; |
| 1069 | + } |
| 1070 | + done(err); |
| 1071 | + }); |
| 1072 | + client.on('connect', () => { |
| 1073 | + done(new Error('This should not connect')); |
| 1074 | + }); |
| 1075 | + client.connect(); |
| 1076 | + } |
| 1077 | + }); |
| 1078 | + }); |
1046 | 1079 | });
|
0 commit comments