2020-05-01 16:03:48 +00:00
|
|
|
import { join } from 'upath';
|
2022-07-22 07:42:30 +00:00
|
|
|
import { envMock, mockExecAll } from '../../../../test/exec-util';
|
2022-03-03 09:35:26 +00:00
|
|
|
import { env, fs, git, mocked } from '../../../../test/util';
|
|
|
|
import { GlobalConfig } from '../../../config/global';
|
|
|
|
import type { RepoGlobalConfig } from '../../../config/types';
|
|
|
|
import { PlatformId } from '../../../constants/platforms';
|
|
|
|
import * as docker from '../../../util/exec/docker';
|
|
|
|
import type { StatusResult } from '../../../util/git/types';
|
|
|
|
import * as _hostRules from '../../../util/host-rules';
|
2021-05-17 13:21:28 +00:00
|
|
|
import type { UpdateArtifactsConfig } from '../types';
|
2022-06-20 15:05:39 +00:00
|
|
|
import * as gomod from '.';
|
2019-07-25 06:17:19 +00:00
|
|
|
|
2022-03-03 09:35:26 +00:00
|
|
|
jest.mock('../../../util/exec/env');
|
|
|
|
jest.mock('../../../util/git');
|
|
|
|
jest.mock('../../../util/host-rules');
|
|
|
|
jest.mock('../../../util/http');
|
|
|
|
jest.mock('../../../util/fs');
|
2018-10-01 11:50:36 +00:00
|
|
|
|
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
|
2022-05-29 17:11:12 +00:00
|
|
|
require go.uber.org/zap v1.20.0
|
2018-10-05 10:34:51 +00:00
|
|
|
|
|
|
|
replace github.com/pkg/errors => ../errors
|
2022-02-09 09:38:37 +00:00
|
|
|
|
|
|
|
replace (golang.org/x/foo => github.com/pravesht/gocql v0.0.0)
|
|
|
|
|
2022-05-29 17:11:12 +00:00
|
|
|
replace (
|
|
|
|
// TODO: this comment breaks renovatebot (>v0.11.1)
|
|
|
|
go.uber.org/zap => go.uber.org/zap v1.21.0
|
|
|
|
)
|
|
|
|
|
2018-10-05 10:34:51 +00:00
|
|
|
`;
|
|
|
|
|
2021-08-16 16:00:51 +00:00
|
|
|
const adminConfig: RepoGlobalConfig = {
|
2020-02-10 05:41:37 +00:00
|
|
|
// `join` fixes Windows CI
|
2021-05-26 11:22:16 +00:00
|
|
|
localDir: join('/tmp/github/some/repo'),
|
2020-02-10 05:41:37 +00:00
|
|
|
cacheDir: join('/tmp/renovate/cache'),
|
2021-05-17 13:21:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const config: UpdateArtifactsConfig = {
|
2020-09-30 09:02:25 +00:00
|
|
|
constraints: { go: '1.14' },
|
2022-05-28 08:19:36 +00:00
|
|
|
postUpdateOptions: ['gomodMassage'],
|
2020-02-10 05:41:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const goEnv = {
|
|
|
|
GONOSUMDB: '1',
|
|
|
|
GOPROXY: 'proxy.example.com',
|
2021-07-30 10:23:35 +00:00
|
|
|
GOPRIVATE: 'private.example.com/*',
|
2021-03-17 05:01:34 +00:00
|
|
|
GONOPROXY: 'noproxy.example.com/*',
|
2022-06-21 09:23:58 +00:00
|
|
|
GOINSECURE: 'insecure.example.com/*',
|
2020-02-10 05:41:37 +00:00
|
|
|
CGO_ENABLED: '1',
|
2018-10-01 11:50:36 +00:00
|
|
|
};
|
|
|
|
|
2022-03-03 09:35:26 +00:00
|
|
|
describe('modules/manager/gomod/artifacts', () => {
|
2021-06-02 06:50:23 +00:00
|
|
|
beforeEach(() => {
|
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 });
|
2021-11-23 20:10:45 +00:00
|
|
|
GlobalConfig.set(adminConfig);
|
2020-05-25 14:26:09 +00:00
|
|
|
docker.resetPrefetchedImages();
|
2022-08-12 05:12:30 +00:00
|
|
|
hostRules.getAll.mockReturnValue([]);
|
2018-10-01 11:50:36 +00:00
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2021-05-17 13:21:28 +00:00
|
|
|
afterEach(() => {
|
2021-11-23 20:10:45 +00:00
|
|
|
GlobalConfig.reset();
|
2021-05-17 13:21:28 +00:00
|
|
|
});
|
2021-12-15 10:50:09 +00:00
|
|
|
|
2018-10-01 11:50:36 +00:00
|
|
|
it('returns if no go.sum found', async () => {
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
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
|
|
|
});
|
2021-12-15 10:50:09 +00:00
|
|
|
|
2018-10-01 11:50:36 +00:00
|
|
|
it('returns null if unchanged', async () => {
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2020-07-04 11:52:33 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
2022-06-20 15:05:39 +00:00
|
|
|
modified: [] as string[],
|
2019-12-19 05:10:39 +00:00
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
|
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
|
|
|
});
|
2021-12-15 10:50:09 +00:00
|
|
|
|
2018-10-01 11:50:36 +00:00
|
|
|
it('returns updated go.sum', async () => {
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2020-07-04 11:52:33 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
2019-12-19 05:10:39 +00:00
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
|
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
|
|
|
});
|
2021-12-15 10:50:09 +00:00
|
|
|
|
2020-08-05 07:11:56 +00:00
|
|
|
it('supports vendor directory update', async () => {
|
|
|
|
const foo = join('vendor/github.com/foo/foo/go.mod');
|
|
|
|
const bar = join('vendor/github.com/bar/bar/go.mod');
|
|
|
|
const baz = join('vendor/github.com/baz/baz/go.mod');
|
|
|
|
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce('modules.txt content'); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2020-08-05 07:11:56 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum', foo],
|
|
|
|
not_added: [bar],
|
|
|
|
deleted: [baz],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Foo go.sum');
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Bar go.sum');
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.mod');
|
2020-08-05 07:11:56 +00:00
|
|
|
const res = await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config: {
|
|
|
|
...config,
|
|
|
|
postUpdateOptions: ['gomodTidy'],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(res).not.toBeNull();
|
|
|
|
expect(res?.map(({ file }) => file)).toEqual([
|
2022-01-21 05:47:49 +00:00
|
|
|
{ type: 'addition', path: 'go.sum', contents: 'New go.sum' },
|
|
|
|
{ type: 'addition', path: foo, contents: 'Foo go.sum' },
|
|
|
|
{ type: 'addition', path: bar, contents: 'Bar go.sum' },
|
|
|
|
{ type: 'deletion', path: baz },
|
|
|
|
{ type: 'addition', path: 'go.mod', contents: 'New go.mod' },
|
2020-08-05 07:11:56 +00:00
|
|
|
]);
|
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
|
|
|
});
|
2021-12-15 10:50:09 +00:00
|
|
|
|
2019-04-08 06:15:37 +00:00
|
|
|
it('supports docker mode without credentials', async () => {
|
2021-11-23 20:10:45 +00:00
|
|
|
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2020-07-04 11:52:33 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
2019-12-19 05:10:39 +00:00
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
|
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,
|
2021-06-02 06:50:23 +00:00
|
|
|
config,
|
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
|
|
|
});
|
2021-12-15 10:50:09 +00:00
|
|
|
|
2019-12-16 16:12:53 +00:00
|
|
|
it('supports global mode', async () => {
|
2021-11-23 20:10:45 +00:00
|
|
|
GlobalConfig.set({ ...adminConfig, binarySource: 'global' });
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2020-07-04 11:52:33 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
2019-12-19 05:10:39 +00:00
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
|
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,
|
2021-06-02 06:50:23 +00:00
|
|
|
config,
|
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
|
|
|
});
|
2021-12-15 10:50:09 +00:00
|
|
|
|
2019-04-08 06:15:37 +00:00
|
|
|
it('supports docker mode with credentials', async () => {
|
2021-11-23 20:10:45 +00:00
|
|
|
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
|
2019-12-19 05:10:39 +00:00
|
|
|
hostRules.find.mockReturnValueOnce({
|
2019-04-08 06:15:37 +00:00
|
|
|
token: 'some-token',
|
|
|
|
});
|
2022-08-12 05:12:30 +00:00
|
|
|
hostRules.getAll.mockReturnValueOnce([
|
|
|
|
{
|
|
|
|
token: 'some-token',
|
|
|
|
hostType: PlatformId.Github,
|
|
|
|
matchHost: 'api.github.com',
|
|
|
|
},
|
|
|
|
{ token: 'some-other-token', matchHost: 'https://gitea.com' },
|
|
|
|
]);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2020-07-04 11:52:33 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
2019-12-19 05:10:39 +00:00
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
|
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,
|
2021-06-02 06:50:23 +00:00
|
|
|
config,
|
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
|
|
|
});
|
2021-10-31 07:06:59 +00:00
|
|
|
|
|
|
|
it('supports docker mode with 2 credentials', async () => {
|
2021-11-23 20:10:45 +00:00
|
|
|
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
|
2021-10-31 07:06:59 +00:00
|
|
|
hostRules.find.mockReturnValueOnce({
|
|
|
|
token: 'some-token',
|
|
|
|
});
|
|
|
|
hostRules.getAll.mockReturnValueOnce([
|
2022-08-12 05:12:30 +00:00
|
|
|
{
|
|
|
|
token: 'some-token',
|
|
|
|
hostType: PlatformId.Github,
|
|
|
|
matchHost: 'api.github.com',
|
|
|
|
},
|
2021-10-31 07:06:59 +00:00
|
|
|
{
|
|
|
|
token: 'some-enterprise-token',
|
|
|
|
matchHost: 'github.enterprise.com',
|
2021-12-21 13:09:49 +00:00
|
|
|
hostType: PlatformId.Github,
|
2021-10-31 07:06:59 +00:00
|
|
|
},
|
|
|
|
]);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2021-10-31 07:06:59 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
|
2021-10-31 07:06:59 +00:00
|
|
|
expect(
|
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config,
|
|
|
|
})
|
|
|
|
).not.toBeNull();
|
2022-08-12 05:12:30 +00:00
|
|
|
expect(execSnapshots).toMatchObject([
|
|
|
|
{ cmd: 'docker pull renovate/go:latest' },
|
|
|
|
{ cmd: 'docker ps --filter name=renovate_go -aq' },
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
env: {
|
|
|
|
GIT_CONFIG_COUNT: '6',
|
|
|
|
GIT_CONFIG_KEY_0:
|
|
|
|
'url.https://ssh:some-token@github.com/.insteadOf',
|
|
|
|
GIT_CONFIG_KEY_1:
|
|
|
|
'url.https://git:some-token@github.com/.insteadOf',
|
|
|
|
GIT_CONFIG_KEY_2: 'url.https://some-token@github.com/.insteadOf',
|
|
|
|
GIT_CONFIG_KEY_3:
|
|
|
|
'url.https://ssh:some-enterprise-token@github.enterprise.com/.insteadOf',
|
|
|
|
GIT_CONFIG_KEY_4:
|
|
|
|
'url.https://git:some-enterprise-token@github.enterprise.com/.insteadOf',
|
|
|
|
GIT_CONFIG_KEY_5:
|
|
|
|
'url.https://some-enterprise-token@github.enterprise.com/.insteadOf',
|
|
|
|
GIT_CONFIG_VALUE_0: 'ssh://git@github.com/',
|
|
|
|
GIT_CONFIG_VALUE_1: 'git@github.com:',
|
|
|
|
GIT_CONFIG_VALUE_2: 'https://github.com/',
|
|
|
|
GIT_CONFIG_VALUE_3: 'ssh://git@github.enterprise.com/',
|
|
|
|
GIT_CONFIG_VALUE_4: 'git@github.enterprise.com:',
|
|
|
|
GIT_CONFIG_VALUE_5: 'https://github.enterprise.com/',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
2021-10-31 07:06:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('supports docker mode with single credential', async () => {
|
2021-11-23 20:10:45 +00:00
|
|
|
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
|
2021-10-31 07:06:59 +00:00
|
|
|
hostRules.getAll.mockReturnValueOnce([
|
|
|
|
{
|
|
|
|
token: 'some-enterprise-token',
|
|
|
|
matchHost: 'gitlab.enterprise.com',
|
2021-12-21 13:09:49 +00:00
|
|
|
hostType: PlatformId.Gitlab,
|
2021-10-31 07:06:59 +00:00
|
|
|
},
|
|
|
|
]);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2021-10-31 07:06:59 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
|
2021-10-31 07:06:59 +00:00
|
|
|
expect(
|
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config,
|
|
|
|
})
|
|
|
|
).not.toBeNull();
|
|
|
|
expect(execSnapshots).toEqual(
|
|
|
|
expect.arrayContaining([
|
|
|
|
expect.objectContaining({
|
|
|
|
options: expect.objectContaining({
|
|
|
|
env: expect.objectContaining({
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_COUNT: '3',
|
2021-10-31 07:06:59 +00:00
|
|
|
GIT_CONFIG_KEY_0:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://gitlab-ci-token:some-enterprise-token@gitlab.enterprise.com/.insteadOf',
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_KEY_1:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://gitlab-ci-token:some-enterprise-token@gitlab.enterprise.com/.insteadOf',
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_KEY_2:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://gitlab-ci-token:some-enterprise-token@gitlab.enterprise.com/.insteadOf',
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_VALUE_0: 'ssh://git@gitlab.enterprise.com/',
|
|
|
|
GIT_CONFIG_VALUE_1: 'git@gitlab.enterprise.com:',
|
|
|
|
GIT_CONFIG_VALUE_2: 'https://gitlab.enterprise.com/',
|
2021-10-31 07:06:59 +00:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('supports docker mode with multiple credentials for different paths', async () => {
|
2021-11-23 20:10:45 +00:00
|
|
|
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
|
2021-10-31 07:06:59 +00:00
|
|
|
hostRules.getAll.mockReturnValueOnce([
|
|
|
|
{
|
|
|
|
token: 'some-enterprise-token-repo1',
|
|
|
|
matchHost: 'https://gitlab.enterprise.com/repo1',
|
2021-12-21 13:09:49 +00:00
|
|
|
hostType: PlatformId.Gitlab,
|
2021-10-31 07:06:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
token: 'some-enterprise-token-repo2',
|
|
|
|
matchHost: 'https://gitlab.enterprise.com/repo2',
|
2021-12-21 13:09:49 +00:00
|
|
|
hostType: PlatformId.Gitlab,
|
2021-10-31 07:06:59 +00:00
|
|
|
},
|
|
|
|
]);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2021-10-31 07:06:59 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
|
2021-10-31 07:06:59 +00:00
|
|
|
expect(
|
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config,
|
|
|
|
})
|
|
|
|
).not.toBeNull();
|
|
|
|
expect(execSnapshots).toEqual(
|
|
|
|
expect.arrayContaining([
|
|
|
|
expect.objectContaining({
|
|
|
|
options: expect.objectContaining({
|
|
|
|
env: expect.objectContaining({
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_COUNT: '6',
|
2021-10-31 07:06:59 +00:00
|
|
|
GIT_CONFIG_KEY_0:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://gitlab-ci-token:some-enterprise-token-repo1@gitlab.enterprise.com/repo1.insteadOf',
|
2021-10-31 07:06:59 +00:00
|
|
|
GIT_CONFIG_KEY_1:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://gitlab-ci-token:some-enterprise-token-repo1@gitlab.enterprise.com/repo1.insteadOf',
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_KEY_2:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://gitlab-ci-token:some-enterprise-token-repo1@gitlab.enterprise.com/repo1.insteadOf',
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_KEY_3:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://gitlab-ci-token:some-enterprise-token-repo2@gitlab.enterprise.com/repo2.insteadOf',
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_KEY_4:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://gitlab-ci-token:some-enterprise-token-repo2@gitlab.enterprise.com/repo2.insteadOf',
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_KEY_5:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://gitlab-ci-token:some-enterprise-token-repo2@gitlab.enterprise.com/repo2.insteadOf',
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_VALUE_0: 'ssh://git@gitlab.enterprise.com/repo1',
|
|
|
|
GIT_CONFIG_VALUE_1: 'git@gitlab.enterprise.com:repo1',
|
|
|
|
GIT_CONFIG_VALUE_2: 'https://gitlab.enterprise.com/repo1',
|
|
|
|
GIT_CONFIG_VALUE_3: 'ssh://git@gitlab.enterprise.com/repo2',
|
|
|
|
GIT_CONFIG_VALUE_4: 'git@gitlab.enterprise.com:repo2',
|
|
|
|
GIT_CONFIG_VALUE_5: 'https://gitlab.enterprise.com/repo2',
|
2021-10-31 07:06:59 +00:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('supports docker mode and ignores non http credentials', async () => {
|
2021-11-23 20:10:45 +00:00
|
|
|
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
|
2021-10-31 07:06:59 +00:00
|
|
|
hostRules.getAll.mockReturnValueOnce([
|
|
|
|
{
|
|
|
|
token: 'some-token',
|
|
|
|
matchHost: 'ssh://github.enterprise.com',
|
2021-12-21 13:09:49 +00:00
|
|
|
hostType: PlatformId.Github,
|
2021-10-31 07:06:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
token: 'some-gitlab-token',
|
|
|
|
matchHost: 'gitlab.enterprise.com',
|
2021-12-21 13:09:49 +00:00
|
|
|
hostType: PlatformId.Gitlab,
|
2021-10-31 07:06:59 +00:00
|
|
|
},
|
|
|
|
]);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2021-10-31 07:06:59 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
|
2021-10-31 07:06:59 +00:00
|
|
|
expect(
|
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config,
|
|
|
|
})
|
|
|
|
).not.toBeNull();
|
|
|
|
expect(execSnapshots).toEqual(
|
|
|
|
expect.arrayContaining([
|
|
|
|
expect.objectContaining({
|
|
|
|
options: expect.objectContaining({
|
|
|
|
env: expect.objectContaining({
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_COUNT: '3',
|
2021-10-31 07:06:59 +00:00
|
|
|
GIT_CONFIG_KEY_0:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/.insteadOf',
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_KEY_1:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/.insteadOf',
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_KEY_2:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/.insteadOf',
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_VALUE_0: 'ssh://git@gitlab.enterprise.com/',
|
|
|
|
GIT_CONFIG_VALUE_1: 'git@gitlab.enterprise.com:',
|
|
|
|
GIT_CONFIG_VALUE_2: 'https://gitlab.enterprise.com/',
|
2021-10-31 07:06:59 +00:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('supports docker mode with many credentials', async () => {
|
2021-11-23 20:10:45 +00:00
|
|
|
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
|
2021-10-31 07:06:59 +00:00
|
|
|
hostRules.find.mockReturnValueOnce({
|
|
|
|
token: 'some-token',
|
|
|
|
});
|
|
|
|
hostRules.getAll.mockReturnValueOnce([
|
|
|
|
{
|
|
|
|
token: 'some-token',
|
|
|
|
matchHost: 'api.github.com',
|
2021-12-21 13:09:49 +00:00
|
|
|
hostType: PlatformId.Github,
|
2021-10-31 07:06:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
token: 'some-enterprise-token',
|
|
|
|
matchHost: 'github.enterprise.com',
|
2021-12-21 13:09:49 +00:00
|
|
|
hostType: PlatformId.Github,
|
2021-10-31 07:06:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
token: 'some-gitlab-token',
|
|
|
|
matchHost: 'gitlab.enterprise.com',
|
2021-12-21 13:09:49 +00:00
|
|
|
hostType: PlatformId.Gitlab,
|
2021-10-31 07:06:59 +00:00
|
|
|
},
|
|
|
|
]);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2021-10-31 07:06:59 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
|
2021-10-31 07:06:59 +00:00
|
|
|
expect(
|
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config,
|
|
|
|
})
|
|
|
|
).not.toBeNull();
|
|
|
|
expect(execSnapshots).toEqual(
|
|
|
|
expect.arrayContaining([
|
|
|
|
expect.objectContaining({
|
|
|
|
options: expect.objectContaining({
|
|
|
|
env: expect.objectContaining({
|
2022-08-12 05:12:30 +00:00
|
|
|
GIT_CONFIG_COUNT: '9',
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_KEY_0:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://ssh:some-token@github.com/.insteadOf',
|
2021-10-31 07:06:59 +00:00
|
|
|
GIT_CONFIG_KEY_1:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://git:some-token@github.com/.insteadOf',
|
|
|
|
GIT_CONFIG_KEY_2: 'url.https://some-token@github.com/.insteadOf',
|
2021-10-31 07:06:59 +00:00
|
|
|
GIT_CONFIG_KEY_3:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://ssh:some-enterprise-token@github.enterprise.com/.insteadOf',
|
2022-08-12 05:12:30 +00:00
|
|
|
GIT_CONFIG_KEY_4:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://git:some-enterprise-token@github.enterprise.com/.insteadOf',
|
2022-08-12 05:12:30 +00:00
|
|
|
GIT_CONFIG_KEY_5:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://some-enterprise-token@github.enterprise.com/.insteadOf',
|
2022-08-12 05:12:30 +00:00
|
|
|
GIT_CONFIG_KEY_6:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/.insteadOf',
|
2022-08-12 05:12:30 +00:00
|
|
|
GIT_CONFIG_KEY_7:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/.insteadOf',
|
2022-08-12 05:12:30 +00:00
|
|
|
GIT_CONFIG_KEY_8:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/.insteadOf',
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_VALUE_0: 'ssh://git@github.com/',
|
|
|
|
GIT_CONFIG_VALUE_1: 'git@github.com:',
|
|
|
|
GIT_CONFIG_VALUE_2: 'https://github.com/',
|
2022-08-12 05:12:30 +00:00
|
|
|
GIT_CONFIG_VALUE_3: 'ssh://git@github.enterprise.com/',
|
|
|
|
GIT_CONFIG_VALUE_4: 'git@github.enterprise.com:',
|
|
|
|
GIT_CONFIG_VALUE_5: 'https://github.enterprise.com/',
|
|
|
|
GIT_CONFIG_VALUE_6: 'ssh://git@gitlab.enterprise.com/',
|
|
|
|
GIT_CONFIG_VALUE_7: 'git@gitlab.enterprise.com:',
|
|
|
|
GIT_CONFIG_VALUE_8: 'https://gitlab.enterprise.com/',
|
2021-10-31 07:06:59 +00:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('supports docker mode and ignores non git credentials', async () => {
|
2021-11-23 20:10:45 +00:00
|
|
|
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
|
2021-10-31 07:06:59 +00:00
|
|
|
hostRules.find.mockReturnValueOnce({
|
|
|
|
token: 'some-token',
|
|
|
|
});
|
|
|
|
hostRules.getAll.mockReturnValueOnce([
|
|
|
|
{
|
|
|
|
token: 'some-enterprise-token',
|
|
|
|
matchHost: 'github.enterprise.com',
|
|
|
|
hostType: 'npm',
|
|
|
|
},
|
|
|
|
]);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2021-10-31 07:06:59 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
|
2021-10-31 07:06:59 +00:00
|
|
|
expect(
|
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config,
|
|
|
|
})
|
|
|
|
).not.toBeNull();
|
|
|
|
expect(execSnapshots).toEqual(
|
|
|
|
expect.arrayContaining([
|
|
|
|
expect.objectContaining({
|
|
|
|
options: expect.objectContaining({
|
|
|
|
env: expect.objectContaining({
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_COUNT: '3',
|
|
|
|
GIT_CONFIG_KEY_0:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://ssh:some-token@github.com/.insteadOf',
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_KEY_1:
|
2022-02-07 20:00:53 +00:00
|
|
|
'url.https://git:some-token@github.com/.insteadOf',
|
|
|
|
GIT_CONFIG_KEY_2: 'url.https://some-token@github.com/.insteadOf',
|
2022-02-05 07:50:48 +00:00
|
|
|
GIT_CONFIG_VALUE_0: 'ssh://git@github.com/',
|
|
|
|
GIT_CONFIG_VALUE_1: 'git@github.com:',
|
|
|
|
GIT_CONFIG_VALUE_2: 'https://github.com/',
|
2021-10-31 07:06:59 +00:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-08-17 12:14:19 +00:00
|
|
|
it('supports docker mode with goModTidy', async () => {
|
2021-11-23 20:10:45 +00:00
|
|
|
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
|
2020-08-17 12:14:19 +00:00
|
|
|
hostRules.find.mockReturnValueOnce({});
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2020-07-04 11:52:33 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
2019-12-19 05:10:39 +00:00
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum 1');
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum 2');
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum 3');
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.mod');
|
2020-08-17 12:14:19 +00:00
|
|
|
expect(
|
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config: {
|
|
|
|
...config,
|
|
|
|
postUpdateOptions: ['gomodTidy'],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
).not.toBeNull();
|
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
2019-05-24 13:01:07 +00:00
|
|
|
});
|
2021-12-15 10:50:09 +00:00
|
|
|
|
2022-01-14 13:39:01 +00:00
|
|
|
it('supports docker mode with gomodTidy1.17', async () => {
|
|
|
|
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
|
|
|
|
hostRules.find.mockReturnValueOnce({});
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2022-01-14 13:39:01 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum 1');
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum 2');
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.sum 3');
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce('New go.mod');
|
|
|
|
expect(
|
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config: {
|
|
|
|
...config,
|
|
|
|
postUpdateOptions: ['gomodTidy1.17'],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
).not.toBeNull();
|
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2018-10-01 11:50:36 +00:00
|
|
|
it('catches errors', async () => {
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.writeLocalFile.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,
|
|
|
|
})
|
2021-08-18 06:49:27 +00:00
|
|
|
).toEqual([
|
|
|
|
{
|
|
|
|
artifactError: {
|
|
|
|
lockFile: 'go.sum',
|
|
|
|
stderr: 'This update totally doesnt work',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
2020-01-02 15:30:40 +00:00
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
2018-10-01 11:50:36 +00:00
|
|
|
});
|
2021-12-15 10:50:09 +00:00
|
|
|
|
2021-03-27 06:02:32 +00:00
|
|
|
it('updates import paths with gomodUpdateImportPaths', async () => {
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2021-03-27 06:02:32 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum', 'main.go'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile
|
|
|
|
.mockResolvedValueOnce('New go.sum')
|
|
|
|
.mockResolvedValueOnce('New main.go')
|
|
|
|
.mockResolvedValueOnce('New go.mod');
|
2021-03-27 06:02:32 +00:00
|
|
|
expect(
|
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
2021-06-26 13:29:01 +00:00
|
|
|
updatedDeps: [{ depName: 'github.com/google/go-github/v24' }],
|
2021-03-27 06:02:32 +00:00
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config: {
|
|
|
|
...config,
|
|
|
|
updateType: 'major',
|
|
|
|
newMajor: 28,
|
|
|
|
postUpdateOptions: ['gomodUpdateImportPaths'],
|
|
|
|
},
|
|
|
|
})
|
2021-08-18 06:49:27 +00:00
|
|
|
).toEqual([
|
2022-01-21 05:47:49 +00:00
|
|
|
{ file: { type: 'addition', path: 'go.sum', contents: 'New go.sum' } },
|
|
|
|
{ file: { type: 'addition', path: 'main.go', contents: 'New main.go' } },
|
|
|
|
{ file: { type: 'addition', path: 'go.mod', contents: 'New go.mod' } },
|
2021-08-18 06:49:27 +00:00
|
|
|
]);
|
2021-03-27 06:02:32 +00:00
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
|
|
|
});
|
2021-12-15 10:50:09 +00:00
|
|
|
|
2021-03-27 06:02:32 +00:00
|
|
|
it('skips updating import paths with gomodUpdateImportPaths on v0 to v1', async () => {
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2021-03-27 06:02:32 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum', 'main.go'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile
|
|
|
|
.mockResolvedValueOnce('New go.sum')
|
|
|
|
.mockResolvedValueOnce('New go.mod');
|
2021-03-27 06:02:32 +00:00
|
|
|
expect(
|
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
2021-06-26 13:29:01 +00:00
|
|
|
updatedDeps: [{ depName: 'github.com/pkg/errors' }],
|
2021-03-27 06:02:32 +00:00
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config: {
|
|
|
|
...config,
|
|
|
|
updateType: 'major',
|
|
|
|
newMajor: 1,
|
|
|
|
postUpdateOptions: ['gomodUpdateImportPaths'],
|
|
|
|
},
|
|
|
|
})
|
2021-08-18 06:49:27 +00:00
|
|
|
).toEqual([
|
2022-01-21 05:47:49 +00:00
|
|
|
{ file: { type: 'addition', path: 'go.sum', contents: 'New go.sum' } },
|
|
|
|
{ file: { type: 'addition', path: 'go.mod', contents: 'New go.mod' } },
|
2021-08-18 06:49:27 +00:00
|
|
|
]);
|
2021-03-27 06:02:32 +00:00
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
|
|
|
});
|
2021-12-15 10:50:09 +00:00
|
|
|
|
2021-10-20 11:28:09 +00:00
|
|
|
it('skips gomodTidy without gomodUpdateImportPaths on major update', async () => {
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2021-10-20 11:28:09 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum', 'main.go'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile
|
|
|
|
.mockResolvedValueOnce('New go.sum')
|
|
|
|
.mockResolvedValueOnce('New main.go')
|
|
|
|
.mockResolvedValueOnce('New go.mod');
|
2021-10-20 11:28:09 +00:00
|
|
|
expect(
|
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [{ depName: 'github.com/google/go-github/v24' }],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config: {
|
|
|
|
...config,
|
|
|
|
updateType: 'major',
|
|
|
|
newMajor: 28,
|
|
|
|
postUpdateOptions: ['gomodTidy'],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
).toMatchSnapshot();
|
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
|
|
|
});
|
2021-12-15 10:50:09 +00:00
|
|
|
|
2021-10-20 11:28:09 +00:00
|
|
|
it('does not execute go mod tidy when none of gomodTidy and gomodUpdateImportPaths are set', async () => {
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2021-10-20 11:28:09 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum', 'main.go'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile
|
|
|
|
.mockResolvedValueOnce('New go.sum')
|
|
|
|
.mockResolvedValueOnce('New main.go')
|
|
|
|
.mockResolvedValueOnce('New go.mod');
|
2021-10-20 11:28:09 +00:00
|
|
|
expect(
|
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
|
|
|
updatedDeps: [{ depName: 'github.com/google/go-github/v24' }],
|
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config: {
|
|
|
|
...config,
|
|
|
|
updateType: 'major',
|
|
|
|
newMajor: 28,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
).toMatchSnapshot();
|
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
|
|
|
});
|
2021-12-15 10:50:09 +00:00
|
|
|
|
2021-03-27 06:02:32 +00:00
|
|
|
it('updates import paths with specific tool version from constraint', async () => {
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2021-03-27 06:02:32 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum', 'main.go'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile
|
|
|
|
.mockResolvedValueOnce('New go.sum')
|
|
|
|
.mockResolvedValueOnce('New main.go')
|
|
|
|
.mockResolvedValueOnce('New go.mod');
|
2021-03-27 06:02:32 +00:00
|
|
|
expect(
|
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
2021-06-26 13:29:01 +00:00
|
|
|
updatedDeps: [{ depName: 'github.com/google/go-github/v24' }],
|
2021-03-27 06:02:32 +00:00
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config: {
|
|
|
|
...config,
|
|
|
|
updateType: 'major',
|
|
|
|
newMajor: 28,
|
|
|
|
postUpdateOptions: ['gomodUpdateImportPaths'],
|
|
|
|
constraints: {
|
|
|
|
gomodMod: 'v1.2.3',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2021-08-18 06:49:27 +00:00
|
|
|
).toEqual([
|
2022-01-21 05:47:49 +00:00
|
|
|
{ file: { type: 'addition', path: 'go.sum', contents: 'New go.sum' } },
|
|
|
|
{ file: { type: 'addition', path: 'main.go', contents: 'New main.go' } },
|
|
|
|
{ file: { type: 'addition', path: 'go.mod', contents: 'New go.mod' } },
|
2021-08-18 06:49:27 +00:00
|
|
|
]);
|
2021-03-27 06:02:32 +00:00
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
|
|
|
});
|
2021-12-15 10:50:09 +00:00
|
|
|
|
2021-03-27 06:02:32 +00:00
|
|
|
it('updates import paths with latest tool version on invalid version constraint', async () => {
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2021-03-27 06:02:32 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum', 'main.go'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile
|
|
|
|
.mockResolvedValueOnce('New go.sum')
|
|
|
|
.mockResolvedValueOnce('New main.go')
|
|
|
|
.mockResolvedValueOnce('New go.mod');
|
2021-03-27 06:02:32 +00:00
|
|
|
expect(
|
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
2021-06-26 13:29:01 +00:00
|
|
|
updatedDeps: [{ depName: 'github.com/google/go-github/v24' }],
|
2021-03-27 06:02:32 +00:00
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config: {
|
|
|
|
...config,
|
|
|
|
updateType: 'major',
|
|
|
|
newMajor: 28,
|
|
|
|
postUpdateOptions: ['gomodUpdateImportPaths'],
|
|
|
|
constraints: {
|
|
|
|
gomodMod: 'a.b.c',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2021-08-18 06:49:27 +00:00
|
|
|
).toEqual([
|
2022-01-21 05:47:49 +00:00
|
|
|
{ file: { type: 'addition', path: 'go.sum', contents: 'New go.sum' } },
|
|
|
|
{ file: { type: 'addition', path: 'main.go', contents: 'New main.go' } },
|
|
|
|
{ file: { type: 'addition', path: 'go.mod', contents: 'New go.mod' } },
|
2021-08-18 06:49:27 +00:00
|
|
|
]);
|
2021-03-27 06:02:32 +00:00
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
|
|
|
});
|
2021-12-15 10:50:09 +00:00
|
|
|
|
2021-03-27 06:02:32 +00:00
|
|
|
it('skips updating import paths for gopkg.in dependencies', async () => {
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
|
2022-06-20 15:05:39 +00:00
|
|
|
// TODO: #7154 can be null
|
|
|
|
fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename
|
2022-07-22 07:42:30 +00:00
|
|
|
const execSnapshots = mockExecAll();
|
2021-03-27 06:02:32 +00:00
|
|
|
git.getRepoStatus.mockResolvedValueOnce({
|
|
|
|
modified: ['go.sum'],
|
|
|
|
} as StatusResult);
|
2021-12-15 10:50:09 +00:00
|
|
|
fs.readLocalFile
|
|
|
|
.mockResolvedValueOnce('New go.sum')
|
|
|
|
.mockResolvedValueOnce('New go.mod');
|
2021-03-27 06:02:32 +00:00
|
|
|
expect(
|
|
|
|
await gomod.updateArtifacts({
|
|
|
|
packageFileName: 'go.mod',
|
2021-06-26 13:29:01 +00:00
|
|
|
updatedDeps: [{ depName: 'gopkg.in/yaml.v2' }],
|
2021-03-27 06:02:32 +00:00
|
|
|
newPackageFileContent: gomod1,
|
|
|
|
config: {
|
|
|
|
...config,
|
|
|
|
updateType: 'major',
|
|
|
|
newMajor: 28,
|
|
|
|
postUpdateOptions: ['gomodUpdateImportPaths'],
|
|
|
|
},
|
|
|
|
})
|
2021-08-18 06:49:27 +00:00
|
|
|
).toEqual([
|
2022-01-21 05:47:49 +00:00
|
|
|
{ file: { type: 'addition', path: 'go.sum', contents: 'New go.sum' } },
|
|
|
|
{ file: { type: 'addition', path: 'go.mod', contents: 'New go.mod' } },
|
2021-08-18 06:49:27 +00:00
|
|
|
]);
|
2021-03-27 06:02:32 +00:00
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
|
|
|
});
|
2018-10-01 11:50:36 +00:00
|
|
|
});
|