-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
index.spec.ts
133 lines (129 loc) · 4.22 KB
/
index.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { ERROR, WARN } from 'bunyan';
import { getName, logger } from '../../../test/util';
import * as _configParser from '../../config';
import {
PLATFORM_TYPE_GITHUB,
PLATFORM_TYPE_GITLAB,
} from '../../constants/platforms';
import * as datasourceDocker from '../../datasource/docker';
import * as _platform from '../../platform';
import * as _repositoryWorker from '../repository';
import * as _limits from './limits';
import * as globalWorker from '.';
jest.mock('../repository');
// imports are readonly
const repositoryWorker = _repositoryWorker;
const configParser: jest.Mocked<typeof _configParser> = _configParser as never;
const platform: jest.Mocked<typeof _platform> = _platform as never;
const limits = _limits;
describe(getName(), () => {
beforeEach(() => {
jest.resetAllMocks();
logger.getProblems.mockImplementationOnce(() => []);
configParser.parseConfigs = jest.fn();
platform.initPlatform.mockImplementation((input) => Promise.resolve(input));
});
it('handles config warnings and errors', async () => {
configParser.parseConfigs.mockResolvedValueOnce({
repositories: [],
maintainYarnLock: true,
foo: 1,
});
await expect(globalWorker.start()).resolves.toEqual(0);
});
it('handles zero repos', async () => {
configParser.parseConfigs.mockResolvedValueOnce({
baseDir: '/tmp/base',
cacheDir: '/tmp/cache',
repositories: [],
});
await expect(globalWorker.start()).resolves.toEqual(0);
});
it('processes repositories', async () => {
configParser.parseConfigs.mockResolvedValueOnce({
gitAuthor: 'a@b.com',
enabled: true,
repositories: ['a', 'b'],
hostRules: [
{
hostType: datasourceDocker.id,
username: 'some-user',
password: 'some-password',
},
],
});
await globalWorker.start();
expect(configParser.parseConfigs).toHaveBeenCalledTimes(1);
expect(repositoryWorker.renovateRepository).toHaveBeenCalledTimes(2);
});
it('processes repositories break', async () => {
limits.isLimitReached = jest.fn(() => true);
configParser.parseConfigs.mockResolvedValueOnce({
gitAuthor: 'a@b.com',
enabled: true,
repositories: ['a', 'b'],
hostRules: [
{
hostType: datasourceDocker.id,
username: 'some-user',
password: 'some-password',
},
],
});
await globalWorker.start();
expect(configParser.parseConfigs).toHaveBeenCalledTimes(1);
expect(repositoryWorker.renovateRepository).toHaveBeenCalledTimes(0);
});
it('exits with non-zero when errors are logged', async () => {
configParser.parseConfigs.mockResolvedValueOnce({
baseDir: '/tmp/base',
cacheDir: '/tmp/cache',
repositories: [],
});
logger.getProblems.mockReset();
logger.getProblems.mockImplementationOnce(() => [
{
level: ERROR,
msg: 'meh',
},
]);
await expect(globalWorker.start()).resolves.not.toEqual(0);
});
it('exits with zero when warnings are logged', async () => {
configParser.parseConfigs.mockResolvedValueOnce({
baseDir: '/tmp/base',
cacheDir: '/tmp/cache',
repositories: [],
});
logger.getProblems.mockReset();
logger.getProblems.mockImplementationOnce(() => [
{
level: WARN,
msg: 'meh',
},
]);
await expect(globalWorker.start()).resolves.toEqual(0);
});
describe('processes platforms', () => {
it('github', async () => {
configParser.parseConfigs.mockResolvedValueOnce({
repositories: ['a'],
platform: PLATFORM_TYPE_GITHUB,
endpoint: 'https://github.com/',
});
await globalWorker.start();
expect(configParser.parseConfigs).toHaveBeenCalledTimes(1);
expect(repositoryWorker.renovateRepository).toHaveBeenCalledTimes(1);
});
it('gitlab', async () => {
configParser.parseConfigs.mockResolvedValueOnce({
repositories: [{ repository: 'a' }],
platform: PLATFORM_TYPE_GITLAB,
endpoint: 'https://my.gitlab.com/',
});
await globalWorker.start();
expect(configParser.parseConfigs).toHaveBeenCalledTimes(1);
expect(repositoryWorker.renovateRepository).toHaveBeenCalledTimes(1);
});
});
});