Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1dc1050
test(NODE-7160): migrate `node-mongodb-native/test/unit/assorted` tests
PavelSafronov Sep 18, 2025
7c118db
Merge branch 'main' into NODE-7160
PavelSafronov Sep 18, 2025
bbdb366
Update test/unit/assorted/max_staleness.spec.test.js
PavelSafronov Sep 18, 2025
16f5dc5
fix: pr feedback
PavelSafronov Sep 18, 2025
84151b4
Merge branch 'NODE-7160' of https://github.com/PavelSafronov/node-mon…
PavelSafronov Sep 18, 2025
70a4f27
Merge branch 'main' into NODE-7160
PavelSafronov Sep 18, 2025
88b54e3
fix: js files should not be using import
PavelSafronov Sep 19, 2025
f66787c
Merge branch 'NODE-7160' of https://github.com/PavelSafronov/node-mon…
PavelSafronov Sep 19, 2025
be1fb8e
fix: for shared library test, continue to reference `lib`, not `src`.
PavelSafronov Sep 19, 2025
9051b92
starting work on updating all of unit tests
PavelSafronov Sep 19, 2025
493b32d
more migrated tests
PavelSafronov Sep 19, 2025
ba0b5df
more migrations
PavelSafronov Sep 19, 2025
dc82c35
more migrations
PavelSafronov Sep 19, 2025
44d9232
more migrations
PavelSafronov Sep 19, 2025
c68bdcb
more migrations
PavelSafronov Sep 19, 2025
abfb10e
last import fix
PavelSafronov Sep 22, 2025
ac4c380
fixed imports
PavelSafronov Sep 22, 2025
1f9b43b
removing `done` from some tests
PavelSafronov Sep 22, 2025
0a910b8
more migrations
PavelSafronov Sep 23, 2025
8d6bb36
more migrations
PavelSafronov Sep 23, 2025
7d8b94c
Merge branch 'mongodb:main' into NODE-7169
PavelSafronov Sep 23, 2025
6ebbaca
lint autofixes
PavelSafronov Sep 23, 2025
660ebb2
Merge branch 'mongodb:main' into NODE-7169
PavelSafronov Sep 24, 2025
516686b
update imports
PavelSafronov Sep 24, 2025
ffcc8d5
fix: pr feedback
PavelSafronov Sep 24, 2025
7d7055f
fix: lint
PavelSafronov Sep 24, 2025
01226ef
fix: lint and missing import
PavelSafronov Sep 24, 2025
0f11c1f
fix: pr feedback
PavelSafronov Sep 24, 2025
4f9184c
Merge branch 'mongodb:main' into NODE-7169
PavelSafronov Sep 25, 2025
afe4c9e
reverting unnecessary changes outside of unit tests
PavelSafronov Sep 25, 2025
91028b7
pr feedback
PavelSafronov Sep 25, 2025
cfa75a6
linter fix
PavelSafronov Sep 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/action/dependency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as path from 'node:path';
import { expect } from 'chai';

import { dependencies, peerDependencies, peerDependenciesMeta } from '../../package.json';
import { setDifference } from '../mongodb';
import { setDifference } from '../../src/utils';
import { alphabetically, itInNodeProcess, sorted } from '../tools/utils';

const EXPECTED_DEPENDENCIES = sorted(
Expand Down
5 changes: 4 additions & 1 deletion test/integration/auth/auth.prose.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { expect } from 'chai';
import * as sinon from 'sinon';

import { Connection, LEGACY_HELLO_COMMAND, type MongoClient, ScramSHA256 } from '../../mongodb';
import { ScramSHA256 } from '../../../src/cmap/auth/scram';
import { Connection } from '../../../src/cmap/connection';
import { LEGACY_HELLO_COMMAND } from '../../../src/constants';
import { type MongoClient } from '../../../src/mongo_client';
import { type TestConfiguration } from '../../tools/runner/config';

function makeConnectionString(config, username, password) {
Expand Down
22 changes: 7 additions & 15 deletions test/integration/auth/mongodb_aws.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
import * as process from 'node:process';

import { type Document } from 'bson';
import { expect } from 'chai';
import * as http from 'http';
import { performance } from 'perf_hooks';
import * as sinon from 'sinon';

import { refreshKMSCredentials } from '../../../src/client-side-encryption/providers';
import {
AWSSDKCredentialProvider,
type CommandOptions,
Connection,
type Document,
MongoAWSError,
type MongoClient,
MongoDBAWS,
type MongoDBNamespace,
type MongoDBResponseConstructor,
MongoMissingCredentialsError,
MongoMissingDependencyError,
MongoServerError,
setDifference
} from '../../mongodb';
import { AWSSDKCredentialProvider } from '../../../src/cmap/auth/aws_temporary_credentials';
import { type CommandOptions, Connection } from '../../../src/cmap/connection';
import { type MongoDBResponseConstructor } from '../../../src/cmap/wire_protocol/responses';
import { MongoAWSError, MongoMissingDependencyError, MongoServerError } from '../../../src/error';
import { type MongoClient } from '../../../src/mongo_client';
import { type MongoDBNamespace } from '../../../src/utils';

const isMongoDBAWSAuthEnvironment = (process.env.MONGODB_URI ?? '').includes('MONGODB-AWS');

Expand Down
2 changes: 1 addition & 1 deletion test/integration/enumerate_databases.prose.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';

import type { MongoClient } from '../mongodb';
import { type MongoClient } from '../../src/mongo_client';

const REQUIRED_DBS = ['admin', 'local', 'config'];
const DB_NAME = 'listDatabasesTest';
Expand Down
3 changes: 2 additions & 1 deletion test/integration/enumerate_databases.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { expect } from 'chai';
import { once } from 'events';

import { type MongoClient, MongoServerError } from '../mongodb';
import { MongoServerError } from '../../src/error';
import { type MongoClient } from '../../src/mongo_client';
import { TestBuilder, UnifiedTestSuiteBuilder } from '../tools/unified_suite_builder';

const metadata: MongoDBMetadataUI = {
Expand Down
12 changes: 6 additions & 6 deletions test/integration/index_management.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect } from 'chai';

import {
type Collection,
type CommandStartedEvent,
type CommandSucceededEvent,
type Db,
type MongoClient,
MongoServerError
} from '../mongodb';
type CommandSucceededEvent
} from '../../src/cmap/command_monitoring_events';
import { type Collection } from '../../src/collection';
import { type Db } from '../../src/db';
import { MongoServerError } from '../../src/error';
import { type MongoClient } from '../../src/mongo_client';
import { type FailCommandFailPoint } from '../tools/utils';
import { assert as test, filterForCommands, setupDatabase } from './shared';

Expand Down
2 changes: 1 addition & 1 deletion test/tools/mongodb-mock/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
const { MockServer } = require('./src/server.js');
const { LEGACY_HELLO_COMMAND } = require('../../mongodb');
const { LEGACY_HELLO_COMMAND } = require('../../../src/constants.ts');

let mockServers = [];

Expand Down
18 changes: 6 additions & 12 deletions test/tools/runner/config.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import * as util from 'node:util';
import * as types from 'node:util/types';

import { Double, Long, ObjectId } from 'bson';
import { expect } from 'chai';
import { type Context } from 'mocha';
import ConnectionString from 'mongodb-connection-string-url';
import { type CompressorName } from 'mongodb-legacy';
import * as qs from 'querystring';
import * as url from 'url';

import {
type AuthMechanism,
Double,
HostAddress,
Long,
MongoClient,
type MongoClientOptions,
ObjectId,
type ServerApi,
TopologyType,
type WriteConcernSettings
} from '../../mongodb';
import { type AuthMechanism } from '../../../src/cmap/auth/providers';
import { MongoClient, type MongoClientOptions, type ServerApi } from '../../../src/mongo_client';
import { TopologyType } from '../../../src/sdam/common';
import { HostAddress } from '../../../src/utils';
import { type WriteConcernSettings } from '../../../src/write_concern';
import { getEnvironmentalOptions } from '../utils';
import { type Filter } from './filters/filter';
import { flakyTests } from './flaky';
Expand Down
2 changes: 1 addition & 1 deletion test/tools/runner/filters/filter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type MongoClient } from '../../../mongodb';
import { type MongoClient } from '../../../../src/mongo_client';

export abstract class Filter {
async initializeFilter(_client: MongoClient, _context: Record<string, any>): Promise<void> {
Expand Down
18 changes: 6 additions & 12 deletions test/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@ import { on, once } from 'node:events';
import * as fs from 'node:fs/promises';
import * as path from 'node:path';

import { EJSON } from 'bson';
import { type Document, EJSON } from 'bson';
import * as BSON from 'bson';
import { expect } from 'chai';
import { Readable } from 'stream';
import { setTimeout } from 'timers';
import { inspect, promisify } from 'util';

import {
type AnyClientBulkWriteModel,
type Document,
type HostAddress,
MongoClient,
type MongoClientOptions,
now,
OP_MSG,
Topology,
type TopologyOptions
} from '../mongodb';
import { OP_MSG } from '../../src/cmap/wire_protocol/constants';
import { MongoClient, type MongoClientOptions } from '../../src/mongo_client';
import { type AnyClientBulkWriteModel } from '../../src/operations/client_bulk_write/common';
import { Topology, type TopologyOptions } from '../../src/sdam/topology';
import { type HostAddress, now } from '../../src/utils';
import { type TestConfiguration } from './runner/config';

export function ensureCalledWith(stub: any, args: any[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,9 @@ describe('Polling Srv Records for Mongos Discovery', () => {
return mock.cleanup();
});

afterEach(function (done) {
afterEach(function () {
if (context.topology) {
context.topology.close();
done();
} else {
done();
}
});

Expand Down
3 changes: 1 addition & 2 deletions test/unit/bson.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BSON } from 'bson';
import { expect } from 'chai';

import { BSON } from '../mongodb';

describe('When importing BSON', function () {
const types = [
['Long', 23],
Expand Down
4 changes: 3 additions & 1 deletion test/unit/change_stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { Long, Timestamp } from 'bson';
import { expect } from 'chai';
import * as sinon from 'sinon';

import { ChangeStreamCursor, MongoClient, MongoDBNamespace } from '../mongodb';
import { ChangeStreamCursor } from '../../src/cursor/change_stream_cursor';
import { MongoClient } from '../../src/mongo_client';
import { MongoDBNamespace } from '../../src/utils';

describe('ChangeStreamCursor', function () {
afterEach(function () {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/client-side-encryption/auto_encrypter.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { BSON } from 'bson';
import { expect } from 'chai';
import * as fs from 'fs';
import * as net from 'net';
import * as sinon from 'sinon';

import { AutoEncrypter } from '../../../src/client-side-encryption/auto_encrypter';
import { type DataKey } from '../../../src/client-side-encryption/client_encryption';
import { MongocryptdManager } from '../../../src/client-side-encryption/mongocryptd_manager';
import { StateMachine } from '../../../src/client-side-encryption/state_machine';
import { MongoClient } from '../../../src/mongo_client';
import { BSON, type DataKey } from '../../mongodb';
import * as requirements from './requirements.helper';

const bson = BSON;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Binary, BSON, deserialize } from 'bson';
import { expect } from 'chai';
import * as fs from 'fs';
import { resolve } from 'path';
Expand All @@ -10,7 +11,7 @@ import {
MongoCryptCreateEncryptedCollectionError
} from '../../../src/client-side-encryption/errors';
import { StateMachine } from '../../../src/client-side-encryption/state_machine';
import { Binary, BSON, deserialize, MongoClient } from '../../mongodb';
import { MongoClient } from '../../../src/mongo_client';

const { EJSON } = BSON;

Expand Down
2 changes: 1 addition & 1 deletion test/unit/client-side-encryption/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
MongoCryptError,
MongoCryptInvalidArgumentError
} from '../../../src/client-side-encryption/errors';
import { MongoError } from '../../mongodb';
import { MongoError } from '../../../src/error';

describe('MongoCryptError', function () {
const errors = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
tokenCache
} from '../../../../src/client-side-encryption/providers/azure';
import { AWSSDKCredentialProvider } from '../../../../src/cmap/auth/aws_temporary_credentials';
import { MongoNetworkTimeoutError } from '../../../../src/error';
import * as utils from '../../../../src/utils';
import { MongoNetworkTimeoutError } from '../../../mongodb';
import * as requirements from '../requirements.helper';

const originalAccessKeyId = process.env.AWS_ACCESS_KEY_ID;
Expand Down
63 changes: 29 additions & 34 deletions test/unit/client-side-encryption/state_machine.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import { BSON, Int32, Long, serialize } from 'bson';
import { expect } from 'chai';
import { EventEmitter, once } from 'events';
import * as fs from 'fs/promises';
import { type MongoCryptKMSRequest } from 'mongodb-client-encryption';
import * as net from 'net';
import * as sinon from 'sinon';
import { setTimeout } from 'timers';
import { setTimeout as setTimeoutAsync } from 'timers/promises';
import * as tls from 'tls';

import { StateMachine } from '../../../src/client-side-encryption/state_machine';
import { Collection } from '../../../src/collection';
import { CursorTimeoutContext } from '../../../src/cursor/abstract_cursor';
import { Db } from '../../../src/db';
import {
BSON,
Collection,
CSOTTimeoutContext,
CursorTimeoutContext,
type FindOptions,
Int32,
Long,
MongoClient,
serialize,
squashError
} from '../../mongodb';
import { MongoClient } from '../../../src/mongo_client';
import { type FindOptions } from '../../../src/operations/find';
import { CSOTTimeoutContext } from '../../../src/timeout';
import { squashError } from '../../../src/utils';
import { sleep } from '../../tools/utils';

describe('StateMachine', function () {
Expand Down Expand Up @@ -129,7 +123,7 @@ describe('StateMachine', function () {
});
});

it('should only resolve once bytesNeeded drops to zero', function (done) {
it('should only resolve once bytesNeeded drops to zero', async function () {
const stateMachine = new StateMachine({} as any);
const request = new MockRequest(Buffer.from('foobar'), 500);
let status = 'pending';
Expand All @@ -143,22 +137,21 @@ describe('StateMachine', function () {
.catch(() => {});

this.fakeSocket.emit('connect');
setTimeout(() => {
expect(status).to.equal('pending');
expect(request.bytesNeeded).to.equal(500);
expect(request.kmsProvider).to.equal('aws');
this.fakeSocket.emit('data', Buffer.alloc(300));
setTimeout(() => {
expect(status).to.equal('pending');
expect(request.bytesNeeded).to.equal(200);
this.fakeSocket.emit('data', Buffer.alloc(200));
setTimeout(() => {
expect(status).to.equal('resolved');
expect(request.bytesNeeded).to.equal(0);
done();
});
});
});
await sleep();

expect(status).to.equal('pending');
expect(request.bytesNeeded).to.equal(500);
expect(request.kmsProvider).to.equal('aws');
this.fakeSocket.emit('data', Buffer.alloc(300));
await sleep();

expect(status).to.equal('pending');
expect(request.bytesNeeded).to.equal(200);
this.fakeSocket.emit('data', Buffer.alloc(200));
await sleep();

expect(status).to.equal('resolved');
expect(request.bytesNeeded).to.equal(0);
});
});

Expand Down Expand Up @@ -196,13 +189,15 @@ describe('StateMachine', function () {
} as any);
const request = new MockRequest(Buffer.from('foobar'), 500);

it('rejects with the validation error', function (done) {
stateMachine.kmsRequest(request).catch(err => {
it('rejects with the validation error', async function () {
try {
await stateMachine.kmsRequest(request);
expect.fail('should have failed with validation error');
} catch (err) {
expect(err.message).to.equal(
`Insecure TLS options prohibited for aws: ${option}`
);
done();
});
}
});
});
}
Expand Down
3 changes: 2 additions & 1 deletion test/unit/cmap/auth/auth_provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from 'chai';

import { type AuthContext, AuthProvider, MongoRuntimeError } from '../../../mongodb';
import { type AuthContext, AuthProvider } from '../../../../src/cmap/auth/auth_provider';
import { MongoRuntimeError } from '../../../../src/error';

describe('AuthProvider', function () {
describe('#reauth', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cmap/auth/gssapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
GSSAPICanonicalizationValue,
performGSSAPICanonicalizeHostName,
resolveCname
} from '../../../mongodb';
} from '../../../../src/cmap/auth/gssapi';

describe('GSSAPI', () => {
let lookupSpy;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { expect } from 'chai';
import * as sinon from 'sinon';

import { MongoCredentials } from '../../../../../src/cmap/auth/mongo_credentials';
import { AutomatedCallbackWorkflow } from '../../../../../src/cmap/auth/mongodb_oidc/automated_callback_workflow';
import { CallbackWorkflow } from '../../../../../src/cmap/auth/mongodb_oidc/callback_workflow';
import { callback } from '../../../../../src/cmap/auth/mongodb_oidc/gcp_machine_workflow';
import { TokenCache } from '../../../../../src/cmap/auth/mongodb_oidc/token_cache';
import {
AutomatedCallbackWorkflow,
CallbackWorkflow,
Connection,
MongoCredentials
} from '../../../../mongodb';
import { Connection } from '../../../../../src/cmap/connection';

describe('AutomatedCallbackWorkflow', function () {
describe('#execute', function () {
Expand Down
Loading