Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
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: 26 additions & 37 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,9 @@ 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 => {
expect(err.message).to.equal(
`Insecure TLS options prohibited for aws: ${option}`
);
done();
});
it('rejects with the validation error', async function () {
const err = await stateMachine.kmsRequest(request).catch(e => e);
expect(err.message).to.equal(`Insecure TLS options prohibited for aws: ${option}`);
});
});
}
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';

import { OIDC_VERSION, type OIDCCallbackParams } from '../../../../../src/cmap/auth/mongodb_oidc';
import { callback } from '../../../../../src/cmap/auth/mongodb_oidc/azure_machine_workflow';
import { OIDC_VERSION, type OIDCCallbackParams } from '../../../../mongodb';

describe('Azure machine workflow', function () {
describe('#callback', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';

import { OIDC_VERSION, type OIDCCallbackParams } from '../../../../../src/cmap/auth/mongodb_oidc';
import { callback } from '../../../../../src/cmap/auth/mongodb_oidc/gcp_machine_workflow';
import { OIDC_VERSION, type OIDCCallbackParams } from '../../../../mongodb';

describe('GCP machine workflow', function () {
describe('#callback', function () {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/cmap/command_monitoring_events.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { OpQueryRequest, OpMsgRequest } = require('../../mongodb');
const { CommandStartedEvent } = require('../../mongodb');
const { OpQueryRequest, OpMsgRequest } = require('../../../src/cmap/commands');
const { CommandStartedEvent } = require('../../../src/cmap/command_monitoring_events');
const { expect } = require('chai');

describe('Command Monitoring Events - unit/cmap', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cmap/commands.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as BSON from 'bson';
import { expect } from 'chai';

import { DocumentSequence, OpMsgRequest, OpReply } from '../../mongodb';
import { DocumentSequence, OpMsgRequest, OpReply } from '../../../src/cmap/commands';

describe('commands', function () {
describe('OpMsgRequest', function () {
Expand Down
24 changes: 11 additions & 13 deletions test/unit/cmap/connect.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { type Document } from 'bson';
import { expect } from 'chai';

import { MongoCredentials } from '../../../src/cmap/auth/mongo_credentials';
import { connect, prepareHandshakeDocument } from '../../../src/cmap/connect';
import { type Connection, type ConnectionOptions } from '../../../src/cmap/connection';
import {
addContainerMetadata,
CancellationToken,
type ClientMetadata,
connect,
type Connection,
type ConnectionOptions,
HostAddress,
isHello,
LEGACY_HELLO_COMMAND,
MongoClientAuthProviders,
MongoCredentials,
MongoNetworkError,
prepareHandshakeDocument
} from '../../mongodb';
type ClientMetadata
} from '../../../src/cmap/handshake/client_metadata';
import { LEGACY_HELLO_COMMAND } from '../../../src/constants';
import { MongoNetworkError } from '../../../src/error';
import { MongoClientAuthProviders } from '../../../src/mongo_client_auth_providers';
import { CancellationToken } from '../../../src/mongo_types';
import { HostAddress, isHello } from '../../../src/utils';
import { genClusterTime } from '../../tools/common';
import * as mock from '../../tools/mongodb-mock/index';

Expand Down
17 changes: 5 additions & 12 deletions test/unit/cmap/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@ import { expect } from 'chai';
import * as sinon from 'sinon';
import { setTimeout } from 'timers/promises';

import {
connect,
Connection,
isHello,
MongoClientAuthProviders,
MongoDBCollectionNamespace,
MongoNetworkTimeoutError,
MongoRuntimeError,
ns,
promiseWithResolvers,
SizedMessageTransform
} from '../../mongodb';
import { connect } from '../../../src/cmap/connect';
import { Connection, SizedMessageTransform } from '../../../src/cmap/connection';
import { MongoNetworkTimeoutError, MongoRuntimeError } from '../../../src/error';
import { MongoClientAuthProviders } from '../../../src/mongo_client_auth_providers';
import { isHello, MongoDBCollectionNamespace, ns, promiseWithResolvers } from '../../../src/utils';
import * as mock from '../../tools/mongodb-mock/index';

const connectionOptionsDefaults = {
Expand Down
12 changes: 7 additions & 5 deletions test/unit/cmap/connection_pool.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
'use strict';

const { ConnectionPool, MongoError } = require('../../mongodb');
const { WaitQueueTimeoutError } = require('../../mongodb');
const { ConnectionPool } = require('../../../src/cmap/connection_pool');
const { MongoError } = require('../../../src/error');
const { WaitQueueTimeoutError } = require('../../../src/cmap/errors');
const mock = require('../../tools/mongodb-mock/index');
const sinon = require('sinon');
const { expect } = require('chai');
const { setImmediate } = require('timers/promises');
const { ns, isHello } = require('../../mongodb');
const { isHello } = require('../../../src/utils');
const { ns } = require('../../../src/utils');
const { createTimerSandbox } = require('../timer_sandbox');
const { topologyWithPlaceholderClient } = require('../../tools/utils');
const { MongoClientAuthProviders } = require('../../mongodb');
const { TimeoutContext } = require('../../mongodb');
const { MongoClientAuthProviders } = require('../../../src/mongo_client_auth_providers');
const { TimeoutContext } = require('../../../src/timeout');

describe('Connection Pool', function () {
let timeoutContext;
Expand Down
3 changes: 2 additions & 1 deletion test/unit/cmap/connection_pool_events.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from 'chai';

import { type ConnectionPool, ConnectionPoolCreatedEvent } from '../../mongodb';
import { type ConnectionPool } from '../../../src/cmap/connection_pool';
import { ConnectionPoolCreatedEvent } from '../../../src/cmap/connection_pool_events';

describe('Connection Pool Events', function () {
const connectionPoolMock = {
Expand Down
9 changes: 4 additions & 5 deletions test/unit/cmap/handshake/client_metadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Int32, ObjectId } from 'bson';
import { expect } from 'chai';
import * as os from 'os';
import * as process from 'process';
Expand All @@ -7,12 +8,10 @@ import { inspect } from 'util';
import { version as NODE_DRIVER_VERSION } from '../../../../package.json';
import {
getFAASEnv,
Int32,
LimitedSizeDocument,
makeClientMetadata,
MongoInvalidArgumentError,
ObjectId
} from '../../../mongodb';
makeClientMetadata
} from '../../../../src/cmap/handshake/client_metadata';
import { MongoInvalidArgumentError } from '../../../../src/error';

describe('client metadata module', () => {
afterEach(() => sinon.restore());
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cmap/metrics.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { expect } = require('chai');
const { ConnectionPoolMetrics } = require('../../mongodb');
const { ConnectionPoolMetrics } = require('../../../src/cmap/metrics');

describe('ConnectionPoolMetrics', function () {
describe('#constructor', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cmap/stream_description.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { Double, Long } = require('bson');
const { StreamDescription } = require('../../mongodb');
const { StreamDescription } = require('../../../src/cmap/stream_description');
const { expect } = require('chai');

describe('StreamDescription - unit/cmap', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cmap/wire_protocol/compression.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as zstd from '@mongodb-js/zstd';
import { expect } from 'chai';

import { compress, Compressor, decompress } from '../../../mongodb';
import { compress, Compressor, decompress } from '../../../../src/cmap/wire_protocol/compression';

describe('compression', function () {
describe('.compress()', function () {
Expand Down
Loading