-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
ipv6.test.ts
48 lines (41 loc) · 1.47 KB
/
ipv6.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { expect } from 'chai';
import * as net from 'net';
import * as process from 'process';
import * as sinon from 'sinon';
import { TopologyType } from '../../../src';
import { byStrings, sorted } from '../../tools/utils';
describe('IPv6 Addresses', () => {
let client;
let ipv6Hosts;
beforeEach(async function () {
if (
process.platform !== 'win32' &&
this.configuration.topologyType !== TopologyType.ReplicaSetWithPrimary
) {
// Ubuntu 18 does not support localhost AAAA lookups (IPv6)
// Windows (VS2019) does
return this.skip();
}
ipv6Hosts = this.configuration.options.hostAddresses.map(({ port }) => `[::1]:${port}`);
client = this.configuration.newClient(`mongodb://${ipv6Hosts.join(',')}/test`, {
family: 6,
[Symbol.for('@@mdb.skipPingOnConnect')]: true
});
});
afterEach(async function () {
sinon.restore();
await client.close();
});
it('should successfully connect using ipv6', async () => {
await client.db().command({ ping: 1 });
expect(sorted(client.topology.s.description.servers.keys(), byStrings)).to.deep.equal(
ipv6Hosts
);
});
it('should connect using ipv6 in connection string', async () => {
const createConnectionSpy = sinon.spy(net, 'createConnection');
await client.db().command({ ping: 1 });
expect(createConnectionSpy).to.be.calledWithMatch({ host: '::1' });
expect(createConnectionSpy).to.not.be.calledWithMatch({ host: 'localhost' });
});
});