Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
test(mongodb+srv): add test harness for mongodb+srv tests
Browse files Browse the repository at this point in the history
NODE-1295
  • Loading branch information
mbroadst committed Jan 23, 2018
1 parent 8f797a7 commit b513019
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/tests/unit/mongodb_srv_spec_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'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() {
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, (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();
});
}
});
});
});

0 comments on commit b513019

Please sign in to comment.