forked from renovatebot/renovate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract.spec.ts
131 lines (120 loc) · 4.49 KB
/
extract.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
import { codeBlock } from 'common-tags';
import { Fixtures } from '../../../../test/fixtures';
import { GlobalConfig } from '../../../config/global';
import { extractPackageFile } from '.';
const yamlFileMultiConfig = Fixtures.get('gitlab-ci.1.yaml');
const yamlFileSingleConfig = Fixtures.get('gitlab-ci.2.yaml');
const yamlWithEmptyIncludeConfig = Fixtures.get('gitlab-ci.3.yaml');
const yamlWithTriggerRef = Fixtures.get('gitlab-ci.4.yaml');
describe('modules/manager/gitlabci-include/extract', () => {
describe('extractPackageFile()', () => {
it('returns null for empty', () => {
expect(extractPackageFile('nothing here')).toBeNull();
});
it('returns null for include block without any actual includes', () => {
const res = extractPackageFile(yamlWithEmptyIncludeConfig);
expect(res).toBeNull();
});
it('extracts single include block', () => {
const res = extractPackageFile(yamlFileSingleConfig);
expect(res?.deps).toMatchSnapshot();
expect(res?.deps).toHaveLength(1);
});
it('extracts multiple include blocks', () => {
const res = extractPackageFile(yamlFileMultiConfig);
expect(res?.deps).toMatchSnapshot();
expect(res?.deps).toHaveLength(3);
});
it('extracts multiple embedded include blocks', () => {
const res = extractPackageFile(yamlWithTriggerRef);
expect(res?.deps).toHaveLength(2);
expect(res?.deps).toMatchObject([
{
currentValue: 'master',
datasource: 'gitlab-tags',
depName: 'mikebryant/include-source-example',
},
{
currentValue: '1.0.0',
datasource: 'gitlab-tags',
depName: 'mikebryant/include-source-example',
},
]);
});
it('ignores includes without project and file keys', () => {
const includeWithoutProjectRef = `include:
- 'https://gitlab.com/mikebryant/include-source-example.yml'
- remote: 'https://gitlab.com/mikebryant/include-source-example.yml'
- local: mikebryant/include-source-example`;
const res = extractPackageFile(includeWithoutProjectRef);
expect(res).toBeNull();
});
it('extracts component references', () => {
GlobalConfig.set({
endpoint: 'https://gitlab.example.com',
});
const content = codeBlock`
include:
- component: gitlab.example.com/an-org/a-project/a-component@1.0
inputs:
stage: build
- component: gitlab.example.com/an-org/a-subgroup/a-project/a-component@e3262fdd0914fa823210cdb79a8c421e2cef79d8
- component: gitlab.example.com/an-org/a-subgroup/another-project/a-component@main
- component: gitlab.example.com/another-org/a-project/a-component@~latest
inputs:
stage: test
- component: gitlab.example.com/malformed-component-reference
- component:
malformed: true
- component: gitlab.example.com/an-org/a-component@1.0
- component: other-gitlab.example.com/an-org/a-project/a-component@1.0
`;
const res = extractPackageFile(content);
expect(res?.deps).toMatchObject([
{
currentValue: '1.0',
datasource: 'gitlab-tags',
depName: 'an-org/a-project',
depType: 'repository',
},
{
currentValue: 'e3262fdd0914fa823210cdb79a8c421e2cef79d8',
datasource: 'gitlab-tags',
depName: 'an-org/a-subgroup/a-project',
depType: 'repository',
},
{
currentValue: 'main',
datasource: 'gitlab-tags',
depName: 'an-org/a-subgroup/another-project',
depType: 'repository',
},
{
currentValue: '~latest',
datasource: 'gitlab-tags',
depName: 'another-org/a-project',
depType: 'repository',
skipReason: 'unsupported-version',
},
{
currentValue: '1.0',
datasource: 'gitlab-tags',
depName: 'an-org/a-project',
depType: 'repository',
skipReason: 'invalid-value',
},
]);
});
it('normalizes configured endpoints', () => {
const endpoints = [
'http://gitlab.test/api/v4',
'http://gitlab.test/api/v4/',
];
for (const endpoint of endpoints) {
GlobalConfig.set({ platform: 'gitlab', endpoint });
const res = extractPackageFile(yamlFileMultiConfig);
expect(res?.deps[0].registryUrls).toEqual(['http://gitlab.test']);
}
});
});
});