|
| 1 | +import { expect } from 'chai'; |
| 2 | +import * as dns from 'dns'; |
| 3 | + |
| 4 | +import { MongoClient } from '../../mongodb'; |
| 5 | +import sinon = require('sinon'); |
| 6 | + |
| 7 | +describe.only('Initial DNS Seedlist Discovery (Prose Tests)', () => { |
| 8 | + function makeSrvStub() { |
| 9 | + sinon.stub(dns.promises, 'resolveSrv').callsFake(async () => { |
| 10 | + return [ |
| 11 | + { |
| 12 | + name: 'localhost', |
| 13 | + port: 27017, |
| 14 | + weight: 0, |
| 15 | + priority: 0 |
| 16 | + } |
| 17 | + ]; |
| 18 | + }); |
| 19 | + |
| 20 | + sinon.stub(dns.promises, 'resolveTxt').callsFake(async () => { |
| 21 | + throw { code: 'ENODATA' }; |
| 22 | + }); |
| 23 | + } |
| 24 | + |
| 25 | + afterEach(async () => { |
| 26 | + sinon.restore(); |
| 27 | + }); |
| 28 | + |
| 29 | + it('1.1 Driver should not throw error on SRV URI with two parts', async () => { |
| 30 | + // 1. stub dns resolution to always pass |
| 31 | + makeSrvStub(); |
| 32 | + // 2. assert that creating a MongoClient with the uri 'mongodb+srv://mongodb.localhost' does not cause an error |
| 33 | + //const client = new MongoClient('mongodb+srv://mongodb.localhost', {}); |
| 34 | + const client = new MongoClient('mongodb+srv://mongodb.localhost'); |
| 35 | + // 3. assert that connecting the client from 2. to the server does not cause an error |
| 36 | + await client.connect(); |
| 37 | + }); |
| 38 | + |
| 39 | + it('1.2 Driver should not throw error on SRV URI with one part', async () => { |
| 40 | + // 1. stub dns resolution to always pass |
| 41 | + makeSrvStub(); |
| 42 | + // 2. assert that creating a MongoClient with the uri 'mongodb+srv//localhost' does not cause an error |
| 43 | + const client = new MongoClient('mongodb+srv://localhost', {}); |
| 44 | + // 3. assert that connecting the client from 2. to the server does not cause an error |
| 45 | + await client.connect(); |
| 46 | + }); |
| 47 | +}); |
0 commit comments