0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-25 09:19:32 +01:00
mongodb/jstests/noPassthrough/shell_error_codes.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

/**
* Tests for the ErrorCodes objects in error_codes.js generated file.
*/
(() => {
"use strict";
const tests = [];
const nonExistingErrorCode = 999999999;
tests.push(function errorCodesShouldThrowExceptionForNonExistingError() {
assert.throws(() => {
return ErrorCodes.thisIsAnErrorCodeThatDoesNotExist;
});
});
tests.push(function errorCodesShouldNotThrowExceptionForExistingError() {
assert.doesNotThrow(() => {
return ErrorCodes.BadValue;
});
});
tests.push(function errorCodeStringsShouldThrowExceptionForNonExistingError() {
assert.throws(() => {
return ErrorCodeStrings[nonExistingErrorCode];
});
});
tests.push(function errorCodeStringsShouldNotThrowExceptionForExistingError() {
assert.doesNotThrow(() => {
return ErrorCodeStrings[2];
});
});
tests.push(function errorCodesShouldHaveCategoriesDefined() {
assert.eq(true, ErrorCodes.isNetworkError(ErrorCodes.HostNotFound));
});
tests.push(function errorCodesCategoriesShouldReturnFalseOnNonExistingErrorCodes() {
assert.eq(false, ErrorCodes.isNetworkError(nonExistingErrorCode));
});
/* main */
tests.forEach((test) => {
jsTest.log(`Starting tests '${test.name}'`);
test();
});
})();