forked from mongodb/node-mongodb-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.test.ts
46 lines (41 loc) · 1.49 KB
/
errors.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
import { expect } from 'chai';
import { MongoClient, MongoServerSelectionError, ReadPreference } from '../../mongodb';
describe('Error (Integration)', function () {
it('NODE-5296: handles aggregate errors from dns lookup', async function () {
const error = await MongoClient.connect('mongodb://localhost:27222', {
serverSelectionTimeoutMS: 1000
}).catch(e => e);
expect(error).to.be.instanceOf(MongoServerSelectionError);
expect(error.message).not.to.be.empty;
});
context('when a server selection error is stringified', function () {
it(
'the error"s topology description correctly displays the `servers`',
{ requires: { topology: 'replicaset' } },
async function () {
const client: MongoClient = this.configuration.newClient({
serverSelectionTimeoutMS: 1000
});
try {
await client.connect();
const error = await client
.db('foo')
.collection('bar')
.find(
{},
{
// Use meaningless read preference tags to ensure that the server selection fails
readPreference: new ReadPreference('secondary', [{ ny: 'ny' }])
}
)
.toArray()
.catch(e => JSON.parse(JSON.stringify(e)));
const servers = error.reason.servers;
expect(Object.keys(servers).length > 0).to.be.true;
} finally {
await client.close();
}
}
);
});
});