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
/
connection_string_spec_tests.js
73 lines (61 loc) · 2.26 KB
/
connection_string_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
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
const parseConnectionString = require('../../../lib/uri_parser');
const fs = require('fs');
const f = require('util').format;
const expect = require('chai').expect;
// NOTE: These are cases we could never check for unless we write out own
// url parser. The node parser simply won't let these through, so we
// are safe skipping them.
const skipTests = [
'Invalid port (negative number) with hostname',
'Invalid port (non-numeric string) with hostname',
'Missing delimiting slash between hosts and options',
// These tests are only relevant to the native driver which
// cares about specific keys, and validating their values
'Unrecognized option keys are ignored',
'Unsupported option values are ignored'
];
describe('Connection String (spec)', function() {
const testFiles = fs
.readdirSync(f('%s/../spec/connection-string', __dirname))
.filter(x => x.indexOf('.json') !== -1)
.map(x => JSON.parse(fs.readFileSync(f('%s/../spec/connection-string/%s', __dirname, x))));
// Execute the tests
for (let i = 0; i < testFiles.length; i++) {
const testFile = testFiles[i];
// Get each test
for (let j = 0; j < testFile.tests.length; j++) {
const test = testFile.tests[j];
if (skipTests.indexOf(test.description) !== -1) {
continue;
}
it(test.description, {
metadata: { requires: { topology: 'single' } },
test: function(done) {
const valid = test.valid;
parseConnectionString(test.uri, function(err, result) {
if (valid === false) {
expect(err).to.exist;
expect(result).to.not.exist;
} else {
expect(err).to.not.exist;
expect(result).to.exist;
// remove data we don't track
if (test.auth && test.auth.password === '') {
test.auth.password = null;
}
test.hosts = test.hosts.map(host => {
delete host.type;
return host;
});
expect(result.hosts).to.eql(test.hosts);
expect(result.auth).to.eql(test.auth);
expect(result.options).to.eql(test.options);
}
done();
});
}
});
}
}
});