This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
/
mongodb_srv_spec_tests.js
61 lines (53 loc) · 1.94 KB
/
mongodb_srv_spec_tests.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
'use strict';
const fs = require('fs');
const path = require('path');
const parseConnectionString = require('../../../lib/uri_parser');
const expect = require('chai').expect;
describe('mongodb+srv (spec)', function() {
it('should parse a default database', function(done) {
parseConnectionString('mongodb+srv://test5.test.build.10gen.cc/somedb', (err, result) => {
expect(result.auth.db).to.eql('somedb');
done();
});
});
const specPath = path.join(__dirname, '../spec', 'initial-dns-seedlist-discovery');
const testFiles = fs
.readdirSync(specPath)
.filter(x => x.indexOf('.json') !== -1)
.map(x => [x, fs.readFileSync(path.join(specPath, x), 'utf8')])
.map(x => [path.basename(x[0], '.json'), JSON.parse(x[1])]);
testFiles.forEach(test => {
if (!test[1].comment) {
test[1].comment = test[0];
}
it(test[1].comment, {
metadata: { requires: { topology: ['single'] } },
test: function(done) {
parseConnectionString(test[1].uri, { caseTranslate: false }, (err, result) => {
if (test[1].error) {
expect(err).to.exist;
expect(result).to.not.exist;
} else {
expect(err).to.not.exist;
expect(result).to.exist;
if (test[1].options && test[1].options.replicaSet) {
expect(result.options.replicaset).to.equal(test[1].options.replicaSet);
}
if (test[1].options && test[1].options.ssl) {
expect(result.options.ssl).to.equal(test[1].options.ssl);
}
if (
test[1].parsed_options &&
test[1].parsed_options.user &&
test[1].parsed_options.password
) {
expect(result.auth.username).to.equal(test[1].parsed_options.user);
expect(result.auth.password).to.equal(test[1].parsed_options.password);
}
}
done();
});
}
});
});
});