Skip to content

Commit 3787250

Browse files
move unit to integration test to get correct maxWireVersion for opMsg
1 parent bcf1244 commit 3787250

File tree

2 files changed

+44
-51
lines changed

2 files changed

+44
-51
lines changed

test/integration/collection-management/collection.test.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { expect } from 'chai';
2-
3-
import { Collection, type Db, type MongoClient, MongoServerError } from '../../mongodb';
2+
import * as sinon from 'sinon';
3+
4+
import {
5+
Collection,
6+
CreateIndexesOperation,
7+
type Db,
8+
type MongoClient,
9+
MongoServerError
10+
} from '../../mongodb';
411
import { type FailPoint } from '../../tools/utils';
512
import { setupDatabase } from '../shared';
613

@@ -422,6 +429,41 @@ describe('Collection', function () {
422429
});
423430
});
424431

432+
describe('#createIndex', () => {
433+
let client: MongoClient;
434+
let db: Db;
435+
let coll: Collection<{ a: string }>;
436+
const ERROR_RESPONSE = {
437+
ok: 0,
438+
errmsg:
439+
'WiredTigerIndex::insert: key too large to index, failing 1470 { : "56f37cb8e4b089e98d52ab0e", : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." }',
440+
code: 17280
441+
};
442+
443+
beforeEach(async function () {
444+
client = configuration.newClient({ w: 1 });
445+
db = client.db(configuration.db);
446+
coll = db.collection('test_coll');
447+
await client.connect();
448+
sinon.stub(CreateIndexesOperation.prototype, 'execute').callsFake(() => {
449+
throw ERROR_RESPONSE;
450+
});
451+
});
452+
453+
afterEach(async function () {
454+
await coll.drop();
455+
await client.close();
456+
sinon.restore();
457+
});
458+
459+
it('should error when createIndex fails', async function () {
460+
const e = await coll.createIndex({ a: 1 }).catch(e => e);
461+
expect(e).to.have.property('ok', ERROR_RESPONSE.ok);
462+
expect(e).to.have.property('errmsg', ERROR_RESPONSE.errmsg);
463+
expect(e).to.have.property('code', ERROR_RESPONSE.code);
464+
});
465+
});
466+
425467
describe('countDocuments()', function () {
426468
let client: MongoClient;
427469
let collection: Collection<{ test: string }>;

test/unit/collection.test.ts

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,6 @@ describe('Collection', function () {
1414
await cleanup();
1515
});
1616

17-
context('#createIndex', () => {
18-
it.only('should error when createIndex fails', function (done) {
19-
const ERROR_RESPONSE = {
20-
ok: 0,
21-
errmsg:
22-
'WiredTigerIndex::insert: key too large to index, failing 1470 { : "56f37cb8e4b089e98d52ab0e", : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." }',
23-
code: 17280
24-
};
25-
26-
server.setMessageHandler(request => {
27-
const doc = request.document;
28-
29-
if (isHello(doc)) {
30-
return request.reply(Object.assign({}, HELLO));
31-
}
32-
33-
if (doc.createIndexes) {
34-
return request.reply(ERROR_RESPONSE);
35-
}
36-
37-
if (doc.insert === 'system.indexes') {
38-
return request.reply(ERROR_RESPONSE);
39-
}
40-
});
41-
42-
const client = new MongoClient(`mongodb://${server.uri()}`);
43-
44-
const close = e => client.close().then(() => done(e));
45-
46-
client
47-
.connect()
48-
.then(() => client.db('foo').collection('bar'))
49-
.then(coll => coll.createIndex({ a: 1 }))
50-
.then(
51-
() => close('Expected createIndex to fail, but it succeeded'),
52-
e => {
53-
try {
54-
expect(e).to.have.property('ok', ERROR_RESPONSE.ok);
55-
expect(e).to.have.property('errmsg', ERROR_RESPONSE.errmsg);
56-
expect(e).to.have.property('code', ERROR_RESPONSE.code);
57-
close(null);
58-
} catch (err) {
59-
close(err);
60-
}
61-
}
62-
);
63-
});
64-
});
65-
6617
context('#aggregate', () => {
6718
// general test for aggregate function
6819
function testAggregate(config, done) {

0 commit comments

Comments
 (0)