Skip to content

Commit bede1f0

Browse files
committed
test: move all specs to a common top-level spec folder
1 parent da05a46 commit bede1f0

File tree

521 files changed

+140
-2912
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

521 files changed

+140
-2912
lines changed

test/functional/apm.test.js

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'use strict';
22

33
const instrument = require('../..').instrument;
4-
const path = require('path');
5-
const fs = require('fs');
64
const shared = require('./shared');
75
const setupDatabase = shared.setupDatabase;
86
const filterForCommands = shared.filterForCommands;
97
const filterOutCommands = shared.filterOutCommands;
108
const ignoreNsNotFound = shared.ignoreNsNotFound;
11-
const EJSON = require('mongodb-extjson');
9+
const loadSpecTests = require('../spec').loadSpecTests;
1210
const chai = require('chai');
1311
const expect = chai.expect;
1412

@@ -1075,43 +1073,34 @@ describe('APM', function() {
10751073
});
10761074
}
10771075

1078-
fs
1079-
.readdirSync(__dirname + '/spec/apm')
1080-
.filter(x => x.indexOf('.json') !== -1)
1081-
.map(x =>
1082-
Object.assign(
1083-
{ title: path.basename(x, '.json') },
1084-
EJSON.parse(fs.readFileSync(__dirname + '/spec/apm/' + x), { relaxed: true })
1085-
)
1086-
)
1087-
.forEach(scenario => {
1088-
describe(scenario.title, function() {
1089-
scenario.tests.forEach(test => {
1090-
const requirements = { topology: ['single', 'replicaset', 'sharded'] };
1091-
if (test.ignore_if_server_version_greater_than) {
1092-
requirements.mongodb = `<${test.ignore_if_server_version_greater_than}`;
1093-
} else if (test.ignore_if_server_version_less_than) {
1094-
requirements.mongodb = `>${test.ignore_if_server_version_less_than}`;
1095-
}
1076+
loadSpecTests('apm').forEach(scenario => {
1077+
describe(scenario.name, function() {
1078+
scenario.tests.forEach(test => {
1079+
const requirements = { topology: ['single', 'replicaset', 'sharded'] };
1080+
if (test.ignore_if_server_version_greater_than) {
1081+
requirements.mongodb = `<${test.ignore_if_server_version_greater_than}`;
1082+
} else if (test.ignore_if_server_version_less_than) {
1083+
requirements.mongodb = `>${test.ignore_if_server_version_less_than}`;
1084+
}
10961085

1097-
if (test.ignore_if_topology_type) {
1098-
requirements.topology = requirements.topology.filter(
1099-
top => test.ignore_if_topology_type.indexOf(top) < 0
1100-
);
1101-
}
1086+
if (test.ignore_if_topology_type) {
1087+
requirements.topology = requirements.topology.filter(
1088+
top => test.ignore_if_topology_type.indexOf(top) < 0
1089+
);
1090+
}
11021091

1103-
it(test.description, {
1104-
metadata: { requires: requirements },
1105-
test: function() {
1106-
const client = this.configuration.newClient({}, { monitorCommands: true });
1107-
return client.connect().then(client => {
1108-
expect(client).to.exist;
1109-
return executeOperation(client, scenario, test).then(() => client.close());
1110-
});
1111-
}
1112-
});
1092+
it(test.description, {
1093+
metadata: { requires: requirements },
1094+
test: function() {
1095+
const client = this.configuration.newClient({}, { monitorCommands: true });
1096+
return client.connect().then(client => {
1097+
expect(client).to.exist;
1098+
return executeOperation(client, scenario, test).then(() => client.close());
1099+
});
1100+
}
11131101
});
11141102
});
11151103
});
1104+
});
11161105
});
11171106
});

test/functional/change_stream_spec.test.js

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
22

3-
const EJSON = require('mongodb-extjson');
43
const chai = require('chai');
5-
const fs = require('fs');
4+
const loadSpecTests = require('../spec').loadSpecTests;
65
const camelCase = require('lodash.camelcase');
76
const setupDatabase = require('./shared').setupDatabase;
87
const delay = require('./shared').delay;
@@ -29,56 +28,50 @@ describe('Change Stream Spec', function() {
2928
return new Promise(r => gc.close(() => r()));
3029
});
3130

32-
fs
33-
.readdirSync(`${__dirname}/spec/change-stream`)
34-
.filter(filename => filename.match(/\.json$/))
35-
.forEach(filename => {
36-
const specString = fs.readFileSync(`${__dirname}/spec/change-stream/${filename}`, 'utf8');
37-
const specData = EJSON.parse(specString, { relaxed: true });
38-
39-
const ALL_DBS = [specData.database_name, specData.database2_name];
40-
41-
describe(filename, () => {
42-
beforeEach(function() {
43-
const gc = globalClient;
44-
const sDB = specData.database_name;
45-
const sColl = specData.collection_name;
46-
const configuration = this.configuration;
47-
return Promise.all(ALL_DBS.map(db => gc.db(db).dropDatabase({ w: 'majority' })))
48-
.then(() => gc.db(sDB).createCollection(sColl))
49-
.then(() => gc.db(specData.database2_name).createCollection(specData.collection2_name))
50-
.then(() => configuration.newClient({}, { monitorCommands: true }).connect())
51-
.then(client => {
52-
ctx = { gc, client };
53-
events = [];
54-
const _events = events;
55-
56-
ctx.database = ctx.client.db(sDB);
57-
ctx.collection = ctx.database.collection(sColl);
58-
ctx.client.on('commandStarted', e => _events.push(e));
59-
});
60-
});
31+
loadSpecTests('change-stream').forEach(suite => {
32+
const ALL_DBS = [suite.database_name, suite.database2_name];
33+
34+
describe(suite.name, () => {
35+
beforeEach(function() {
36+
const gc = globalClient;
37+
const sDB = suite.database_name;
38+
const sColl = suite.collection_name;
39+
const configuration = this.configuration;
40+
return Promise.all(ALL_DBS.map(db => gc.db(db).dropDatabase({ w: 'majority' })))
41+
.then(() => gc.db(sDB).createCollection(sColl))
42+
.then(() => gc.db(suite.database2_name).createCollection(suite.collection2_name))
43+
.then(() => configuration.newClient({}, { monitorCommands: true }).connect())
44+
.then(client => {
45+
ctx = { gc, client };
46+
events = [];
47+
const _events = events;
48+
49+
ctx.database = ctx.client.db(sDB);
50+
ctx.collection = ctx.database.collection(sColl);
51+
ctx.client.on('commandStarted', e => _events.push(e));
52+
});
53+
});
6154

62-
afterEach(function() {
63-
const client = ctx.client;
64-
ctx = undefined;
65-
events = undefined;
55+
afterEach(function() {
56+
const client = ctx.client;
57+
ctx = undefined;
58+
events = undefined;
6659

67-
client.removeAllListeners('commandStarted');
60+
client.removeAllListeners('commandStarted');
6861

69-
return client && client.close(true);
70-
});
62+
return client && client.close(true);
63+
});
7164

72-
specData.tests.forEach(test => {
73-
const shouldSkip = test.skip || TESTS_TO_SKIP.has(test.description);
74-
const itFn = shouldSkip ? it.skip : test.only ? it.only : it;
75-
const metadata = generateMetadata(test);
76-
const testFn = generateTestFn(test);
65+
suite.tests.forEach(test => {
66+
const shouldSkip = test.skip || TESTS_TO_SKIP.has(test.description);
67+
const itFn = shouldSkip ? it.skip : test.only ? it.only : it;
68+
const metadata = generateMetadata(test);
69+
const testFn = generateTestFn(test);
7770

78-
itFn(test.description, { metadata, test: testFn });
79-
});
71+
itFn(test.description, { metadata, test: testFn });
8072
});
8173
});
74+
});
8275

8376
// Fn Generator methods
8477

@@ -206,7 +199,10 @@ describe('Change Stream Spec', function() {
206199
});
207200
}
208201

209-
return changeStreamPromise.then(result => close(null, result), err => close(err));
202+
return changeStreamPromise.then(
203+
result => close(null, result),
204+
err => close(err)
205+
);
210206
}
211207

212208
function runOperations(client, operations) {

test/functional/client_side_encryption/corpus.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('Client Side Encryption Corpus', function() {
1919
}
2020
};
2121

22-
const corpusDir = path.resolve(__dirname, '..', 'spec', 'client-side-encryption', 'corpus');
22+
const corpusDir = path.resolve(__dirname, '../../spec/client-side-encryption/corpus');
2323
function loadCorpusData(filename) {
2424
return EJSON.parse(fs.readFileSync(path.resolve(corpusDir, filename), { strict: true }));
2525
}

test/functional/client_side_encryption/prose.test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,7 @@ describe('Client Side Encryption Prose Tests', function() {
454454
const EJSON = require('mongodb-extjson');
455455
function loadLimits(file) {
456456
return EJSON.parse(
457-
fs.readFileSync(
458-
path.resolve(__dirname, '..', 'spec', 'client-side-encryption', 'limits', file)
459-
)
457+
fs.readFileSync(path.resolve(__dirname, '../../spec/client-side-encryption/limits', file))
460458
);
461459
}
462460

@@ -731,9 +729,7 @@ describe('Client Side Encryption Prose Tests', function() {
731729
const EJSON = require('mongodb-extjson');
732730
function loadExternal(file) {
733731
return EJSON.parse(
734-
fs.readFileSync(
735-
path.resolve(__dirname, '..', 'spec', 'client-side-encryption', 'external', file)
736-
)
732+
fs.readFileSync(path.resolve(__dirname, '../../spec/client-side-encryption/external', file))
737733
);
738734
}
739735

test/functional/client_side_encryption/spec.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('Client Side Encryption', function() {
2424
}
2525

2626
const testContext = new TestRunnerContext();
27-
const testSuites = gatherTestSuites(path.join(__dirname, '..', 'spec', 'client-side-encryption'));
27+
const testSuites = gatherTestSuites(path.join(__dirname, '../../spec/client-side-encryption'));
2828
after(() => testContext.teardown());
2929
before(function() {
3030
return testContext.setup(this.configuration);
Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,32 @@
11
'use strict';
22

3-
const parse = require('../../lib/url_parser'),
4-
fs = require('fs'),
5-
f = require('util').format,
6-
expect = require('chai').expect;
3+
const parse = require('../../lib/url_parser');
4+
const expect = require('chai').expect;
5+
const loadSpecTests = require('../spec').loadSpecTests;
76

87
describe('Connection String (spec)', function() {
9-
const testFiles = fs
10-
.readdirSync(f('%s/spec/connection-string', __dirname))
11-
.filter(function(x) {
12-
return x.indexOf('.json') !== -1;
13-
})
14-
.map(function(x) {
15-
return JSON.parse(fs.readFileSync(f('%s/spec/connection-string/%s', __dirname, x)));
16-
});
17-
18-
// Execute the tests
19-
for (let i = 0; i < testFiles.length; i++) {
20-
const testFile = testFiles[i];
21-
22-
// Get each test
23-
for (let j = 0; j < testFile.tests.length; j++) {
24-
const test = testFile.tests[j];
8+
loadSpecTests('connection-string').forEach(suite => {
9+
describe(suite.name, function() {
10+
suite.tests.forEach(test => {
11+
it(test.description, {
12+
metadata: { requires: { topology: 'single' } },
13+
test: function(done) {
14+
const valid = test.valid;
2515

26-
it(test.description, {
27-
metadata: { requires: { topology: 'single' } },
28-
test: function(done) {
29-
const valid = test.valid;
16+
parse(test.uri, {}, function(err, result) {
17+
if (valid === false) {
18+
expect(err).to.exist;
19+
expect(result).to.not.exist;
20+
} else {
21+
expect(err).to.not.exist;
22+
expect(result).to.exist;
23+
}
3024

31-
parse(test.uri, {}, function(err, result) {
32-
if (valid === false) {
33-
expect(err).to.exist;
34-
expect(result).to.not.exist;
35-
} else {
36-
expect(err).to.not.exist;
37-
expect(result).to.exist;
38-
}
39-
40-
done();
41-
});
42-
}
25+
done();
26+
});
27+
}
28+
});
4329
});
44-
}
45-
}
30+
});
31+
});
4632
});

test/functional/crud_spec.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ const gatherTestSuites = require('./spec-runner').gatherTestSuites;
1313
const generateTopologyTests = require('./spec-runner').generateTopologyTests;
1414

1515
function findScenarios() {
16-
const route = [__dirname, 'spec', 'crud'].concat(Array.from(arguments));
16+
const route = [__dirname, '..', 'spec', 'crud'].concat(Array.from(arguments));
1717
return fs
18-
.readdirSync(path.join.apply(path, route))
18+
.readdirSync(path.resolve.apply(path, route))
1919
.filter(x => x.indexOf('json') !== -1)
20-
.map(x => [x, fs.readFileSync(path.join.apply(path, route.concat([x])), 'utf8')])
20+
.map(x => [x, fs.readFileSync(path.resolve.apply(path, route.concat([x])), 'utf8')])
2121
.map(x => [path.basename(x[0], '.json'), JSON.parse(x[1])]);
2222
}
2323

@@ -474,7 +474,7 @@ describe('CRUD spec', function() {
474474

475475
describe('CRUD v2', function() {
476476
const testContext = new TestRunnerContext();
477-
const testSuites = gatherTestSuites(path.join(__dirname, 'spec', 'crud', 'v2'));
477+
const testSuites = gatherTestSuites(path.resolve(__dirname, '../spec/crud/v2'));
478478
after(() => testContext.teardown());
479479
before(function() {
480480
return testContext.setup(this.configuration);

test/functional/gridfs_stream.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ describe('GridFS Stream', function() {
10971097
}
10981098
});
10991099

1100-
var UPLOAD_SPEC = require('./spec/gridfs/gridfs-upload.json');
1100+
var UPLOAD_SPEC = require('../spec/gridfs/gridfs-upload.json');
11011101
UPLOAD_SPEC.tests.forEach(function(specTest) {
11021102
(function(testSpec) {
11031103
it(testSpec.description, {
@@ -1155,7 +1155,7 @@ describe('GridFS Stream', function() {
11551155
})(specTest);
11561156
});
11571157

1158-
var DOWNLOAD_SPEC = require('./spec/gridfs/gridfs-download.json');
1158+
var DOWNLOAD_SPEC = require('../spec/gridfs/gridfs-download.json');
11591159
DOWNLOAD_SPEC.tests.forEach(function(specTest) {
11601160
(function(testSpec) {
11611161
it(testSpec.description, {

test/functional/mongodb_srv.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ var expect = require('chai').expect;
88

99
function getTests() {
1010
return fs
11-
.readdirSync(path.join(__dirname, 'spec/dns-txt-records'))
11+
.readdirSync(path.resolve(__dirname, '../spec/dns-txt-records'))
1212
.filter(x => x.indexOf('json') !== -1)
13-
.map(x => [x, fs.readFileSync(path.join(__dirname, 'spec/dns-txt-records', x), 'utf8')])
13+
.map(x => [x, fs.readFileSync(path.resolve(__dirname, '../spec/dns-txt-records', x), 'utf8')])
1414
.map(x => [path.basename(x[0], '.json'), JSON.parse(x[1])]);
1515
}
1616

test/functional/retryable_reads.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
'use strict';
22

3-
const path = require('path');
43
const TestRunnerContext = require('./spec-runner').TestRunnerContext;
5-
const gatherTestSuites = require('./spec-runner').gatherTestSuites;
64
const generateTopologyTests = require('./spec-runner').generateTopologyTests;
5+
const loadSpecTests = require('../spec').loadSpecTests;
76

87
describe('Retryable Reads', function() {
98
const testContext = new TestRunnerContext();
10-
const testSuites = gatherTestSuites(path.join(__dirname, 'spec', 'retryable-reads'));
9+
const testSuites = loadSpecTests('retryable-reads');
1110

1211
after(() => testContext.teardown());
1312
before(function() {

0 commit comments

Comments
 (0)