-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
optional_require.test.js
71 lines (66 loc) · 1.98 KB
/
optional_require.test.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
const { expect } = require('chai');
const { existsSync } = require('fs');
const { resolve } = require('path');
const { compress } = require('../../src/cmap/wire_protocol/compression');
const { GSSAPI } = require('../../src/cmap/auth/gssapi');
const { AuthContext } = require('../../src/cmap/auth/auth_provider');
const { MongoDBAWS } = require('../../src/cmap/auth/mongodb_aws');
function moduleExistsSync(moduleName) {
return existsSync(resolve(__dirname, `../../node_modules/${moduleName}`));
}
describe('optionalRequire', function () {
context('Snappy', function () {
it('should error if not installed', function () {
const moduleName = 'snappy';
if (moduleExistsSync(moduleName)) {
return this.skip();
}
compress(
{
options: {
agreedCompressor: 'snappy'
}
},
Buffer.alloc(1),
error => {
expect(error).to.exist;
expect(error.message).includes('not found');
}
);
});
});
context('Kerberos', function () {
it('should error if not installed', function () {
const moduleName = 'kerberos';
if (moduleExistsSync(moduleName)) {
return this.skip();
}
const gssapi = new GSSAPI();
gssapi.auth(new AuthContext(null, true, { host: true, port: true }), error => {
expect(error).to.exist;
expect(error.message).includes('not found');
});
});
});
context('aws4', {
metadata: {
requires: {
mongodb: '>=4.4'
}
},
test: function () {
it('should error if not installed', function () {
const moduleName = 'aws4';
if (moduleExistsSync(moduleName)) {
return this.skip();
}
const mdbAWS = new MongoDBAWS();
mdbAWS.auth(new AuthContext({ ismaster: { maxWireVersion: 9 } }, true, null), error => {
expect(error).to.exist;
expect(error.message).includes('not found');
});
});
}
});
});