mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-10 22:16:28 +00:00
test(gradle-wrapper): add mock test (#6233)
This commit is contained in:
parent
081ee55dea
commit
ca71eddbdb
8 changed files with 535 additions and 256 deletions
|
@ -0,0 +1,67 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`manager/gradle-wrapper/artifacts gradlew failed 1`] = `
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"cmd": "<gradlew> wrapper --gradle-version 5.6.4",
|
||||||
|
"options": Object {
|
||||||
|
"cwd": "/root/project/lib/manager/gradle-wrapper/__fixtures__/testFiles",
|
||||||
|
"encoding": "utf-8",
|
||||||
|
"env": Object {
|
||||||
|
"HOME": "/home/user",
|
||||||
|
"HTTPS_PROXY": "https://example.com",
|
||||||
|
"HTTP_PROXY": "http://example.com",
|
||||||
|
"LANG": "en_US.UTF-8",
|
||||||
|
"LC_ALL": "en_US",
|
||||||
|
"NO_PROXY": "localhost",
|
||||||
|
"PATH": "/tmp/path",
|
||||||
|
},
|
||||||
|
"timeout": 900000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`manager/gradle-wrapper/artifacts replaces existing value 1`] = `
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"cmd": "<gradlew> wrapper --gradle-distribution-url https://services.gradle.org/distributions/gradle-6.3-bin.zip",
|
||||||
|
"options": Object {
|
||||||
|
"cwd": "/root/project/lib/manager/gradle-wrapper/__fixtures__/testFiles",
|
||||||
|
"encoding": "utf-8",
|
||||||
|
"env": Object {
|
||||||
|
"HOME": "/home/user",
|
||||||
|
"HTTPS_PROXY": "https://example.com",
|
||||||
|
"HTTP_PROXY": "http://example.com",
|
||||||
|
"LANG": "en_US.UTF-8",
|
||||||
|
"LC_ALL": "en_US",
|
||||||
|
"NO_PROXY": "localhost",
|
||||||
|
"PATH": "/tmp/path",
|
||||||
|
},
|
||||||
|
"timeout": 900000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`manager/gradle-wrapper/artifacts updates distributionSha256Sum 1`] = `
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"cmd": "<gradlew> wrapper --gradle-distribution-url https://services.gradle.org/distributions/gradle-6.3-bin.zip --gradle-distribution-sha256-sum 038794feef1f4745c6347107b6726279d1c824f3fc634b60f86ace1e9fbd1768",
|
||||||
|
"options": Object {
|
||||||
|
"cwd": "/root/project/lib/manager/gradle-wrapper/__fixtures__/testFiles",
|
||||||
|
"encoding": "utf-8",
|
||||||
|
"env": Object {
|
||||||
|
"HOME": "/home/user",
|
||||||
|
"HTTPS_PROXY": "https://example.com",
|
||||||
|
"HTTP_PROXY": "http://example.com",
|
||||||
|
"LANG": "en_US.UTF-8",
|
||||||
|
"LC_ALL": "en_US",
|
||||||
|
"NO_PROXY": "localhost",
|
||||||
|
"PATH": "/tmp/path",
|
||||||
|
},
|
||||||
|
"timeout": 900000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
`;
|
289
lib/manager/gradle-wrapper/artifacts-real.spec.ts
Normal file
289
lib/manager/gradle-wrapper/artifacts-real.spec.ts
Normal file
|
@ -0,0 +1,289 @@
|
||||||
|
import { resolve } from 'path';
|
||||||
|
import { readFile, readFileSync } from 'fs-extra';
|
||||||
|
import Git from 'simple-git/promise';
|
||||||
|
import * as httpMock from '../../../test/httpMock';
|
||||||
|
import { getName, partial, platform } from '../../../test/util';
|
||||||
|
import { setUtilConfig } from '../../util';
|
||||||
|
import * as runCache from '../../util/cache/run';
|
||||||
|
import { ifSystemSupportsGradle } from '../gradle/__testutil__/gradle';
|
||||||
|
import * as dcUpdate from '.';
|
||||||
|
|
||||||
|
const fixtures = resolve(__dirname, './__fixtures__');
|
||||||
|
const config = {
|
||||||
|
localDir: resolve(fixtures, './testFiles'),
|
||||||
|
toVersion: '5.6.4',
|
||||||
|
};
|
||||||
|
|
||||||
|
function readString(...paths: string[]): Promise<string> {
|
||||||
|
return readFile(resolve(fixtures, ...paths), 'utf8');
|
||||||
|
}
|
||||||
|
|
||||||
|
function readBinSync(...paths: string[]): Buffer {
|
||||||
|
return readFileSync(resolve(fixtures, ...paths));
|
||||||
|
}
|
||||||
|
|
||||||
|
function compareFile(file: string, path: string) {
|
||||||
|
expect(readBinSync(`./testFiles/${file}`)).toEqual(
|
||||||
|
readBinSync(`./${path}/${file}`)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe(getName(__filename), () => {
|
||||||
|
ifSystemSupportsGradle(6).describe('real tests', () => {
|
||||||
|
jest.setTimeout(60 * 1000);
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
jest.resetAllMocks();
|
||||||
|
await setUtilConfig(config);
|
||||||
|
httpMock.setup();
|
||||||
|
runCache.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await Git(fixtures).checkout(['HEAD', '--', '.']);
|
||||||
|
httpMock.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('replaces existing value', async () => {
|
||||||
|
platform.getRepoStatus.mockResolvedValue({
|
||||||
|
modified: [
|
||||||
|
'gradle/wrapper/gradle-wrapper.properties',
|
||||||
|
'gradle/wrapper/gradle-wrapper.jar',
|
||||||
|
'gradlew',
|
||||||
|
'gradlew.bat',
|
||||||
|
],
|
||||||
|
} as Git.StatusResult);
|
||||||
|
|
||||||
|
const res = await dcUpdate.updateArtifacts({
|
||||||
|
packageFileName: 'gradle/wrapper/gradle-wrapper.properties',
|
||||||
|
updatedDeps: [],
|
||||||
|
newPackageFileContent: await readString(
|
||||||
|
`./expectedFiles/gradle/wrapper/gradle-wrapper.properties`
|
||||||
|
),
|
||||||
|
config: { ...config, toVersion: '6.3' },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res).toEqual(
|
||||||
|
[
|
||||||
|
'gradle/wrapper/gradle-wrapper.properties',
|
||||||
|
'gradle/wrapper/gradle-wrapper.jar',
|
||||||
|
'gradlew',
|
||||||
|
'gradlew.bat',
|
||||||
|
].map((fileProjectPath) => {
|
||||||
|
return {
|
||||||
|
file: {
|
||||||
|
name: fileProjectPath,
|
||||||
|
contents: readBinSync(`./testFiles/${fileProjectPath}`),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
[
|
||||||
|
'gradle/wrapper/gradle-wrapper.properties',
|
||||||
|
'gradle/wrapper/gradle-wrapper.jar',
|
||||||
|
'gradlew',
|
||||||
|
'gradlew.bat',
|
||||||
|
].forEach((file) => {
|
||||||
|
compareFile(file, 'expectedFiles');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('updates from version', async () => {
|
||||||
|
platform.getRepoStatus.mockResolvedValueOnce(
|
||||||
|
partial<Git.StatusResult>({
|
||||||
|
modified: ['gradle/wrapper/gradle-wrapper.properties'],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = await dcUpdate.updateArtifacts({
|
||||||
|
packageFileName: 'gradle/wrapper/gradle-wrapper.properties',
|
||||||
|
updatedDeps: [],
|
||||||
|
newPackageFileContent: ``,
|
||||||
|
config: { ...config, toVersion: '6.3' },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toHaveLength(1);
|
||||||
|
expect(result[0].artifactError).toBeUndefined();
|
||||||
|
|
||||||
|
compareFile('gradle/wrapper/gradle-wrapper.properties', 'expectedFiles');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('up to date', async () => {
|
||||||
|
platform.getRepoStatus.mockResolvedValue({
|
||||||
|
modified: [],
|
||||||
|
} as Git.StatusResult);
|
||||||
|
|
||||||
|
const res = await dcUpdate.updateArtifacts({
|
||||||
|
packageFileName: 'gradle/wrapper/gradle-wrapper.properties',
|
||||||
|
updatedDeps: [],
|
||||||
|
newPackageFileContent: await readString(
|
||||||
|
`./testFiles/gradle/wrapper/gradle-wrapper.properties`
|
||||||
|
),
|
||||||
|
config,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res).toEqual([]);
|
||||||
|
|
||||||
|
// 5.6.4 => 5.6.4 (updates execs)
|
||||||
|
// 6.3 => (5.6.4) (downgrades execs)
|
||||||
|
// looks like a bug in Gradle
|
||||||
|
['gradle/wrapper/gradle-wrapper.properties'].forEach((file) => {
|
||||||
|
compareFile(file, 'testFiles-copy');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getRepoStatus fails', async () => {
|
||||||
|
platform.getRepoStatus.mockImplementation(() => {
|
||||||
|
throw new Error('failed');
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await dcUpdate.updateArtifacts({
|
||||||
|
packageFileName: 'gradle/wrapper/gradle-wrapper.properties',
|
||||||
|
updatedDeps: [],
|
||||||
|
newPackageFileContent: await readString(
|
||||||
|
`./testFiles/gradle/wrapper/gradle-wrapper.properties`
|
||||||
|
),
|
||||||
|
config,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res[0].artifactError.lockFile).toEqual(
|
||||||
|
'gradle/wrapper/gradle-wrapper.properties'
|
||||||
|
);
|
||||||
|
expect(res[0].artifactError.stderr).toEqual('failed');
|
||||||
|
|
||||||
|
// 5.6.4 => 5.6.4 (updates execs) - unexpected behavior (looks like a bug in Gradle)
|
||||||
|
['gradle/wrapper/gradle-wrapper.properties'].forEach((file) => {
|
||||||
|
compareFile(file, 'testFiles-copy');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gradlew failed', async () => {
|
||||||
|
const cfg = { ...config, localDir: resolve(fixtures, './wrongCmd') };
|
||||||
|
|
||||||
|
await setUtilConfig(cfg);
|
||||||
|
const res = await dcUpdate.updateArtifacts({
|
||||||
|
packageFileName: 'gradle/wrapper/gradle-wrapper.properties',
|
||||||
|
updatedDeps: [],
|
||||||
|
newPackageFileContent: await readString(
|
||||||
|
`./testFiles/gradle/wrapper/gradle-wrapper.properties`
|
||||||
|
),
|
||||||
|
config: cfg,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res[0].artifactError.lockFile).toEqual(
|
||||||
|
'gradle/wrapper/gradle-wrapper.properties'
|
||||||
|
);
|
||||||
|
expect(res[0].artifactError.stderr).not.toBeNull();
|
||||||
|
expect(res[0].artifactError.stderr).not.toEqual('');
|
||||||
|
|
||||||
|
// 5.6.4 => 5.6.4 (updates execs) - unexpected behavior (looks like a bug in Gradle)
|
||||||
|
['gradle/wrapper/gradle-wrapper.properties'].forEach((file) => {
|
||||||
|
compareFile(file, 'testFiles-copy');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gradlew not found', async () => {
|
||||||
|
const res = await dcUpdate.updateArtifacts({
|
||||||
|
packageFileName: 'gradle-wrapper.properties',
|
||||||
|
updatedDeps: [],
|
||||||
|
newPackageFileContent: undefined,
|
||||||
|
config: {
|
||||||
|
localDir: 'some-dir',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('updates distributionSha256Sum', async () => {
|
||||||
|
httpMock
|
||||||
|
.scope('https://services.gradle.org')
|
||||||
|
.get('/distributions/gradle-6.3-bin.zip.sha256')
|
||||||
|
.reply(
|
||||||
|
200,
|
||||||
|
'038794feef1f4745c6347107b6726279d1c824f3fc634b60f86ace1e9fbd1768'
|
||||||
|
);
|
||||||
|
|
||||||
|
platform.getRepoStatus.mockResolvedValueOnce(
|
||||||
|
partial<Git.StatusResult>({
|
||||||
|
modified: ['gradle/wrapper/gradle-wrapper.properties'],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const newContent = await readString(`./gradle-wrapper-sum.properties`);
|
||||||
|
|
||||||
|
const result = await dcUpdate.updateArtifacts({
|
||||||
|
packageFileName: 'gradle/wrapper/gradle-wrapper.properties',
|
||||||
|
updatedDeps: [],
|
||||||
|
newPackageFileContent: newContent.replace(
|
||||||
|
'038794feef1f4745c6347107b6726279d1c824f3fc634b60f86ace1e9fbd1768',
|
||||||
|
'1f3067073041bc44554d0efe5d402a33bc3d3c93cc39ab684f308586d732a80d'
|
||||||
|
),
|
||||||
|
config: {
|
||||||
|
...config,
|
||||||
|
toVersion: '6.3',
|
||||||
|
currentValue: '5.6.4',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toHaveLength(1);
|
||||||
|
expect(result[0].artifactError).toBeUndefined();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
await readString(
|
||||||
|
config.localDir,
|
||||||
|
`./gradle/wrapper/gradle-wrapper.properties`
|
||||||
|
)
|
||||||
|
).toEqual(newContent);
|
||||||
|
|
||||||
|
expect(httpMock.getTrace()).toEqual([
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'accept-encoding': 'gzip, deflate',
|
||||||
|
host: 'services.gradle.org',
|
||||||
|
'user-agent': 'https://github.com/renovatebot/renovate',
|
||||||
|
},
|
||||||
|
method: 'GET',
|
||||||
|
url:
|
||||||
|
'https://services.gradle.org/distributions/gradle-6.3-bin.zip.sha256',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('distributionSha256Sum 404', async () => {
|
||||||
|
httpMock
|
||||||
|
.scope('https://services.gradle.org')
|
||||||
|
.get('/distributions/gradle-6.3-bin.zip.sha256')
|
||||||
|
.reply(404);
|
||||||
|
|
||||||
|
const result = await dcUpdate.updateArtifacts({
|
||||||
|
packageFileName: 'gradle/wrapper/gradle-wrapper.properties',
|
||||||
|
updatedDeps: [],
|
||||||
|
newPackageFileContent: `distributionSha256Sum=336b6898b491f6334502d8074a6b8c2d73ed83b92123106bd4bf837f04111043\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-6.3-bin.zip`,
|
||||||
|
config,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toEqual([
|
||||||
|
{
|
||||||
|
artifactError: {
|
||||||
|
lockFile: 'gradle/wrapper/gradle-wrapper.properties',
|
||||||
|
stderr: 'Response code 404 (Not Found)',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
expect(httpMock.getTrace()).toEqual([
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'accept-encoding': 'gzip, deflate',
|
||||||
|
host: 'services.gradle.org',
|
||||||
|
'user-agent': 'https://github.com/renovatebot/renovate',
|
||||||
|
},
|
||||||
|
method: 'GET',
|
||||||
|
url:
|
||||||
|
'https://services.gradle.org/distributions/gradle-6.3-bin.zip.sha256',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,55 +1,59 @@
|
||||||
|
import { exec as _exec } from 'child_process';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import { readFile, readFileSync } from 'fs-extra';
|
import { readFile } from 'fs-extra';
|
||||||
import Git from 'simple-git/promise';
|
import Git from 'simple-git/promise';
|
||||||
|
import { envMock, mockExecAll } from '../../../test/execUtil';
|
||||||
import * as httpMock from '../../../test/httpMock';
|
import * as httpMock from '../../../test/httpMock';
|
||||||
import {
|
import {
|
||||||
bufferSerializer,
|
addReplacingSerializer,
|
||||||
|
env,
|
||||||
|
fs,
|
||||||
getName,
|
getName,
|
||||||
partial,
|
partial,
|
||||||
platform,
|
platform,
|
||||||
} from '../../../test/util';
|
} from '../../../test/util';
|
||||||
import { setUtilConfig } from '../../util';
|
import { setUtilConfig } from '../../util';
|
||||||
import * as runCache from '../../util/cache/run';
|
import { BinarySource } from '../../util/exec/common';
|
||||||
import { ifSystemSupportsGradle } from '../gradle/__testutil__/gradle';
|
import { resetPrefetchedImages } from '../../util/exec/docker';
|
||||||
import * as dcUpdate from '.';
|
import * as dcUpdate from '.';
|
||||||
|
|
||||||
|
jest.mock('child_process');
|
||||||
|
jest.mock('../../util/fs');
|
||||||
|
jest.mock('../../util/exec/env');
|
||||||
|
|
||||||
|
const exec: jest.Mock<typeof _exec> = _exec as any;
|
||||||
const fixtures = resolve(__dirname, './__fixtures__');
|
const fixtures = resolve(__dirname, './__fixtures__');
|
||||||
const config = {
|
const config = {
|
||||||
localDir: resolve(fixtures, './testFiles'),
|
localDir: resolve(fixtures, './testFiles'),
|
||||||
toVersion: '5.6.4',
|
toVersion: '5.6.4',
|
||||||
};
|
};
|
||||||
|
const dockerConfig = { ...config, binarySource: BinarySource.Docker };
|
||||||
|
|
||||||
jest.mock('../../platform');
|
addReplacingSerializer('gradlew.bat', '<gradlew>');
|
||||||
|
addReplacingSerializer('./gradlew', '<gradlew>');
|
||||||
expect.addSnapshotSerializer(bufferSerializer());
|
|
||||||
|
|
||||||
function readString(...paths: string[]): Promise<string> {
|
function readString(...paths: string[]): Promise<string> {
|
||||||
return readFile(resolve(fixtures, ...paths), 'utf8');
|
return readFile(resolve(fixtures, ...paths), 'utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
function readBinSync(...paths: string[]): Buffer {
|
|
||||||
return readFileSync(resolve(fixtures, ...paths));
|
|
||||||
}
|
|
||||||
|
|
||||||
function compareFile(file: string, path: string) {
|
|
||||||
expect(readBinSync(`./testFiles/${file}`)).toEqual(
|
|
||||||
readBinSync(`./${path}/${file}`)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe(getName(__filename), () => {
|
describe(getName(__filename), () => {
|
||||||
ifSystemSupportsGradle(6).describe('real tests', () => {
|
|
||||||
jest.setTimeout(60 * 1000);
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
await setUtilConfig(config);
|
|
||||||
httpMock.setup();
|
httpMock.setup();
|
||||||
runCache.clear();
|
|
||||||
|
env.getChildProcessEnv.mockReturnValue({
|
||||||
|
...envMock.basic,
|
||||||
|
LANG: 'en_US.UTF-8',
|
||||||
|
LC_ALL: 'en_US',
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
await setUtilConfig(config);
|
||||||
await Git(fixtures)?.checkout(['HEAD', '--', '.']);
|
resetPrefetchedImages();
|
||||||
|
|
||||||
|
fs.readLocalFile.mockResolvedValue('test');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
httpMock.reset();
|
httpMock.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -57,14 +61,15 @@ describe(getName(__filename), () => {
|
||||||
platform.getRepoStatus.mockResolvedValue({
|
platform.getRepoStatus.mockResolvedValue({
|
||||||
modified: [
|
modified: [
|
||||||
'gradle/wrapper/gradle-wrapper.properties',
|
'gradle/wrapper/gradle-wrapper.properties',
|
||||||
'gradle/wrapper/gradle-wrapper.jar',
|
|
||||||
'gradlew',
|
'gradlew',
|
||||||
'gradlew.bat',
|
'gradlew.bat',
|
||||||
],
|
],
|
||||||
} as Git.StatusResult);
|
} as Git.StatusResult);
|
||||||
|
|
||||||
|
const execSnapshots = mockExecAll(exec);
|
||||||
|
|
||||||
const res = await dcUpdate.updateArtifacts({
|
const res = await dcUpdate.updateArtifacts({
|
||||||
packageFileName: 'gradle/wrapper/gradle-wrapper.properties',
|
packageFileName: 'gradle-wrapper.properties',
|
||||||
updatedDeps: [],
|
updatedDeps: [],
|
||||||
newPackageFileContent: await readString(
|
newPackageFileContent: await readString(
|
||||||
`./expectedFiles/gradle/wrapper/gradle-wrapper.properties`
|
`./expectedFiles/gradle/wrapper/gradle-wrapper.properties`
|
||||||
|
@ -75,121 +80,18 @@ describe(getName(__filename), () => {
|
||||||
expect(res).toEqual(
|
expect(res).toEqual(
|
||||||
[
|
[
|
||||||
'gradle/wrapper/gradle-wrapper.properties',
|
'gradle/wrapper/gradle-wrapper.properties',
|
||||||
'gradle/wrapper/gradle-wrapper.jar',
|
|
||||||
'gradlew',
|
'gradlew',
|
||||||
'gradlew.bat',
|
'gradlew.bat',
|
||||||
].map((fileProjectPath) => {
|
].map((fileProjectPath) => {
|
||||||
return {
|
return {
|
||||||
file: {
|
file: {
|
||||||
name: fileProjectPath,
|
name: fileProjectPath,
|
||||||
contents: readBinSync(`./testFiles/${fileProjectPath}`),
|
contents: 'test',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
expect(execSnapshots).toMatchSnapshot();
|
||||||
[
|
|
||||||
'gradle/wrapper/gradle-wrapper.properties',
|
|
||||||
'gradle/wrapper/gradle-wrapper.jar',
|
|
||||||
'gradlew',
|
|
||||||
'gradlew.bat',
|
|
||||||
].forEach((file) => {
|
|
||||||
compareFile(file, 'expectedFiles');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('updates from version', async () => {
|
|
||||||
platform.getRepoStatus.mockResolvedValueOnce(
|
|
||||||
partial<Git.StatusResult>({
|
|
||||||
modified: ['gradle/wrapper/gradle-wrapper.properties'],
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const result = await dcUpdate.updateArtifacts({
|
|
||||||
packageFileName: 'gradle/wrapper/gradle-wrapper.properties',
|
|
||||||
updatedDeps: [],
|
|
||||||
newPackageFileContent: ``,
|
|
||||||
config: { ...config, toVersion: '6.3' },
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result).toHaveLength(1);
|
|
||||||
expect(result[0].artifactError).toBeUndefined();
|
|
||||||
|
|
||||||
compareFile('gradle/wrapper/gradle-wrapper.properties', 'expectedFiles');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('up to date', async () => {
|
|
||||||
platform.getRepoStatus.mockResolvedValue({
|
|
||||||
modified: [],
|
|
||||||
} as Git.StatusResult);
|
|
||||||
|
|
||||||
const res = await dcUpdate.updateArtifacts({
|
|
||||||
packageFileName: 'gradle/wrapper/gradle-wrapper.properties',
|
|
||||||
updatedDeps: [],
|
|
||||||
newPackageFileContent: await readString(
|
|
||||||
`./testFiles/gradle/wrapper/gradle-wrapper.properties`
|
|
||||||
),
|
|
||||||
config,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(res).toEqual([]);
|
|
||||||
|
|
||||||
// 5.6.4 => 5.6.4 (updates execs)
|
|
||||||
// 6.3 => (5.6.4) (downgrades execs)
|
|
||||||
// looks like a bug in Gradle
|
|
||||||
['gradle/wrapper/gradle-wrapper.properties'].forEach((file) => {
|
|
||||||
compareFile(file, 'testFiles-copy');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getRepoStatus fails', async () => {
|
|
||||||
platform.getRepoStatus.mockImplementation(() => {
|
|
||||||
throw new Error('failed');
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await dcUpdate.updateArtifacts({
|
|
||||||
packageFileName: 'gradle/wrapper/gradle-wrapper.properties',
|
|
||||||
updatedDeps: [],
|
|
||||||
newPackageFileContent: await readString(
|
|
||||||
`./testFiles/gradle/wrapper/gradle-wrapper.properties`
|
|
||||||
),
|
|
||||||
config,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(res[0].artifactError.lockFile).toEqual(
|
|
||||||
'gradle/wrapper/gradle-wrapper.properties'
|
|
||||||
);
|
|
||||||
expect(res[0].artifactError.stderr).toEqual('failed');
|
|
||||||
|
|
||||||
// 5.6.4 => 5.6.4 (updates execs) - unexpected behavior (looks like a bug in Gradle)
|
|
||||||
['gradle/wrapper/gradle-wrapper.properties'].forEach((file) => {
|
|
||||||
compareFile(file, 'testFiles-copy');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('gradlew failed', async () => {
|
|
||||||
const cfg = { ...config, localDir: resolve(fixtures, './wrongCmd') };
|
|
||||||
|
|
||||||
await setUtilConfig(cfg);
|
|
||||||
const res = await dcUpdate.updateArtifacts({
|
|
||||||
packageFileName: 'gradle-wrapper.properties',
|
|
||||||
updatedDeps: [],
|
|
||||||
newPackageFileContent: await readString(
|
|
||||||
`./testFiles/gradle/wrapper/gradle-wrapper.properties`
|
|
||||||
),
|
|
||||||
config: cfg,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(res[0].artifactError.lockFile).toEqual(
|
|
||||||
'gradle-wrapper.properties'
|
|
||||||
);
|
|
||||||
expect(res[0].artifactError.stderr).not.toBeNull();
|
|
||||||
expect(res[0].artifactError.stderr).not.toEqual('');
|
|
||||||
|
|
||||||
// 5.6.4 => 5.6.4 (updates execs) - unexpected behavior (looks like a bug in Gradle)
|
|
||||||
['gradle/wrapper/gradle-wrapper.properties'].forEach((file) => {
|
|
||||||
compareFile(file, 'testFiles-copy');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('gradlew not found', async () => {
|
it('gradlew not found', async () => {
|
||||||
|
@ -205,7 +107,25 @@ describe(getName(__filename), () => {
|
||||||
expect(res).toBeNull();
|
expect(res).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates distributionSha256Sum', async () => {
|
it('gradlew failed', async () => {
|
||||||
|
const execSnapshots = mockExecAll(exec, new Error('failed'));
|
||||||
|
platform.getRepoStatus.mockResolvedValueOnce(
|
||||||
|
partial<Git.StatusResult>({
|
||||||
|
modified: [],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const res = await dcUpdate.updateArtifacts({
|
||||||
|
packageFileName: 'gradle-wrapper.properties',
|
||||||
|
updatedDeps: [],
|
||||||
|
newPackageFileContent: '',
|
||||||
|
config,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(execSnapshots).toMatchSnapshot();
|
||||||
|
expect(res).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.only('updates distributionSha256Sum', async () => {
|
||||||
httpMock
|
httpMock
|
||||||
.scope('https://services.gradle.org')
|
.scope('https://services.gradle.org')
|
||||||
.get('/distributions/gradle-6.3-bin.zip.sha256')
|
.get('/distributions/gradle-6.3-bin.zip.sha256')
|
||||||
|
@ -219,32 +139,20 @@ describe(getName(__filename), () => {
|
||||||
modified: ['gradle/wrapper/gradle-wrapper.properties'],
|
modified: ['gradle/wrapper/gradle-wrapper.properties'],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
const newContent = await readString(`./gradle-wrapper-sum.properties`);
|
|
||||||
|
const execSnapshots = mockExecAll(exec);
|
||||||
|
|
||||||
const result = await dcUpdate.updateArtifacts({
|
const result = await dcUpdate.updateArtifacts({
|
||||||
packageFileName: 'gradle/wrapper/gradle-wrapper.properties',
|
packageFileName: 'gradle-wrapper.properties',
|
||||||
updatedDeps: [],
|
updatedDeps: [],
|
||||||
newPackageFileContent: newContent.replace(
|
newPackageFileContent: `distributionSha256Sum=336b6898b491f6334502d8074a6b8c2d73ed83b92123106bd4bf837f04111043\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-6.3-bin.zip`,
|
||||||
'038794feef1f4745c6347107b6726279d1c824f3fc634b60f86ace1e9fbd1768',
|
config: dockerConfig,
|
||||||
'1f3067073041bc44554d0efe5d402a33bc3d3c93cc39ab684f308586d732a80d'
|
|
||||||
),
|
|
||||||
config: {
|
|
||||||
...config,
|
|
||||||
toVersion: '6.3',
|
|
||||||
currentValue: '5.6.4',
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result).toHaveLength(1);
|
expect(result).toHaveLength(1);
|
||||||
expect(result[0].artifactError).toBeUndefined();
|
expect(result[0].artifactError).toBeUndefined();
|
||||||
|
|
||||||
expect(
|
expect(execSnapshots).toMatchSnapshot();
|
||||||
await readString(
|
|
||||||
config.localDir,
|
|
||||||
`./gradle/wrapper/gradle-wrapper.properties`
|
|
||||||
)
|
|
||||||
).toEqual(newContent);
|
|
||||||
|
|
||||||
expect(httpMock.getTrace()).toEqual([
|
expect(httpMock.getTrace()).toEqual([
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -266,7 +174,7 @@ describe(getName(__filename), () => {
|
||||||
.reply(404);
|
.reply(404);
|
||||||
|
|
||||||
const result = await dcUpdate.updateArtifacts({
|
const result = await dcUpdate.updateArtifacts({
|
||||||
packageFileName: 'gradle/wrapper/gradle-wrapper.properties',
|
packageFileName: 'gradle-wrapper.properties',
|
||||||
updatedDeps: [],
|
updatedDeps: [],
|
||||||
newPackageFileContent: `distributionSha256Sum=336b6898b491f6334502d8074a6b8c2d73ed83b92123106bd4bf837f04111043\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-6.3-bin.zip`,
|
newPackageFileContent: `distributionSha256Sum=336b6898b491f6334502d8074a6b8c2d73ed83b92123106bd4bf837f04111043\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-6.3-bin.zip`,
|
||||||
config,
|
config,
|
||||||
|
@ -275,7 +183,7 @@ describe(getName(__filename), () => {
|
||||||
expect(result).toEqual([
|
expect(result).toEqual([
|
||||||
{
|
{
|
||||||
artifactError: {
|
artifactError: {
|
||||||
lockFile: 'gradle/wrapper/gradle-wrapper.properties',
|
lockFile: 'gradle-wrapper.properties',
|
||||||
stderr: 'Response code 404 (Not Found)',
|
stderr: 'Response code 404 (Not Found)',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -294,4 +202,3 @@ describe(getName(__filename), () => {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
/* istanbul ignore file */
|
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import * as fs from 'fs-extra';
|
import * as fs from 'fs-extra';
|
||||||
import Git from 'simple-git/promise';
|
import Git from 'simple-git/promise';
|
||||||
|
|
|
@ -184,6 +184,7 @@
|
||||||
"@babel/plugin-syntax-dynamic-import": "7.8.3",
|
"@babel/plugin-syntax-dynamic-import": "7.8.3",
|
||||||
"@babel/preset-env": "7.9.6",
|
"@babel/preset-env": "7.9.6",
|
||||||
"@babel/preset-typescript": "7.9.0",
|
"@babel/preset-typescript": "7.9.0",
|
||||||
|
"@jest/globals": "26.0.1",
|
||||||
"@jest/reporters": "26.0.1",
|
"@jest/reporters": "26.0.1",
|
||||||
"@jest/test-result": "26.0.1",
|
"@jest/test-result": "26.0.1",
|
||||||
"@semantic-release/exec": "5.0.0",
|
"@semantic-release/exec": "5.0.0",
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
import { exec as _exec } from 'child_process';
|
import { exec as _exec } from 'child_process';
|
||||||
|
import is from '@sindresorhus/is';
|
||||||
|
import traverse from 'traverse';
|
||||||
|
import { toUnix } from 'upath';
|
||||||
import { ExecOptions } from '../lib/util/exec';
|
import { ExecOptions } from '../lib/util/exec';
|
||||||
|
|
||||||
type CallOptions = ExecOptions | null | undefined;
|
type CallOptions = ExecOptions | null | undefined;
|
||||||
|
@ -18,15 +21,15 @@ export function execSnapshot(cmd: string, options?: CallOptions): ExecSnapshot {
|
||||||
options,
|
options,
|
||||||
};
|
};
|
||||||
|
|
||||||
const str = JSON.stringify(snapshot, (k, v) => (v === undefined ? null : v));
|
const cwd = toUnix(process.cwd());
|
||||||
|
|
||||||
const cwd = process.cwd().replace(/\\(\w)/g, '/$1');
|
// eslint-disable-next-line array-callback-return
|
||||||
return JSON.parse(
|
return traverse(snapshot).map(function fixup(v) {
|
||||||
str
|
if (is.string(v)) {
|
||||||
.replace(/\\(\w)/g, '/$1')
|
const val = v.replace(/\\(\w)/g, '/$1').replace(cwd, '/root/project');
|
||||||
.split(cwd)
|
this.update(val);
|
||||||
.join('/root/project')
|
}
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultExecResult = { stdout: '', stderr: '' };
|
const defaultExecResult = { stdout: '', stderr: '' };
|
||||||
|
|
19
test/util.ts
19
test/util.ts
|
@ -1,9 +1,12 @@
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
|
import { expect, jest } from '@jest/globals';
|
||||||
import * as upath from 'upath';
|
import * as upath from 'upath';
|
||||||
import { RenovateConfig as _RenovateConfig } from '../lib/config';
|
import { RenovateConfig as _RenovateConfig } from '../lib/config';
|
||||||
import { getConfig } from '../lib/config/defaults';
|
import { getConfig } from '../lib/config/defaults';
|
||||||
import { platform as _platform } from '../lib/platform';
|
import { platform as _platform } from '../lib/platform';
|
||||||
|
import * as _env from '../lib/util/exec/env';
|
||||||
import * as _fs from '../lib/util/fs';
|
import * as _fs from '../lib/util/fs';
|
||||||
|
import * as _hostRules from '../lib/util/host-rules';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple wrapper for getting mocked version of a module
|
* Simple wrapper for getting mocked version of a module
|
||||||
|
@ -26,7 +29,7 @@ export function mocked<T>(module: T): jest.Mocked<T> {
|
||||||
*/
|
*/
|
||||||
export function mockPartial(moduleName: string, overrides?: object): unknown {
|
export function mockPartial(moduleName: string, overrides?: object): unknown {
|
||||||
const absolutePath = upath.join(module.parent.filename, '../', moduleName);
|
const absolutePath = upath.join(module.parent.filename, '../', moduleName);
|
||||||
const originalModule = jest.requireActual(absolutePath);
|
const originalModule = jest.requireActual(absolutePath) as any;
|
||||||
return {
|
return {
|
||||||
__esModule: true,
|
__esModule: true,
|
||||||
...originalModule,
|
...originalModule,
|
||||||
|
@ -44,6 +47,8 @@ export function partial<T>(obj: Partial<T>): T {
|
||||||
|
|
||||||
export const fs = mocked(_fs);
|
export const fs = mocked(_fs);
|
||||||
export const platform = mocked(_platform);
|
export const platform = mocked(_platform);
|
||||||
|
export const env = mocked(_env);
|
||||||
|
export const hostRules = mocked(_hostRules);
|
||||||
|
|
||||||
// Required because of isolatedModules
|
// Required because of isolatedModules
|
||||||
export type RenovateConfig = _RenovateConfig;
|
export type RenovateConfig = _RenovateConfig;
|
||||||
|
@ -75,14 +80,22 @@ export const replacingSerializer = (
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export function addReplacingSerializer(from: string, to: string): void {
|
||||||
|
expect.addSnapshotSerializer(replacingSerializer(from, to));
|
||||||
|
}
|
||||||
|
|
||||||
function toHash(buf: Buffer): string {
|
function toHash(buf: Buffer): string {
|
||||||
return crypto.createHash('sha256').update(buf).digest('hex');
|
return crypto.createHash('sha256').update(buf).digest('hex');
|
||||||
}
|
}
|
||||||
|
|
||||||
export const bufferSerializer = (): jest.SnapshotSerializerPlugin => ({
|
const bufferSerializer: jest.SnapshotSerializerPlugin = {
|
||||||
test: (value) => Buffer.isBuffer(value),
|
test: (value) => Buffer.isBuffer(value),
|
||||||
serialize: (val, config, indent, depth, refs, printer) => {
|
serialize: (val, config, indent, depth, refs, printer) => {
|
||||||
const replaced = toHash(val);
|
const replaced = toHash(val);
|
||||||
return printer(replaced, config, indent, depth, refs);
|
return printer(replaced, config, indent, depth, refs);
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
|
||||||
|
export function addBufferSerializer(): void {
|
||||||
|
expect.addSnapshotSerializer(bufferSerializer);
|
||||||
|
}
|
||||||
|
|
|
@ -946,7 +946,7 @@
|
||||||
jest-mock "^26.0.1"
|
jest-mock "^26.0.1"
|
||||||
jest-util "^26.0.1"
|
jest-util "^26.0.1"
|
||||||
|
|
||||||
"@jest/globals@^26.0.1":
|
"@jest/globals@26.0.1", "@jest/globals@^26.0.1":
|
||||||
version "26.0.1"
|
version "26.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/@jest/globals/-/globals-26.0.1.tgz#3f67b508a7ce62b6e6efc536f3d18ec9deb19a9c"
|
resolved "https://registry.yarnpkg.com/@jest/globals/-/globals-26.0.1.tgz#3f67b508a7ce62b6e6efc536f3d18ec9deb19a9c"
|
||||||
integrity sha512-iuucxOYB7BRCvT+TYBzUqUNuxFX1hqaR6G6IcGgEqkJ5x4htNKo1r7jk1ji9Zj8ZMiMw0oB5NaA7k5Tx6MVssA==
|
integrity sha512-iuucxOYB7BRCvT+TYBzUqUNuxFX1hqaR6G6IcGgEqkJ5x4htNKo1r7jk1ji9Zj8ZMiMw0oB5NaA7k5Tx6MVssA==
|
||||||
|
|
Loading…
Reference in a new issue