Skip to content

Commit c536683

Browse files
committed
test(txns): introduce errorLabel checks to the test runner
1 parent 3e9584b commit c536683

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

test/functional/transactions_tests.js

+31-4
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ function runTestSuiteTest(testData, context) {
186186
Object.assign({ monitorCommands: true }, testData.clientOptions)
187187
);
188188

189+
// test-specific client options
190+
clientOptions.autoReconnect = false;
191+
189192
return MongoClient.connect(context.url, clientOptions).then(client => {
190193
context.testClient = client;
191194
client.on('commandStarted', event => {
@@ -438,16 +441,40 @@ function testOperation(operation, obj, context) {
438441
}
439442

440443
if (operation.result) {
441-
if (operation.result.errorContains || operation.result.errorCodeName) {
444+
const result = operation.result;
445+
446+
if (
447+
result.errorContains ||
448+
result.errorCodeName ||
449+
result.errorLabelsContain ||
450+
result.errorLabelsOmit
451+
) {
442452
return opPromise
443453
.then(() => {
444454
throw new Error('expected an error!');
445455
})
446456
.catch(err => {
457+
const errorContains = result.errorContains;
458+
const errorCodeName = result.errorCodeName;
459+
const errorLabelsContain = result.errorLabelsContain;
460+
const errorLabelsOmit = result.errorLabelsOmit;
461+
462+
if (errorLabelsContain) {
463+
expect(err.errorLabels).to.include.members(errorLabelsContain);
464+
}
465+
466+
if (errorLabelsOmit) {
467+
if (err.errorLabels && Array.isArray(err.errorLabels) && err.errorLabels.length !== 0) {
468+
expect(err.errorLabels).to.not.include.members(errorLabelsOmit);
469+
}
470+
}
471+
447472
if (operation.result.errorContains) {
448-
expect(err).to.match(new RegExp(operation.result.errorContains, 'i'));
449-
} else {
450-
expect(err.codeName).to.equal(operation.result.errorCodeName);
473+
expect(err).to.match(new RegExp(errorContains, 'i'));
474+
}
475+
476+
if (errorCodeName) {
477+
expect(err.codeName).to.equal(errorCodeName);
451478
}
452479
});
453480
}

0 commit comments

Comments
 (0)