/
artifacts.spec.ts
231 lines (212 loc) · 7.15 KB
/
artifacts.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import { join } from 'upath';
import { envMock, mockExecAll } from '../../../../test/exec-util';
import { env, fs, mocked } from '../../../../test/util';
import { GlobalConfig } from '../../../config/global';
import type { RepoGlobalConfig } from '../../../config/types';
import * as docker from '../../../util/exec/docker';
import * as _datasource from '../../datasource';
import type { UpdateArtifact, UpdateArtifactsConfig } from '../types';
import * as pub from '.';
jest.mock('../../../util/exec/env');
jest.mock('../../../util/fs');
jest.mock('../../../util/git');
jest.mock('../../../util/http');
jest.mock('../../datasource');
process.env.BUILDPACK = 'true';
const lockFile = 'pubspec.lock';
const oldLockFileContent = 'Old pubspec.lock';
const newLockFileContent = 'New pubspec.lock';
const depName = 'depName';
const datasource = mocked(_datasource);
const adminConfig: RepoGlobalConfig = {
localDir: join('/tmp/github/some/repo'),
cacheDir: join('/tmp/cache'),
containerbaseDir: join('/tmp/cache/containerbase'),
};
const config: UpdateArtifactsConfig = {};
const updateArtifact: UpdateArtifact = {
packageFileName: 'pubspec.yaml',
updatedDeps: [{ depName }],
newPackageFileContent: '',
config,
};
describe('modules/manager/pub/artifacts', () => {
beforeEach(() => {
jest.resetAllMocks();
jest.resetModules();
env.getChildProcessEnv.mockReturnValue(envMock.basic);
GlobalConfig.set(adminConfig);
docker.resetPrefetchedImages();
datasource.getPkgReleases.mockResolvedValueOnce({
releases: [{ version: '2.10.5' }, { version: '3.3.9' }],
});
});
afterEach(() => {
GlobalConfig.set(adminConfig);
});
it('returns null if no pubspec.lock found', async () => {
expect(await pub.updateArtifacts(updateArtifact)).toBeNull();
});
it('returns null if updatedDeps is empty', async () => {
expect(
await pub.updateArtifacts({ ...updateArtifact, updatedDeps: [] })
).toBeNull();
});
describe.each([
{ sdk: 'dart', packageFileContent: '' },
{ sdk: 'flutter', packageFileContent: 'sdk: flutter' },
])('validates pub tools', (params) => {
it(`returns null for ${params.sdk} if unchanged`, async () => {
const execSnapshots = mockExecAll();
fs.readLocalFile.mockResolvedValueOnce(oldLockFileContent);
fs.readLocalFile.mockResolvedValueOnce(oldLockFileContent);
expect(
await pub.updateArtifacts({
...updateArtifact,
newPackageFileContent: params.packageFileContent,
})
).toBeNull();
expect(execSnapshots).toMatchObject([
{
cmd: `${params.sdk} pub upgrade ${depName}`,
},
]);
});
it(`returns updated ${params.sdk} pubspec.lock`, async () => {
const execSnapshots = mockExecAll();
fs.getSiblingFileName.mockReturnValueOnce(lockFile);
fs.readLocalFile.mockResolvedValueOnce(oldLockFileContent);
fs.readLocalFile.mockResolvedValueOnce(newLockFileContent);
expect(
await pub.updateArtifacts({
...updateArtifact,
newPackageFileContent: params.packageFileContent,
})
).toEqual([
{
file: {
type: 'addition',
path: lockFile,
contents: newLockFileContent,
},
},
]);
expect(execSnapshots).toMatchObject([
{
cmd: `${params.sdk} pub upgrade ${depName}`,
},
]);
});
it(`returns updated ${params.sdk} pubspec.lock for lockfile maintenance`, async () => {
const execSnapshots = mockExecAll();
fs.getSiblingFileName.mockReturnValueOnce(lockFile);
fs.readLocalFile.mockResolvedValueOnce(oldLockFileContent);
fs.readLocalFile.mockResolvedValueOnce(newLockFileContent);
expect(
await pub.updateArtifacts({
...updateArtifact,
newPackageFileContent: params.packageFileContent,
config: { ...config, updateType: 'lockFileMaintenance' },
})
).toEqual([
{
file: {
type: 'addition',
path: lockFile,
contents: newLockFileContent,
},
},
]);
expect(execSnapshots).toMatchObject([
{
cmd: `${params.sdk} pub upgrade`,
},
]);
});
it(`supports ${params.sdk} docker mode`, async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
const execSnapshots = mockExecAll();
fs.getSiblingFileName.mockReturnValueOnce(lockFile);
fs.readLocalFile.mockResolvedValueOnce(oldLockFileContent);
fs.readLocalFile.mockResolvedValueOnce(newLockFileContent);
expect(
await pub.updateArtifacts({
...updateArtifact,
newPackageFileContent: params.packageFileContent,
})
).toEqual([
{
file: {
type: 'addition',
path: lockFile,
contents: newLockFileContent,
},
},
]);
expect(execSnapshots).toMatchObject([
{
cmd: 'docker pull renovate/sidecar',
},
{
cmd: 'docker ps --filter name=renovate_sidecar -aq',
},
{
cmd:
'docker run --rm --name=renovate_sidecar --label=renovate_child ' +
'-v "/tmp/github/some/repo":"/tmp/github/some/repo" ' +
'-v "/tmp/cache":"/tmp/cache" ' +
'-e BUILDPACK_CACHE_DIR ' +
'-e CONTAINERBASE_CACHE_DIR ' +
'-w "/tmp/github/some/repo" ' +
'renovate/sidecar ' +
'bash -l -c "' +
`install-tool ${params.sdk} 3.3.9` +
' && ' +
`${params.sdk} pub upgrade ${depName}` +
'"',
},
]);
});
it(`supports ${params.sdk} install mode`, async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
const execSnapshots = mockExecAll();
fs.getSiblingFileName.mockReturnValueOnce(lockFile);
fs.readLocalFile.mockResolvedValueOnce(oldLockFileContent);
fs.readLocalFile.mockResolvedValueOnce(newLockFileContent);
expect(
await pub.updateArtifacts({
...updateArtifact,
newPackageFileContent: params.packageFileContent,
config: { ...config, constraints: { dart: '3.3.9' } },
})
).toEqual([
{
file: {
type: 'addition',
path: lockFile,
contents: newLockFileContent,
},
},
]);
expect(execSnapshots).toMatchObject([
{ cmd: `install-tool ${params.sdk} 3.3.9` },
{ cmd: `${params.sdk} pub upgrade ${depName}` },
]);
});
it(`catches errors for ${params.sdk}`, async () => {
const stderr = 'not found';
fs.getSiblingFileName.mockReturnValueOnce(lockFile);
fs.readLocalFile.mockResolvedValueOnce(oldLockFileContent);
fs.readLocalFile.mockResolvedValueOnce(newLockFileContent);
fs.writeLocalFile.mockImplementationOnce(() => {
throw new Error(stderr);
});
expect(
await pub.updateArtifacts({
...updateArtifact,
newPackageFileContent: params.packageFileContent,
})
).toEqual([{ artifactError: { lockFile, stderr } }]);
});
});
});