renovate/lib/workers/repository/error.spec.ts

100 lines
3 KiB
TypeScript
Raw Normal View History

2020-05-01 16:03:48 +00:00
import { RenovateConfig, getConfig } from '../../../test/util';
import {
CONFIG_VALIDATION,
2020-06-22 19:28:02 +00:00
EXTERNAL_HOST_ERROR,
MANAGER_LOCKFILE_ERROR,
MANAGER_NO_PACKAGE_FILES,
PLATFORM_AUTHENTICATION_ERROR,
PLATFORM_BAD_CREDENTIALS,
PLATFORM_INTEGRATION_UNAUTHORIZED,
PLATFORM_RATE_LIMIT_EXCEEDED,
REPOSITORY_ACCESS_FORBIDDEN,
REPOSITORY_ARCHIVED,
REPOSITORY_BLOCKED,
REPOSITORY_CANNOT_FORK,
REPOSITORY_CHANGED,
REPOSITORY_DISABLED,
REPOSITORY_EMPTY,
REPOSITORY_FORKED,
REPOSITORY_MIRRORED,
REPOSITORY_NOT_FOUND,
2020-05-01 16:03:48 +00:00
REPOSITORY_NO_VULNERABILITY,
REPOSITORY_RENAMED,
REPOSITORY_TEMPORARY_ERROR,
REPOSITORY_UNINITIATED,
SYSTEM_INSUFFICIENT_DISK_SPACE,
SYSTEM_INSUFFICIENT_MEMORY,
UNKNOWN_ERROR,
2020-03-05 20:57:24 +00:00
} from '../../constants/error-messages';
2020-06-22 19:28:02 +00:00
import { ExternalHostError } from '../../types/error';
2020-05-01 16:03:48 +00:00
import handleError from './error';
2020-03-05 20:57:24 +00:00
jest.mock('./error-config');
let config: RenovateConfig;
beforeEach(() => {
jest.resetAllMocks();
config = getConfig();
});
describe('workers/repository/error', () => {
describe('handleError()', () => {
const errors = [
REPOSITORY_UNINITIATED,
REPOSITORY_EMPTY,
REPOSITORY_DISABLED,
REPOSITORY_CHANGED,
REPOSITORY_FORKED,
MANAGER_NO_PACKAGE_FILES,
CONFIG_VALIDATION,
REPOSITORY_ARCHIVED,
REPOSITORY_MIRRORED,
REPOSITORY_RENAMED,
REPOSITORY_BLOCKED,
REPOSITORY_NOT_FOUND,
REPOSITORY_ACCESS_FORBIDDEN,
PLATFORM_BAD_CREDENTIALS,
PLATFORM_RATE_LIMIT_EXCEEDED,
MANAGER_LOCKFILE_ERROR,
SYSTEM_INSUFFICIENT_DISK_SPACE,
SYSTEM_INSUFFICIENT_MEMORY,
REPOSITORY_NO_VULNERABILITY,
REPOSITORY_CANNOT_FORK,
PLATFORM_INTEGRATION_UNAUTHORIZED,
PLATFORM_AUTHENTICATION_ERROR,
REPOSITORY_TEMPORARY_ERROR,
];
errors.forEach((err) => {
it(`errors ${err}`, async () => {
const res = await handleError(config, new Error(err));
expect(res).toEqual(err);
});
});
2020-06-22 19:28:02 +00:00
it(`handles ExternalHostError`, async () => {
const res = await handleError(
config,
new ExternalHostError(new Error(), 'some-host-type')
);
expect(res).toEqual(EXTERNAL_HOST_ERROR);
});
2019-06-12 14:14:44 +00:00
it('rewrites git 5xx error', async () => {
const gitError = new Error(
"fatal: unable to access 'https://**redacted**@gitlab.com/learnox/learnox.git/': The requested URL returned error: 500\n"
);
const res = await handleError(config, gitError);
2020-06-22 19:28:02 +00:00
expect(res).toEqual(EXTERNAL_HOST_ERROR);
});
2019-06-12 14:14:44 +00:00
it('rewrites git remote error', async () => {
const gitError = new Error(
'fatal: remote error: access denied or repository not exported: /b/nw/bd/27/47/159945428/108610112.git\n'
);
const res = await handleError(config, gitError);
2020-06-22 19:28:02 +00:00
expect(res).toEqual(EXTERNAL_HOST_ERROR);
2019-06-12 14:14:44 +00:00
});
it('handles unknown error', async () => {
const res = await handleError(config, new Error('abcdefg'));
expect(res).toEqual(UNKNOWN_ERROR);
});
});
});