forked from mongodb/node-mongodb-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmax_staleness.spec.test.js
More file actions
56 lines (48 loc) · 1.53 KB
/
max_staleness.spec.test.js
File metadata and controls
56 lines (48 loc) · 1.53 KB
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
'use strict';
const path = require('path');
const fs = require('fs');
const { executeServerSelectionTest } = require('./server_selection_spec_helper');
const { Server } = require('../../mongodb');
const { EJSON } = require('bson');
const sinon = require('sinon');
const maxStalenessDir = path.join(__dirname, '../../spec/max-staleness');
function collectStalenessTests(specDir) {
const testTypes = fs
.readdirSync(specDir)
.filter(d => fs.statSync(path.join(specDir, d)).isDirectory());
const tests = {};
testTypes.forEach(testType => {
tests[testType] = fs
.readdirSync(path.join(specDir, testType))
.filter(f => path.extname(f) === '.json')
.map(f => {
const result = EJSON.parse(fs.readFileSync(path.join(specDir, testType, f)), {
relaxed: true
});
result.description = path.basename(f, '.json');
result.type = testType;
return result;
});
});
return tests;
}
describe('Max Staleness (spec)', function () {
let serverConnect;
before(() => {
serverConnect = sinon.stub(Server.prototype, 'connect').callsFake(function () {
this.s.state = 'connected';
});
});
after(() => {
serverConnect.restore();
});
const specTests = collectStalenessTests(maxStalenessDir);
for (const [specTestName, test] of Object.entries(specTests)) {
describe(specTestName, () => {
for (const testData of test)
it(testData.description, async function () {
return executeServerSelectionTest(testData);
});
});
}
});