forked from renovatebot/renovate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.spec.ts
114 lines (105 loc) · 3.37 KB
/
error.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { RenovateConfig, getConfig } from '../../../test/util';
import {
CONFIG_SECRETS_EXPOSED,
CONFIG_VALIDATION,
EXTERNAL_HOST_ERROR,
MANAGER_LOCKFILE_ERROR,
NO_VULNERABILITY_ALERTS,
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,
REPOSITORY_NO_PACKAGE_FILES,
REPOSITORY_RENAMED,
REPOSITORY_UNINITIATED,
SYSTEM_INSUFFICIENT_DISK_SPACE,
SYSTEM_INSUFFICIENT_MEMORY,
TEMPORARY_ERROR,
UNKNOWN_ERROR,
} from '../../constants/error-messages';
import { ExternalHostError } from '../../types/errors/external-host-error';
import handleError from './error';
jest.mock('./error-issue');
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,
REPOSITORY_NO_PACKAGE_FILES,
CONFIG_SECRETS_EXPOSED,
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,
NO_VULNERABILITY_ALERTS,
REPOSITORY_CANNOT_FORK,
PLATFORM_INTEGRATION_UNAUTHORIZED,
PLATFORM_AUTHENTICATION_ERROR,
TEMPORARY_ERROR,
];
errors.forEach((err) => {
it(`errors ${err}`, async () => {
const res = await handleError(config, new Error(err));
expect(res).toEqual(err);
});
});
it(`handles ExternalHostError`, async () => {
const res = await handleError(
config,
new ExternalHostError(new Error(), 'some-host-type')
);
expect(res).toEqual(EXTERNAL_HOST_ERROR);
});
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);
expect(res).toEqual(EXTERNAL_HOST_ERROR);
});
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(EXTERNAL_HOST_ERROR);
});
it('rewrites git fatal error', async () => {
const gitError = new Error(
'fatal: not a git repository (or any parent up to mount point /mnt)\nStopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).\n'
);
const res = await handleError(config, gitError);
expect(res).toEqual(TEMPORARY_ERROR);
});
it('handles unknown error', async () => {
const res = await handleError(config, new Error('abcdefg'));
expect(res).toEqual(UNKNOWN_ERROR);
});
});
});