2019-07-15 09:04:05 +00:00
|
|
|
import handleError from '../../../lib/workers/repository/error';
|
2017-11-05 04:45:49 +00:00
|
|
|
|
2017-12-18 08:39:52 +00:00
|
|
|
jest.mock('../../../lib/workers/repository/error-config');
|
|
|
|
|
2017-11-05 04:45:49 +00:00
|
|
|
let config;
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
2019-03-11 15:50:10 +00:00
|
|
|
config = require('../../config/config/_fixtures');
|
2017-11-05 04:45:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('workers/repository/error', () => {
|
|
|
|
describe('handleError()', () => {
|
|
|
|
const errors = [
|
|
|
|
'uninitiated',
|
2018-09-25 06:50:47 +00:00
|
|
|
'empty',
|
2017-11-05 04:45:49 +00:00
|
|
|
'disabled',
|
2018-02-03 14:45:43 +00:00
|
|
|
'repository-changed',
|
2017-11-05 04:45:49 +00:00
|
|
|
'fork',
|
|
|
|
'no-package-files',
|
2017-12-18 08:39:52 +00:00
|
|
|
'config-validation',
|
2018-01-14 17:58:49 +00:00
|
|
|
'registry-failure',
|
2017-12-31 19:28:22 +00:00
|
|
|
'archived',
|
2019-06-13 04:05:58 +00:00
|
|
|
'mirror',
|
2018-02-08 15:04:25 +00:00
|
|
|
'renamed',
|
2018-02-02 17:04:41 +00:00
|
|
|
'blocked',
|
2017-12-31 19:47:46 +00:00
|
|
|
'not-found',
|
2018-02-05 21:23:50 +00:00
|
|
|
'forbidden',
|
2019-02-13 21:33:58 +00:00
|
|
|
'bad-credentials',
|
2018-03-22 08:26:20 +00:00
|
|
|
'rate-limit-exceeded',
|
2018-05-24 14:28:36 +00:00
|
|
|
'lockfile-error',
|
2018-09-08 05:16:05 +00:00
|
|
|
'disk-space',
|
2018-07-21 06:38:13 +00:00
|
|
|
'platform-failure',
|
2018-07-29 13:50:19 +00:00
|
|
|
'no-vulnerability-alerts',
|
2018-10-08 08:41:55 +00:00
|
|
|
'cannot-fork',
|
2018-12-03 11:03:46 +00:00
|
|
|
'integration-unauthorized',
|
2019-02-02 01:46:32 +00:00
|
|
|
'authentication-error',
|
2019-03-16 06:55:39 +00:00
|
|
|
'temporary-error',
|
2017-11-05 04:45:49 +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);
|
|
|
|
});
|
|
|
|
});
|
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);
|
|
|
|
expect(res).toEqual('platform-failure');
|
|
|
|
});
|
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);
|
|
|
|
expect(res).toEqual('platform-failure');
|
|
|
|
});
|
2017-12-18 08:39:52 +00:00
|
|
|
it('handles unknown error', async () => {
|
|
|
|
const res = await handleError(config, new Error('abcdefg'));
|
2017-11-05 04:45:49 +00:00
|
|
|
expect(res).toEqual('unknown-error');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|