Skip to content

Commit 78a55e2

Browse files
authored
test(NODE-4264): part 1 of removing connect from tests (#3257)
1 parent fe7c102 commit 78a55e2

Some content is hidden

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

50 files changed

+5392
-6864
lines changed

global.d.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import { OneOrMore } from './src/mongo_types';
22
import type { TestConfiguration } from './test/tools/runner/config';
33

4-
type WithExclusion<T extends string> = `!${T}`;
5-
/** Defined in test/tools/runner/filters/mongodb_topology_filter.js (topologyTypeToString) */
6-
type TopologyTypes = 'single' | 'replicaset' | 'sharded' | 'load-balanced';
7-
type TopologyTypeRequirement = OneOrMore<TopologyTypes> | OneOrMore<WithExclusion<TopologyTypes>>;
8-
94
declare global {
105
interface MongoDBMetadataUI {
116
requires?: {
127
topology?: TopologyTypeRequirement;
138
mongodb?: string;
149
os?: NodeJS.Platform | `!${NodeJS.Platform}`;
15-
apiVersion?: '1';
10+
apiVersion?: '1' | boolean;
1611
clientSideEncryption?: boolean;
1712
serverless?: 'forbid' | 'allow' | 'require';
1813
auth?: 'enabled' | 'disabled';
@@ -23,6 +18,11 @@ declare global {
2318
};
2419
}
2520

21+
type WithExclusion<T extends string> = `!${T}`;
22+
/** Defined in test/tools/runner/filters/mongodb_topology_filter.js (topologyTypeToString) */
23+
type TopologyTypes = 'single' | 'replicaset' | 'sharded' | 'load-balanced';
24+
type TopologyTypeRequirement = OneOrMore<TopologyTypes> | OneOrMore<WithExclusion<TopologyTypes>>;
25+
2626
interface MetadataAndTest<Fn> {
2727
metadata: MongoDBMetadataUI;
2828
test: Fn;

test/integration/auth/auth.prose.test.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ const sinon = require('sinon');
44
const { expect } = require('chai');
55
const { Connection } = require('../../../src/cmap/connection');
66
const { ScramSHA256 } = require('../../../src/cmap/auth/scram');
7-
const { setupDatabase, withClient } = require('../shared');
7+
const { setupDatabase } = require('../shared');
88
const { LEGACY_HELLO_COMMAND } = require('../../../src/constants');
99

10+
// TODO(NODE-4338): withClient usage prevented these tests from running
11+
// the import has been removed since the function is being deleted, this is here to keep modifications minimal
12+
// so that the implementer of the fix for these tests can try to reference the original intent
13+
const withClient = () => null;
14+
1015
describe('auth prose tests', () => {
16+
beforeEach(function () {
17+
this.currentTest.skipReason = 'TODO(NODE-4338): correct withClient usage';
18+
this.currentTest.skip();
19+
});
20+
1121
describe('SCRAM-SHA-256 prose test', () => {
1222
describe('SCRAM-SHA-256 prose test Steps 1-3', function () {
1323
const test = {};

test/integration/auth/mongodb_aws.test.js

+20-29
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,28 @@ describe('MONGODB-AWS', function () {
1515
}
1616
});
1717

18-
it('should not authorize when not authenticated', function (done) {
19-
const config = this.configuration;
20-
const url = removeAuthFromConnectionString(config.url());
21-
const client = config.newClient(url); // strip provided URI of credentials
22-
client.connect(err => {
23-
expect(err).to.not.exist;
24-
this.defer(() => client.close());
18+
it('should not authorize when not authenticated', async function () {
19+
const url = removeAuthFromConnectionString(this.configuration.url());
20+
const client = this.configuration.newClient(url); // strip provided URI of credentials
2521

26-
client.db('aws').command({ count: 'test' }, (err, count) => {
27-
expect(err).to.exist;
28-
expect(count).to.not.exist;
22+
const error = await client
23+
.db('aws')
24+
.command({ ping: 1 })
25+
.catch(error => error);
2926

30-
done();
31-
});
32-
});
27+
expect(error).to.be.instanceOf(MongoAWSError);
3328
});
3429

35-
it('should authorize when successfully authenticated', function (done) {
36-
const config = this.configuration;
37-
const client = config.newClient(process.env.MONGODB_URI); // use the URI built by the test environment
38-
client.connect(err => {
39-
expect(err).to.not.exist;
40-
this.defer(() => client.close());
30+
it('should authorize when successfully authenticated', async function () {
31+
const client = this.configuration.newClient(process.env.MONGODB_URI); // use the URI built by the test environment
4132

42-
client.db('aws').command({ count: 'test' }, (err, count) => {
43-
expect(err).to.not.exist;
44-
expect(count).to.exist;
33+
const result = await client
34+
.db('aws')
35+
.command({ ping: 1 })
36+
.catch(error => error);
4537

46-
done();
47-
});
48-
});
38+
expect(result).to.not.be.instanceOf(MongoAWSError);
39+
expect(result).to.have.property('ok', 1);
4940
});
5041

5142
it('should allow empty string in authMechanismProperties.AWS_SESSION_TOKEN to override AWS_SESSION_TOKEN environment variable', function () {
@@ -84,10 +75,10 @@ describe('MONGODB-AWS', function () {
8475
client = config.newClient(process.env.MONGODB_URI, { authMechanism: 'MONGODB-AWS' }); // use the URI built by the test environment
8576
const startTime = performance.now();
8677

87-
let caughtError = null;
88-
await client.connect().catch(err => {
89-
caughtError = err;
90-
});
78+
const caughtError = await client
79+
.db()
80+
.command({ ping: 1 })
81+
.catch(error => error);
9182

9283
const endTime = performance.now();
9384
const timeTaken = endTime - startTime;

test/integration/auth/scram_sha_1.test.js

-76
This file was deleted.
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { expect } from 'chai';
2+
3+
import type { MongoClient } from '../../../src';
4+
5+
describe('SCRAM-SHA-1', function () {
6+
let client: MongoClient;
7+
8+
beforeEach(async function () {
9+
const onlyScram1AuthMech =
10+
this.configuration.parameters?.authenticationMechanisms.length === 1 &&
11+
this.configuration.parameters?.authenticationMechanisms[0] === 'SCRAM-SHA-1';
12+
13+
if (!onlyScram1AuthMech) {
14+
this.currentTest.skipReason = `MongoDB auth mechanism must only be SCRAM-SHA-1, got ${this.configuration.parameters?.authenticationMechanisms}`;
15+
return this.skip();
16+
}
17+
18+
client = this.configuration.newClient();
19+
});
20+
21+
afterEach(async () => {
22+
await client?.close();
23+
});
24+
25+
it('successfuly authenticates', async () => {
26+
const result = await client.db().admin().command({ ping: 1 });
27+
expect(result).to.have.property('ok', 1);
28+
});
29+
});

test/integration/auth/scram_sha_256.test.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ const sinon = require('sinon');
44
const { expect } = require('chai');
55
const { Connection } = require('../../../src/cmap/connection');
66
const { ScramSHA256 } = require('../../../src/cmap/auth/scram');
7-
const { setupDatabase, withClient } = require('../shared');
7+
const { setupDatabase } = require('../shared');
88
const { LEGACY_HELLO_COMMAND } = require('../../../src/constants');
99

10+
// TODO(NODE-4338): withClient usage prevented these tests from running
11+
// the import has been removed since the function is being deleted, this is here to keep modifications minimal
12+
// so that the implementer of the fix for these tests can try to reference the original intent
13+
const withClient = () => null;
14+
1015
describe('SCRAM_SHA_256', function () {
16+
beforeEach(function () {
17+
this.currentTest.skipReason = 'TODO(NODE-4338): correct withClient usage';
18+
this.currentTest.skip();
19+
});
20+
1121
const test = {};
1222

1323
// Note: this setup was adapted from the prose test setup

test/integration/bson-decimal128/decimal128.test.js

+21-34
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,30 @@ describe('Decimal128', function () {
99
return setupDatabase(this.configuration);
1010
});
1111

12-
it('should correctly insert decimal128 value', {
13-
// Add a tag that our runner can trigger on
14-
// in this case we are setting that node needs to be higher than 0.10.X to run
15-
metadata: {
16-
requires: {
17-
mongodb: '>=3.3.6',
18-
topology: ['single']
19-
}
20-
},
12+
it('should correctly insert decimal128 value', function (done) {
13+
var configuration = this.configuration;
14+
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
15+
var db = client.db(configuration.db);
16+
var object = {
17+
id: 1,
18+
value: Decimal128.fromString('1.28')
19+
};
2120

22-
test: function (done) {
23-
var configuration = this.configuration;
24-
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
25-
client.connect(function (err, client) {
26-
var db = client.db(configuration.db);
27-
var object = {
28-
id: 1,
29-
value: Decimal128.fromString('1')
30-
};
21+
db.collection('decimal128').insertOne(object, function (err) {
22+
expect(err).to.not.exist;
3123

32-
db.collection('decimal128').insertOne(object, function (err) {
24+
db.collection('decimal128').findOne(
25+
{
26+
id: 1
27+
},
28+
function (err, doc) {
3329
expect(err).to.not.exist;
30+
test.ok(doc.value instanceof Decimal128);
31+
test.equal('1.28', doc.value.toString());
3432

35-
db.collection('decimal128').findOne(
36-
{
37-
id: 1
38-
},
39-
function (err, doc) {
40-
expect(err).to.not.exist;
41-
test.ok(doc.value instanceof Decimal128);
42-
test.equal('1', doc.value.toString());
43-
44-
client.close(done);
45-
}
46-
);
47-
});
48-
});
49-
}
33+
client.close(done);
34+
}
35+
);
36+
});
5037
});
5138
});

test/integration/causal-consistency/causal_consistency.prose.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ describe('Causal Consistency - prose tests', function () {
3737
test.client.on('commandSucceeded', event => {
3838
if (ignoredCommands.indexOf(event.commandName) === -1) test.commands.succeeded.push(event);
3939
});
40-
41-
return test.client.connect();
4240
});
4341

4442
afterEach(() => {

test/integration/change-streams/change_stream.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ describe('Change Streams', function () {
7777
context('ChangeStreamCursor options', function () {
7878
let client, db, collection;
7979

80-
beforeEach(async function () {
81-
client = await this.configuration.newClient().connect();
80+
beforeEach(function () {
81+
client = this.configuration.newClient();
8282
db = client.db('db');
8383
collection = db.collection('collection');
8484
});

0 commit comments

Comments
 (0)