2019-12-19 05:10:39 +00:00
|
|
|
import { exec as _exec } from 'child_process';
|
2020-05-01 16:03:48 +00:00
|
|
|
import _fs from 'fs-extra';
|
|
|
|
import { join } from 'upath';
|
|
|
|
import { envMock, mockExecAll } from '../../../test/execUtil';
|
2020-05-25 14:26:09 +00:00
|
|
|
import { mocked, platform } from '../../../test/util';
|
2020-02-10 05:41:37 +00:00
|
|
|
import { setUtilConfig } from '../../util';
|
2020-02-05 00:14:31 +00:00
|
|
|
import { BinarySource } from '../../util/exec/common';
|
2020-05-25 14:26:09 +00:00
|
|
|
import * as docker from '../../util/exec/docker';
|
2020-05-01 16:03:48 +00:00
|
|
|
import * as _env from '../../util/exec/env';
|
2020-07-03 14:47:00 +00:00
|
|
|
import { StatusResult } from '../../util/git';
|
2020-05-25 14:26:09 +00:00
|
|
|
import * as _hostRules from '../../util/host-rules';
|
2020-05-01 16:03:48 +00:00
|
|
|
import * as gomod from './artifacts';
|
2019-07-25 06:17:19 +00:00
|
|
|
|
2018-10-01 11:50:36 +00:00
|
|
|
jest.mock('fs-extra');
|
2019-12-19 05:10:39 +00:00
|
|
|
jest.mock('child_process');
|
2020-02-05 00:14:31 +00:00
|
|
|
jest.mock('../../util/exec/env');
|
|
|
|
jest.mock('../../util/host-rules');
|
2020-06-12 16:15:17 +00:00
|
|
|
jest.mock('../../util/http');
|
2018-10-01 11:50:36 +00:00
|
|
|
|
2019-12-19 05:10:39 +00:00
|
|
|
const fs: jest.Mocked<typeof _fs> = _fs as any;
|
|
|
|
const exec: jest.Mock<typeof _exec> = _exec as any;
|
2020-01-10 14:18:41 +00:00
|
|
|
const env = mocked(_env);
|
2020-05-25 14:26:09 +00:00
|
|
|
const hostRules = mocked(_hostRules);
|
2019-07-17 08:14:56 +00:00
|
|
|
|
2018-10-05 10:34:51 +00:00
|
|
|
const gomod1 = `module github.com/renovate-tests/gomod1
|
|
|
|
|
|
|
|
require github.com/pkg/errors v0.7.0
|
|
|
|
require github.com/aws/aws-sdk-go v1.15.21
|
|
|
|
require github.com/davecgh/go-spew v1.0.0
|
|
|
|
require golang.org/x/foo v1.0.0
|
|
|
|
require github.com/rarkins/foo abcdef1
|
|
|
|
require gopkg.in/russross/blackfriday.v1 v1.0.0
|
|
|
|
|
|
|
|
replace github.com/pkg/errors => ../errors
|
|
|
|
`;
|
|
|
|
|
2018-10-01 11:50:36 +00:00
|
|
|
const config = {
|
2020-02-10 05:41:37 +00:00
|
|
|
// `join` fixes Windows CI
|
|
|
|
localDir: join('/tmp/github/some/repo'),
|
|
|
|
cacheDir: join('/tmp/renovate/cache'),
|
|
|
|
dockerUser: 'foobar',
|
2020-06-03 08:39:29 +00:00
|
|
|
compatibility: { go: '1.14' },
|
2020-02-10 05:41:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const goEnv = {
|
|
|
|
GONOSUMDB: '1',
|
|
|
|
GOPROXY: 'proxy.example.com',
|
|
|
|
CGO_ENABLED: '1',
|
2018-10-01 11:50:36 +00:00
|
|
|
};
|
|
|
|
|
2019-06-09 06:18:41 +00:00
|
|
|
describe('.updateArtifacts()', () => {
|
2020-04-09 10:47:48 +00:00
|
|
|
beforeEach(async () => {
|
2018-10-01 11:50:36 +00:00
|
|
|
jest.resetAllMocks();
|
2020-01-02 15:30:40 +00:00
|
|
|
jest.resetModules();
|
|
|
|
|
2020-03-20 08:40:02 +00:00
|
|
|
delete process.env.GOPATH;
|
2020-02-10 05:41:37 +00:00
|
|
|
env.getChildProcessEnv.mockReturnValue({ ...envMock.basic, ...goEnv });
|
2020-04-09 10:47:48 +00:00
|
|
|
await setUtilConfig(config);
|
2020-05-25 14:26:09 +00:00
|
|
|
docker.resetPrefetchedImages();
|
2018-10-01 11:50:36 +00:00
|
|
|
});
|
|
|
|
it('returns if no go.sum found', async () => {
|
2020-01-02 15:30:40 +00:00
|
|
|
const execSnapshots = mockExecAll(exec);
|
2019-06-09 06:18:41 +00:00
|
|
|
expect(
|
2020-01-17 11:18:34 +00:00
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config,
|
|
|
|
})
|
2019-06-09 06:18:41 +00:00
|
|
|
).toBeNull();
|
2020-01-02 15:30:40 +00:00
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
2018-10-01 11:50:36 +00:00
|
|
|
});
|
|
|
|
it('returns null if unchanged', async () => {
|
2020-05-13 10:45:02 +00:00
|
|
|
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
|
2020-01-02 15:30:40 +00:00
|
|
|
const execSnapshots = mockExecAll(exec);
|
2019-12-19 05:10:39 +00:00
|
|
|
platform.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: [],
|
|
|
|
} as StatusResult);
|
2019-06-09 06:18:41 +00:00
|
|
|
expect(
|
2020-01-17 11:18:34 +00:00
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config,
|
|
|
|
})
|
2019-06-09 06:18:41 +00:00
|
|
|
).toBeNull();
|
2020-01-02 15:30:40 +00:00
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
2018-10-01 11:50:36 +00:00
|
|
|
});
|
|
|
|
it('returns updated go.sum', async () => {
|
2020-05-13 10:45:02 +00:00
|
|
|
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
|
2020-01-02 15:30:40 +00:00
|
|
|
const execSnapshots = mockExecAll(exec);
|
2019-12-19 05:10:39 +00:00
|
|
|
platform.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
|
|
|
fs.readFile.mockReturnValueOnce('New go.sum' as any);
|
2018-10-05 10:34:51 +00:00
|
|
|
expect(
|
2020-01-17 11:18:34 +00:00
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config,
|
|
|
|
})
|
2018-10-05 10:34:51 +00:00
|
|
|
).not.toBeNull();
|
2020-01-02 15:30:40 +00:00
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
2018-10-01 11:50:36 +00:00
|
|
|
});
|
2019-04-08 06:15:37 +00:00
|
|
|
it('supports docker mode without credentials', async () => {
|
2020-05-25 14:26:09 +00:00
|
|
|
jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce();
|
2020-04-09 10:47:48 +00:00
|
|
|
await setUtilConfig({ ...config, binarySource: BinarySource.Docker });
|
2020-05-13 10:45:02 +00:00
|
|
|
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
|
2020-01-02 15:30:40 +00:00
|
|
|
const execSnapshots = mockExecAll(exec);
|
2019-12-19 05:10:39 +00:00
|
|
|
platform.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
|
|
|
fs.readFile.mockReturnValueOnce('New go.sum' as any);
|
2019-04-08 06:15:37 +00:00
|
|
|
expect(
|
2020-01-17 11:18:34 +00:00
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config: {
|
|
|
|
...config,
|
2020-01-20 15:50:32 +00:00
|
|
|
binarySource: BinarySource.Docker,
|
2020-01-17 11:18:34 +00:00
|
|
|
},
|
2019-04-08 06:15:37 +00:00
|
|
|
})
|
|
|
|
).not.toBeNull();
|
2020-01-02 15:30:40 +00:00
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
2019-04-08 06:15:37 +00:00
|
|
|
});
|
2019-12-16 16:12:53 +00:00
|
|
|
it('supports global mode', async () => {
|
2020-05-13 10:45:02 +00:00
|
|
|
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
|
2020-01-02 15:30:40 +00:00
|
|
|
const execSnapshots = mockExecAll(exec);
|
2019-12-19 05:10:39 +00:00
|
|
|
platform.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
|
|
|
fs.readFile.mockReturnValueOnce('New go.sum' as any);
|
2019-12-16 16:12:53 +00:00
|
|
|
expect(
|
2020-01-17 11:18:34 +00:00
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config: {
|
|
|
|
...config,
|
2020-01-20 15:50:32 +00:00
|
|
|
binarySource: BinarySource.Global,
|
2020-01-17 11:18:34 +00:00
|
|
|
},
|
2019-12-16 16:12:53 +00:00
|
|
|
})
|
|
|
|
).not.toBeNull();
|
2020-01-02 15:30:40 +00:00
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
2019-12-16 16:12:53 +00:00
|
|
|
});
|
2019-04-08 06:15:37 +00:00
|
|
|
it('supports docker mode with credentials', async () => {
|
2020-05-25 14:26:09 +00:00
|
|
|
jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce();
|
2020-04-09 10:47:48 +00:00
|
|
|
await setUtilConfig({ ...config, binarySource: BinarySource.Docker });
|
2019-12-19 05:10:39 +00:00
|
|
|
hostRules.find.mockReturnValueOnce({
|
2019-04-08 06:15:37 +00:00
|
|
|
token: 'some-token',
|
|
|
|
});
|
2020-05-13 10:45:02 +00:00
|
|
|
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
|
2020-01-02 15:30:40 +00:00
|
|
|
const execSnapshots = mockExecAll(exec);
|
2019-12-19 05:10:39 +00:00
|
|
|
platform.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
|
|
|
fs.readFile.mockReturnValueOnce('New go.sum' as any);
|
2018-10-01 11:50:36 +00:00
|
|
|
expect(
|
2020-01-17 11:18:34 +00:00
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config: {
|
|
|
|
...config,
|
2020-01-20 15:50:32 +00:00
|
|
|
binarySource: BinarySource.Docker,
|
2020-01-17 11:18:34 +00:00
|
|
|
},
|
2018-10-01 11:50:36 +00:00
|
|
|
})
|
|
|
|
).not.toBeNull();
|
2020-01-02 15:30:40 +00:00
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
2018-10-01 11:50:36 +00:00
|
|
|
});
|
2020-01-02 15:30:40 +00:00
|
|
|
it('supports docker mode with credentials and appMode enabled', async () => {
|
2020-05-25 14:26:09 +00:00
|
|
|
jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce();
|
2020-04-09 10:47:48 +00:00
|
|
|
await setUtilConfig({ ...config, binarySource: BinarySource.Docker });
|
2019-12-19 05:10:39 +00:00
|
|
|
hostRules.find.mockReturnValueOnce({
|
2019-05-24 13:01:07 +00:00
|
|
|
token: 'some-token',
|
|
|
|
});
|
2020-05-13 10:45:02 +00:00
|
|
|
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
|
2020-01-02 15:30:40 +00:00
|
|
|
const execSnapshots = mockExecAll(exec);
|
2019-12-19 05:10:39 +00:00
|
|
|
platform.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
|
|
|
fs.readFile.mockResolvedValueOnce('New go.sum 1' as any);
|
2020-05-13 10:45:02 +00:00
|
|
|
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
|
2019-12-19 05:10:39 +00:00
|
|
|
fs.readFile.mockResolvedValueOnce('New go.sum 2' as any);
|
|
|
|
fs.readFile.mockResolvedValueOnce('New go.sum 3' as any);
|
2019-05-24 13:01:07 +00:00
|
|
|
try {
|
|
|
|
global.appMode = true;
|
|
|
|
expect(
|
2020-01-17 11:18:34 +00:00
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config: {
|
|
|
|
...config,
|
2020-01-20 15:50:32 +00:00
|
|
|
binarySource: BinarySource.Docker,
|
2020-01-17 11:18:34 +00:00
|
|
|
postUpdateOptions: ['gomodTidy'],
|
|
|
|
},
|
2019-05-24 13:01:07 +00:00
|
|
|
})
|
2019-05-25 04:23:44 +00:00
|
|
|
).not.toBeNull();
|
2020-01-02 15:30:40 +00:00
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
2019-05-24 13:01:07 +00:00
|
|
|
} finally {
|
|
|
|
delete global.appMode;
|
|
|
|
}
|
|
|
|
});
|
2018-10-01 11:50:36 +00:00
|
|
|
it('catches errors', async () => {
|
2020-01-02 15:30:40 +00:00
|
|
|
const execSnapshots = mockExecAll(exec);
|
2020-05-13 10:45:02 +00:00
|
|
|
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
|
2019-12-19 05:10:39 +00:00
|
|
|
fs.outputFile.mockImplementationOnce(() => {
|
2018-10-02 10:44:56 +00:00
|
|
|
throw new Error('This update totally doesnt work');
|
2018-10-01 11:50:36 +00:00
|
|
|
});
|
2018-10-02 10:44:56 +00:00
|
|
|
expect(
|
2020-01-17 11:18:34 +00:00
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config,
|
|
|
|
})
|
2018-10-02 10:44:56 +00:00
|
|
|
).toMatchSnapshot();
|
2020-01-02 15:30:40 +00:00
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
2018-10-01 11:50:36 +00:00
|
|
|
});
|
|
|
|
});
|