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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
1.6 KiB
JavaScript
Raw Normal View History

/**
* Tests for the ErrorCodes objects in error_codes.js generated file.
*/
const tests = [];
const nonExistingErrorCode = 999999999;
tests.push(function errorCodesShouldThrowExceptionForNonExistingError() {
assert.throws(() => {
return ErrorCodes.thisIsAnErrorCodeThatDoesNotExist;
});
});
tests.push(function errorCodesShouldNotThrowExceptionForExistingError() {
assert.doesNotThrow(() => {
return ErrorCodes.BadValue;
});
});
2018-04-27 15:24:01 +02:00
tests.push(function errorCodesShouldNotThrowExceptionForInheritedAttributes() {
assert.doesNotThrow(() => {
return ErrorCodes.prototype;
});
});
2018-04-27 15:24:01 +02:00
tests.push(function errorCodesShouldNotThrowExceptionForSymbols() {
assert.doesNotThrow(() => {
return print(+ErrorCodes);
});
});
2018-04-27 15:24:01 +02:00
tests.push(function errorCodesShouldNotThrowExceptionForConstructor() {
assert.doesNotThrow(() => {
return ErrorCodes.constructor;
});
});
2018-04-27 15:24:01 +02:00
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();
});