Skip to content

Commit 91ae3e6

Browse files
authored
refactor(NODE-3717): reorganize tests part 2 (#3064)
1 parent 04db406 commit 91ae3e6

File tree

10 files changed

+69
-70
lines changed

10 files changed

+69
-70
lines changed

.evergreen/run-serverless-tests.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ if [ -z ${SERVERLESS_ATLAS_USER+omitted} ]; then echo "SERVERLESS_ATLAS_USER is
1212
if [ -z ${SERVERLESS_ATLAS_PASSWORD+omitted} ]; then echo "SERVERLESS_ATLAS_PASSWORD is unset" && exit 1; fi
1313

1414
npx mocha --file test/tools/runner/index.js \
15-
test/functional/crud_spec.test.js \
16-
test/functional/retryable_reads.test.js \
17-
test/functional/retryable_writes.test.js \
15+
test/integration/crud/crud.spec.test.js \
16+
test/integration/retryable-reads/retryable_reads.spec.test.js \
17+
test/integration/retryable-writes/retryable_writes.spec.test.js \
1818
test/functional/sessions.test.js \
1919
test/functional/transactions.test.js \
20-
test/functional/versioned-api.test.js \
21-
test/functional/load-balancer-spec.test.js
20+
test/integration/versioned-api/versioned_api.spec.test.js \
21+
test/integration/load-balancers/load_balancers.spec.test.js

test/functional/bulk.test.js renamed to test/integration/crud/bulk.test.js

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ const {
44
withClientV2,
55
withMonitoredClient,
66
setupDatabase,
7-
ignoreNsNotFound
8-
} = require('./shared');
9-
const test = require('./shared').assert;
10-
const { MongoDriverError, MongoBatchReExecutionError } = require('../../src/error');
11-
const { Long, MongoBulkWriteError } = require('../../src');
7+
ignoreNsNotFound,
8+
assert: test
9+
} = require('../shared');
10+
const { Long, MongoBatchReExecutionError, MongoDriverError } = require('../../../src');
1211
const crypto = require('crypto');
1312
const chai = require('chai');
1413
const expect = chai.expect;
@@ -21,48 +20,6 @@ describe('Bulk', function () {
2120
return setupDatabase(this.configuration);
2221
});
2322

24-
describe('Write Errors', () => {
25-
describe('errInfo property on insertMany', () => {
26-
let client;
27-
28-
beforeEach(async function () {
29-
client = this.configuration.newClient({ monitorCommands: true });
30-
await client.connect();
31-
});
32-
33-
afterEach(async () => {
34-
if (client) {
35-
await client.close();
36-
}
37-
});
38-
39-
it('should be accessible', {
40-
metadata: { requires: { mongodb: '>=5.0.0' } },
41-
async test() {
42-
try {
43-
await client.db().collection('wc_details').drop();
44-
} catch {
45-
// don't care
46-
}
47-
48-
const collection = await client
49-
.db()
50-
.createCollection('wc_details', { validator: { x: { $type: 'string' } } });
51-
52-
try {
53-
await collection.insertMany([{ x: /not a string/ }]);
54-
expect.fail('The insert should fail the validation that x must be a string');
55-
} catch (error) {
56-
expect(error).to.be.instanceOf(MongoBulkWriteError);
57-
expect(error).to.have.property('code', 121);
58-
expect(error).to.have.property('writeErrors').that.is.an('array');
59-
expect(error.writeErrors[0]).to.have.property('errInfo').that.is.an('object');
60-
}
61-
}
62-
});
63-
});
64-
});
65-
6623
it('should correctly handle ordered single batch api write command error', {
6724
metadata: {
6825
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const { expect } = require('chai');
2+
const { MongoBulkWriteError } = require('../../../src');
3+
4+
describe('CRUD Prose Spec Tests', () => {
5+
let client;
6+
7+
beforeEach(async function () {
8+
client = this.configuration.newClient({ monitorCommands: true });
9+
await client.connect();
10+
});
11+
12+
afterEach(async () => {
13+
if (client) {
14+
await client.close();
15+
}
16+
});
17+
18+
// Note: This test does not fully implement the described test, it's missing command monitoring assertions
19+
it('2. WriteError.details exposes writeErrors[].errInfo', {
20+
metadata: { requires: { mongodb: '>=5.0.0' } },
21+
async test() {
22+
try {
23+
await client.db().collection('wc_details').drop();
24+
} catch {
25+
// don't care
26+
}
27+
28+
const collection = await client
29+
.db()
30+
.createCollection('wc_details', { validator: { x: { $type: 'string' } } });
31+
32+
try {
33+
await collection.insertMany([{ x: /not a string/ }]);
34+
expect.fail('The insert should fail the validation that x must be a string');
35+
} catch (error) {
36+
expect(error).to.be.instanceOf(MongoBulkWriteError);
37+
expect(error).to.have.property('code', 121);
38+
expect(error).to.have.property('writeErrors').that.is.an('array');
39+
expect(error.writeErrors[0]).to.have.property('errInfo').that.is.an('object');
40+
}
41+
}
42+
});
43+
});

test/functional/crud_spec.test.js renamed to test/integration/crud/crud.spec.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const chai = require('chai');
66
const expect = chai.expect;
77
chai.use(require('chai-subset'));
88

9-
const { loadSpecTests } = require('../spec/index');
10-
const { runUnifiedTest } = require('../tools/unified-spec-runner/runner');
9+
const { loadSpecTests } = require('../../spec/index');
10+
const { runUnifiedTest } = require('../../tools/unified-spec-runner/runner');
1111

1212
function enforceServerVersionLimits(requires, scenario) {
1313
const versionLimits = [];
@@ -26,7 +26,7 @@ function enforceServerVersionLimits(requires, scenario) {
2626
}
2727

2828
function findScenarios() {
29-
const route = [__dirname, '..', 'spec', 'crud'].concat(Array.from(arguments));
29+
const route = [__dirname, '..', '..', 'spec', 'crud'].concat(Array.from(arguments));
3030
return fs
3131
.readdirSync(path.resolve.apply(path, route))
3232
.filter(x => x.indexOf('json') !== -1)

test/functional/crud_api.test.js renamed to test/integration/crud/crud_api.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
2-
const test = require('./shared').assert;
2+
const { assert: test, setupDatabase } = require('../shared');
33
const { expect } = require('chai');
4-
const { ReturnDocument, ObjectId } = require('../../src');
5-
const setupDatabase = require('./shared').setupDatabase;
4+
const { ReturnDocument, ObjectId } = require('../../../src');
65

76
// instanceof cannot be use reliably to detect the new models in js due to scoping and new
87
// contexts killing class info find/distinct/count thus cannot be overloaded without breaking

test/functional/load-balancer-spec.test.js renamed to test/integration/load-balancers/load_balancers.spec.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
const path = require('path');
3-
const { loadSpecTests } = require('../spec/index');
4-
const { runUnifiedSuite } = require('../tools/unified-spec-runner/runner');
3+
const { loadSpecTests } = require('../../spec/index');
4+
const { runUnifiedSuite } = require('../../tools/unified-spec-runner/runner');
55

66
const SKIP = [
77
// Verified they use the same connection but the Node implementation executes

test/functional/max_staleness.test.js renamed to test/integration/max-staleness/max_staleness.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
'use strict';
22
const { Long } = require('bson');
33
const { expect } = require('chai');
4-
const mock = require('../tools/mock');
5-
const { ReadPreference } = require('../../src');
4+
const mock = require('../../tools/mock');
5+
const { ReadPreference } = require('../../../src');
66

77
const test = {};
8+
// TODO (NODE-3799): convert these to run against a real server
89
describe('Max Staleness', function () {
910
afterEach(() => mock.cleanup());
1011
beforeEach(() => {

test/functional/retryable_reads.test.js renamed to test/integration/retryable-reads/retryable_reads.spec.test.js

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

3-
const TestRunnerContext = require('./spec-runner').TestRunnerContext;
4-
const generateTopologyTests = require('./spec-runner').generateTopologyTests;
5-
const loadSpecTests = require('../spec').loadSpecTests;
3+
const { TestRunnerContext, generateTopologyTests } = require('../../tools/spec-runner');
4+
const { loadSpecTests } = require('../../spec');
65

76
describe('Retryable Reads', function () {
87
const testContext = new TestRunnerContext();

test/functional/retryable_writes.test.js renamed to test/integration/retryable-writes/retryable_writes.spec.test.js

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

3-
const expect = require('chai').expect;
4-
const loadSpecTests = require('../spec').loadSpecTests;
5-
const parseRunOn = require('../functional/spec-runner').parseRunOn;
3+
const { expect } = require('chai');
4+
const { loadSpecTests } = require('../../spec');
5+
const { parseRunOn } = require('../../tools/spec-runner');
66

77
describe('Retryable Writes', function () {
88
let ctx = {};

test/functional/versioned-api.test.js renamed to test/integration/versioned-api/versioned_api.spec.test.js

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

33
const { expect } = require('chai');
4-
const { loadSpecTests } = require('../spec/index');
5-
const { runUnifiedTest } = require('../tools/unified-spec-runner/runner');
4+
const { loadSpecTests } = require('../../spec/');
5+
const { runUnifiedTest } = require('../../tools/unified-spec-runner/runner');
66

77
describe('Versioned API', function () {
88
it('should throw an error if serverApi version is provided via the uri', {

0 commit comments

Comments
 (0)