Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6986355

Browse files
PavelSafronovbaileympearson
andauthored
test(NODE-7169): Migrate node-mongodb-native/test/unit tests (#4676)
Co-authored-by: Bailey Pearson <bailey.pearson@gmail.com>
1 parent a576b7d commit 6986355

File tree

61 files changed

+362
-488
lines changed

Some content is hidden

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

61 files changed

+362
-488
lines changed

‎test/unit/assorted/polling_srv_records_for_mongos_discovery.prose.test.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,9 @@ describe('Polling Srv Records for Mongos Discovery', () => {
9898
return mock.cleanup();
9999
});
100100

101-
afterEach(function (done) {
101+
afterEach(function () {
102102
if (context.topology) {
103103
context.topology.close();
104-
done();
105-
} else {
106-
done();
107104
}
108105
});
109106

‎test/unit/bson.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import { BSON } from 'bson';
12
import { expect } from 'chai';
23

3-
import { BSON } from '../mongodb';
4-
54
describe('When importing BSON', function () {
65
const types = [
76
['Long', 23],

‎test/unit/change_stream.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { Long, Timestamp } from 'bson';
22
import { expect } from 'chai';
33
import * as sinon from 'sinon';
44

5-
import { ChangeStreamCursor, MongoClient, MongoDBNamespace } from '../mongodb';
5+
import { ChangeStreamCursor } from '../../src/cursor/change_stream_cursor';
6+
import { MongoClient } from '../../src/mongo_client';
7+
import { MongoDBNamespace } from '../../src/utils';
68

79
describe('ChangeStreamCursor', function () {
810
afterEach(function () {

‎test/unit/client-side-encryption/auto_encrypter.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import { BSON } from 'bson';
12
import { expect } from 'chai';
23
import * as fs from 'fs';
34
import * as net from 'net';
45
import * as sinon from 'sinon';
56

67
import { AutoEncrypter } from '../../../src/client-side-encryption/auto_encrypter';
8+
import { type DataKey } from '../../../src/client-side-encryption/client_encryption';
79
import { MongocryptdManager } from '../../../src/client-side-encryption/mongocryptd_manager';
810
import { StateMachine } from '../../../src/client-side-encryption/state_machine';
911
import { MongoClient } from '../../../src/mongo_client';
10-
import { BSON, type DataKey } from '../../mongodb';
1112
import * as requirements from './requirements.helper';
1213

1314
const bson = BSON;

‎test/unit/client-side-encryption/client_encryption.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Binary, BSON, deserialize } from 'bson';
12
import { expect } from 'chai';
23
import * as fs from 'fs';
34
import { resolve } from 'path';
@@ -10,7 +11,7 @@ import {
1011
MongoCryptCreateEncryptedCollectionError
1112
} from '../../../src/client-side-encryption/errors';
1213
import { StateMachine } from '../../../src/client-side-encryption/state_machine';
13-
import { Binary,BSON,deserialize,MongoClient } from '../../mongodb';
14+
import { MongoClient } from '../../../src/mongo_client';
1415

1516
const { EJSON } = BSON;
1617

‎test/unit/client-side-encryption/errors.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
MongoCryptError,
88
MongoCryptInvalidArgumentError
99
} from '../../../src/client-side-encryption/errors';
10-
import { MongoError } from '../../mongodb';
10+
import { MongoError } from '../../../src/error';
1111

1212
describe('MongoCryptError', function () {
1313
const errors = [

‎test/unit/client-side-encryption/providers/credentialsProvider.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import {
1313
tokenCache
1414
} from '../../../../src/client-side-encryption/providers/azure';
1515
import { AWSSDKCredentialProvider } from '../../../../src/cmap/auth/aws_temporary_credentials';
16+
import { MongoNetworkTimeoutError } from '../../../../src/error';
1617
import * as utils from '../../../../src/utils';
17-
import { MongoNetworkTimeoutError } from '../../../mongodb';
1818
import * as requirements from '../requirements.helper';
1919

2020
const originalAccessKeyId = process.env.AWS_ACCESS_KEY_ID;

‎test/unit/client-side-encryption/state_machine.test.ts‎

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
1+
import { BSON, Int32, Long, serialize } from 'bson';
12
import { expect } from 'chai';
23
import { EventEmitter, once } from 'events';
34
import * as fs from 'fs/promises';
45
import { type MongoCryptKMSRequest } from 'mongodb-client-encryption';
56
import * as net from 'net';
67
import * as sinon from 'sinon';
7-
import { setTimeout } from 'timers';
88
import { setTimeout as setTimeoutAsync } from 'timers/promises';
99
import * as tls from 'tls';
1010

1111
import { StateMachine } from '../../../src/client-side-encryption/state_machine';
12+
import { Collection } from '../../../src/collection';
13+
import { CursorTimeoutContext } from '../../../src/cursor/abstract_cursor';
1214
import { Db } from '../../../src/db';
13-
import {
14-
BSON,
15-
Collection,
16-
CSOTTimeoutContext,
17-
CursorTimeoutContext,
18-
type FindOptions,
19-
Int32,
20-
Long,
21-
MongoClient,
22-
serialize,
23-
squashError
24-
} from '../../mongodb';
15+
import { MongoClient } from '../../../src/mongo_client';
16+
import { type FindOptions } from '../../../src/operations/find';
17+
import { CSOTTimeoutContext } from '../../../src/timeout';
18+
import { squashError } from '../../../src/utils';
2519
import { sleep } from '../../tools/utils';
2620

2721
describe('StateMachine', function () {
@@ -129,7 +123,7 @@ describe('StateMachine', function () {
129123
});
130124
});
131125

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

145139
this.fakeSocket.emit('connect');
146-
setTimeout(() => {
147-
expect(status).to.equal('pending');
148-
expect(request.bytesNeeded).to.equal(500);
149-
expect(request.kmsProvider).to.equal('aws');
150-
this.fakeSocket.emit('data', Buffer.alloc(300));
151-
setTimeout(() => {
152-
expect(status).to.equal('pending');
153-
expect(request.bytesNeeded).to.equal(200);
154-
this.fakeSocket.emit('data', Buffer.alloc(200));
155-
setTimeout(() => {
156-
expect(status).to.equal('resolved');
157-
expect(request.bytesNeeded).to.equal(0);
158-
done();
159-
});
160-
});
161-
});
140+
await sleep();
141+
142+
expect(status).to.equal('pending');
143+
expect(request.bytesNeeded).to.equal(500);
144+
expect(request.kmsProvider).to.equal('aws');
145+
this.fakeSocket.emit('data', Buffer.alloc(300));
146+
await sleep();
147+
148+
expect(status).to.equal('pending');
149+
expect(request.bytesNeeded).to.equal(200);
150+
this.fakeSocket.emit('data', Buffer.alloc(200));
151+
await sleep();
152+
153+
expect(status).to.equal('resolved');
154+
expect(request.bytesNeeded).to.equal(0);
162155
});
163156
});
164157

@@ -196,13 +189,9 @@ describe('StateMachine', function () {
196189
} as any);
197190
const request = new MockRequest(Buffer.from('foobar'), 500);
198191

199-
it('rejects with the validation error', function (done) {
200-
stateMachine.kmsRequest(request).catch(err => {
201-
expect(err.message).to.equal(
202-
`Insecure TLS options prohibited for aws: ${option}`
203-
);
204-
done();
205-
});
192+
it('rejects with the validation error', async function () {
193+
const err = await stateMachine.kmsRequest(request).catch(e => e);
194+
expect(err.message).to.equal(`Insecure TLS options prohibited for aws: ${option}`);
206195
});
207196
});
208197
}

‎test/unit/cmap/auth/auth_provider.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect } from 'chai';
22

3-
import { type AuthContext, AuthProvider, MongoRuntimeError } from '../../../mongodb';
3+
import { type AuthContext, AuthProvider } from '../../../../src/cmap/auth/auth_provider';
4+
import { MongoRuntimeError } from '../../../../src/error';
45

56
describe('AuthProvider', function () {
67
describe('#reauth', function () {

‎test/unit/cmap/auth/gssapi.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
GSSAPICanonicalizationValue,
77
performGSSAPICanonicalizeHostName,
88
resolveCname
9-
} from '../../../mongodb';
9+
} from '../../../../src/cmap/auth/gssapi';
1010

1111
describe('GSSAPI', () => {
1212
let lookupSpy;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /