2020-05-01 16:03:48 +00:00
|
|
|
import { RenovateConfig, getConfig } from '../../../test/util';
|
2020-01-12 07:50:11 +00:00
|
|
|
import {
|
|
|
|
CONFIG_VALIDATION,
|
|
|
|
DATASOURCE_FAILURE,
|
|
|
|
MANAGER_LOCKFILE_ERROR,
|
|
|
|
MANAGER_NO_PACKAGE_FILES,
|
|
|
|
PLATFORM_AUTHENTICATION_ERROR,
|
|
|
|
PLATFORM_BAD_CREDENTIALS,
|
|
|
|
PLATFORM_FAILURE,
|
|
|
|
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,
|
2020-01-12 07:50:11 +00:00
|
|
|
REPOSITORY_RENAMED,
|
|
|
|
REPOSITORY_TEMPORARY_ERROR,
|
|
|
|
REPOSITORY_UNINITIATED,
|
|
|
|
SYSTEM_INSUFFICIENT_DISK_SPACE,
|
2020-04-16 16:08:53 +00:00
|
|
|
SYSTEM_INSUFFICIENT_MEMORY,
|
2020-01-12 07:50:11 +00:00
|
|
|
UNKNOWN_ERROR,
|
2020-03-05 20:57:24 +00:00
|
|
|
} from '../../constants/error-messages';
|
|
|
|
import { DatasourceError } from '../../datasource/common';
|
2020-05-01 16:03:48 +00:00
|
|
|
import handleError from './error';
|
2017-11-05 04:45:49 +00:00
|
|
|
|
2020-03-05 20:57:24 +00:00
|
|
|
jest.mock('./error-config');
|
2017-12-18 08:39:52 +00:00
|
|
|
|
2020-01-10 10:35:49 +00:00
|
|
|
let config: RenovateConfig;
|
2017-11-05 04:45:49 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
2020-03-02 11:06:16 +00:00
|
|
|
config = getConfig();
|
2017-11-05 04:45:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('workers/repository/error', () => {
|
|
|
|
describe('handleError()', () => {
|
|
|
|
const errors = [
|
2020-01-12 07:50:11 +00:00
|
|
|
REPOSITORY_UNINITIATED,
|
|
|
|
REPOSITORY_EMPTY,
|
|
|
|
REPOSITORY_DISABLED,
|
|
|
|
REPOSITORY_CHANGED,
|
|
|
|
REPOSITORY_FORKED,
|
|
|
|
MANAGER_NO_PACKAGE_FILES,
|
|
|
|
CONFIG_VALIDATION,
|
|
|
|
DATASOURCE_FAILURE,
|
|
|
|
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,
|
2020-04-16 16:08:53 +00:00
|
|
|
SYSTEM_INSUFFICIENT_MEMORY,
|
2020-01-12 07:50:11 +00:00
|
|
|
PLATFORM_FAILURE,
|
|
|
|
REPOSITORY_NO_VULNERABILITY,
|
|
|
|
REPOSITORY_CANNOT_FORK,
|
|
|
|
PLATFORM_INTEGRATION_UNAUTHORIZED,
|
|
|
|
PLATFORM_AUTHENTICATION_ERROR,
|
|
|
|
REPOSITORY_TEMPORARY_ERROR,
|
2017-11-05 04:45:49 +00:00
|
|
|
];
|
2020-04-12 16:09:36 +00:00
|
|
|
errors.forEach((err) => {
|
2017-12-18 08:39:52 +00:00
|
|
|
it(`errors ${err}`, async () => {
|
|
|
|
const res = await handleError(config, new Error(err));
|
2017-11-05 04:45:49 +00:00
|
|
|
expect(res).toEqual(err);
|
|
|
|
});
|
|
|
|
});
|
2020-02-14 08:19:45 +00:00
|
|
|
it(`handles DatasourceError`, async () => {
|
|
|
|
const res = await handleError(config, new DatasourceError(new Error()));
|
|
|
|
expect(res).toEqual(DATASOURCE_FAILURE);
|
|
|
|
});
|
2019-06-12 14:14:44 +00:00
|
|
|
it('rewrites git 5xx error', async () => {
|
2019-06-12 08:49:21 +00:00
|
|
|
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-01-12 07:50:11 +00:00
|
|
|
expect(res).toEqual(PLATFORM_FAILURE);
|
2019-06-12 08:49:21 +00:00
|
|
|
});
|
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-01-12 07:50:11 +00:00
|
|
|
expect(res).toEqual(PLATFORM_FAILURE);
|
2019-06-12 14:14:44 +00:00
|
|
|
});
|
2017-12-18 08:39:52 +00:00
|
|
|
it('handles unknown error', async () => {
|
|
|
|
const res = await handleError(config, new Error('abcdefg'));
|
2020-01-12 07:50:11 +00:00
|
|
|
expect(res).toEqual(UNKNOWN_ERROR);
|
2017-11-05 04:45:49 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|