test(manager/gomod): migrate to fs.readLocalFile (#13099)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
This commit is contained in:
Oleg Krivtsov 2021-12-15 17:50:09 +07:00 committed by GitHub
parent 903ffd082b
commit 83b87c0347
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 109 additions and 131 deletions

View file

@ -31,7 +31,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -63,7 +62,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -93,7 +91,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -140,7 +137,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -170,7 +166,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -195,7 +190,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -220,7 +214,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -250,7 +243,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -283,7 +275,7 @@ Array [
},
},
Object {
"cmd": "docker run --rm --name=renovate_go --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e GOPATH -e GOPROXY -e GOPRIVATE -e GONOPROXY -e GONOSUMDB -e GOFLAGS -e CGO_ENABLED -e GIT_CONFIG_KEY_0 -e GIT_CONFIG_VALUE_0 -e GIT_CONFIG_COUNT -w \\"/tmp/github/some/repo\\" renovate/go:latest bash -l -c \\"go get -d ./...\\"",
"cmd": "docker run --rm --name=renovate_go --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e GOPROXY -e GOPRIVATE -e GONOPROXY -e GONOSUMDB -e GOFLAGS -e CGO_ENABLED -e GIT_CONFIG_KEY_0 -e GIT_CONFIG_VALUE_0 -e GIT_CONFIG_COUNT -w \\"/tmp/github/some/repo\\" renovate/go:latest bash -l -c \\"go get -d ./...\\"",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
@ -295,7 +287,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -328,7 +319,7 @@ Array [
},
},
Object {
"cmd": "docker run --rm --name=renovate_go --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e GOPATH -e GOPROXY -e GOPRIVATE -e GONOPROXY -e GONOSUMDB -e GOFLAGS -e CGO_ENABLED -w \\"/tmp/github/some/repo\\" renovate/go:latest bash -l -c \\"go get -d ./... && go mod tidy && go mod tidy\\"",
"cmd": "docker run --rm --name=renovate_go --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e GOPROXY -e GOPRIVATE -e GONOPROXY -e GONOSUMDB -e GOFLAGS -e CGO_ENABLED -w \\"/tmp/github/some/repo\\" renovate/go:latest bash -l -c \\"go get -d ./... && go mod tidy && go mod tidy\\"",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
@ -337,7 +328,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -370,7 +360,7 @@ Array [
},
},
Object {
"cmd": "docker run --rm --name=renovate_go --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e GOPATH -e GOPROXY -e GOPRIVATE -e GONOPROXY -e GONOSUMDB -e GOFLAGS -e CGO_ENABLED -w \\"/tmp/github/some/repo\\" renovate/go:latest bash -l -c \\"go get -d ./...\\"",
"cmd": "docker run --rm --name=renovate_go --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e GOPROXY -e GOPRIVATE -e GONOPROXY -e GONOSUMDB -e GOFLAGS -e CGO_ENABLED -w \\"/tmp/github/some/repo\\" renovate/go:latest bash -l -c \\"go get -d ./...\\"",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
@ -379,7 +369,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -409,7 +398,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -439,7 +427,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -464,7 +451,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -489,7 +475,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -514,7 +499,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -539,7 +523,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -569,7 +552,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -594,7 +576,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -619,7 +600,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -644,7 +624,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -669,7 +648,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -699,7 +677,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -724,7 +701,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -749,7 +725,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -774,7 +749,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -799,7 +773,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -829,7 +802,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -854,7 +826,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -879,7 +850,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -904,7 +874,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",
@ -929,7 +898,6 @@ Array [
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
"GOPATH": "/tmp/renovate/cache/others/go",
"GOPRIVATE": "private.example.com/*",
"GOPROXY": "proxy.example.com",
"HOME": "/home/user",

View file

@ -1,27 +1,21 @@
import { exec as _exec } from 'child_process';
import _fs from 'fs-extra';
import { join } from 'upath';
import { envMock, mockExecAll } from '../../../test/exec-util';
import { git, mocked } from '../../../test/util';
import { envMock, exec, mockExecAll } from '../../../test/exec-util';
import { env, fs, git, mocked } from '../../../test/util';
import { GlobalConfig } from '../../config/global';
import type { RepoGlobalConfig } from '../../config/types';
import * as docker from '../../util/exec/docker';
import * as _env from '../../util/exec/env';
import type { StatusResult } from '../../util/git/types';
import * as _hostRules from '../../util/host-rules';
import type { UpdateArtifactsConfig } from '../types';
import * as gomod from './artifacts';
jest.mock('fs-extra');
jest.mock('child_process');
jest.mock('../../util/exec/env');
jest.mock('../../util/git');
jest.mock('../../util/host-rules');
jest.mock('../../util/http');
jest.mock('../../util/fs');
const fs: jest.Mocked<typeof _fs> = _fs as any;
const exec: jest.Mock<typeof _exec> = _exec as any;
const env = mocked(_env);
const hostRules = mocked(_hostRules);
const gomod1 = `module github.com/renovate-tests/gomod1
@ -67,6 +61,7 @@ describe('manager/gomod/artifacts', () => {
afterEach(() => {
GlobalConfig.reset();
});
it('returns if no go.sum found', async () => {
const execSnapshots = mockExecAll(exec);
expect(
@ -79,13 +74,15 @@ describe('manager/gomod/artifacts', () => {
).toBeNull();
expect(execSnapshots).toMatchSnapshot();
});
it('returns null if unchanged', async () => {
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: [],
} as StatusResult);
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -96,14 +93,15 @@ describe('manager/gomod/artifacts', () => {
).toBeNull();
expect(execSnapshots).toMatchSnapshot();
});
it('returns updated go.sum', async () => {
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum'],
} as StatusResult);
fs.readFile.mockResolvedValueOnce('New go.sum' as any);
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -114,23 +112,24 @@ describe('manager/gomod/artifacts', () => {
).not.toBeNull();
expect(execSnapshots).toMatchSnapshot();
});
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');
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce('modules.txt content' as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce('modules.txt content'); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum', foo],
not_added: [bar],
deleted: [baz],
} as StatusResult);
fs.readFile.mockResolvedValueOnce('New go.sum' as any);
fs.readFile.mockResolvedValueOnce('Foo go.sum' as any);
fs.readFile.mockResolvedValueOnce('Bar go.sum' as any);
fs.readFile.mockResolvedValueOnce('New go.mod' as any);
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
fs.readLocalFile.mockResolvedValueOnce('Foo go.sum');
fs.readLocalFile.mockResolvedValueOnce('Bar go.sum');
fs.readLocalFile.mockResolvedValueOnce('New go.mod');
const res = await gomod.updateArtifacts({
packageFileName: 'go.mod',
updatedDeps: [],
@ -150,15 +149,16 @@ describe('manager/gomod/artifacts', () => {
]);
expect(execSnapshots).toMatchSnapshot();
});
it('supports docker mode without credentials', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum'],
} as StatusResult);
fs.readFile.mockResolvedValueOnce('New go.sum' as any);
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -169,15 +169,16 @@ describe('manager/gomod/artifacts', () => {
).not.toBeNull();
expect(execSnapshots).toMatchSnapshot();
});
it('supports global mode', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'global' });
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum'],
} as StatusResult);
fs.readFile.mockResolvedValueOnce('New go.sum' as any);
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -188,18 +189,19 @@ describe('manager/gomod/artifacts', () => {
).not.toBeNull();
expect(execSnapshots).toMatchSnapshot();
});
it('supports docker mode with credentials', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
hostRules.find.mockReturnValueOnce({
token: 'some-token',
});
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum'],
} as StatusResult);
fs.readFile.mockResolvedValueOnce('New go.sum' as any);
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -222,13 +224,13 @@ describe('manager/gomod/artifacts', () => {
matchHost: 'github.enterprise.com',
},
]);
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum'],
} as StatusResult);
fs.readFile.mockResolvedValueOnce('New go.sum' as any);
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -263,13 +265,13 @@ describe('manager/gomod/artifacts', () => {
matchHost: 'gitlab.enterprise.com',
},
]);
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum'],
} as StatusResult);
fs.readFile.mockResolvedValueOnce('New go.sum' as any);
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -306,13 +308,13 @@ describe('manager/gomod/artifacts', () => {
matchHost: 'https://gitlab.enterprise.com/repo2',
},
]);
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum'],
} as StatusResult);
fs.readFile.mockResolvedValueOnce('New go.sum' as any);
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -352,13 +354,13 @@ describe('manager/gomod/artifacts', () => {
matchHost: 'gitlab.enterprise.com',
},
]);
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum'],
} as StatusResult);
fs.readFile.mockResolvedValueOnce('New go.sum' as any);
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -402,13 +404,13 @@ describe('manager/gomod/artifacts', () => {
matchHost: 'gitlab.enterprise.com',
},
]);
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum'],
} as StatusResult);
fs.readFile.mockResolvedValueOnce('New go.sum' as any);
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -453,13 +455,13 @@ describe('manager/gomod/artifacts', () => {
hostType: 'npm',
},
]);
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum'],
} as StatusResult);
fs.readFile.mockResolvedValueOnce('New go.sum' as any);
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -486,16 +488,16 @@ describe('manager/gomod/artifacts', () => {
it('supports docker mode with goModTidy', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
hostRules.find.mockReturnValueOnce({});
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum'],
} as StatusResult);
fs.readFile.mockResolvedValueOnce('New go.sum 1' as any);
fs.readFile.mockResolvedValueOnce('New go.sum 2' as any);
fs.readFile.mockResolvedValueOnce('New go.sum 3' as any);
fs.readFile.mockResolvedValueOnce('New go.mod' as any);
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',
@ -509,11 +511,12 @@ describe('manager/gomod/artifacts', () => {
).not.toBeNull();
expect(execSnapshots).toMatchSnapshot();
});
it('catches errors', async () => {
const execSnapshots = mockExecAll(exec);
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.outputFile.mockImplementationOnce(() => {
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
fs.writeLocalFile.mockImplementationOnce(() => {
throw new Error('This update totally doesnt work');
});
expect(
@ -533,17 +536,18 @@ describe('manager/gomod/artifacts', () => {
]);
expect(execSnapshots).toMatchSnapshot();
});
it('updates import paths with gomodUpdateImportPaths', async () => {
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum', 'main.go'],
} as StatusResult);
fs.readFile
.mockResolvedValueOnce('New go.sum' as any)
.mockResolvedValueOnce('New main.go' as any)
.mockResolvedValueOnce('New go.mod' as any);
fs.readLocalFile
.mockResolvedValueOnce('New go.sum')
.mockResolvedValueOnce('New main.go')
.mockResolvedValueOnce('New go.mod');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -563,16 +567,17 @@ describe('manager/gomod/artifacts', () => {
]);
expect(execSnapshots).toMatchSnapshot();
});
it('skips updating import paths with gomodUpdateImportPaths on v0 to v1', async () => {
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum', 'main.go'],
} as StatusResult);
fs.readFile
.mockResolvedValueOnce('New go.sum' as any)
.mockResolvedValueOnce('New go.mod' as any);
fs.readLocalFile
.mockResolvedValueOnce('New go.sum')
.mockResolvedValueOnce('New go.mod');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -591,17 +596,18 @@ describe('manager/gomod/artifacts', () => {
]);
expect(execSnapshots).toMatchSnapshot();
});
it('skips gomodTidy without gomodUpdateImportPaths on major update', async () => {
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum', 'main.go'],
} as StatusResult);
fs.readFile
.mockResolvedValueOnce('New go.sum' as any)
.mockResolvedValueOnce('New main.go' as any)
.mockResolvedValueOnce('New go.mod' as any);
fs.readLocalFile
.mockResolvedValueOnce('New go.sum')
.mockResolvedValueOnce('New main.go')
.mockResolvedValueOnce('New go.mod');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -617,17 +623,18 @@ describe('manager/gomod/artifacts', () => {
).toMatchSnapshot();
expect(execSnapshots).toMatchSnapshot();
});
it('does not execute go mod tidy when none of gomodTidy and gomodUpdateImportPaths are set', async () => {
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum', 'main.go'],
} as StatusResult);
fs.readFile
.mockResolvedValueOnce('New go.sum' as any)
.mockResolvedValueOnce('New main.go' as any)
.mockResolvedValueOnce('New go.mod' as any);
fs.readLocalFile
.mockResolvedValueOnce('New go.sum')
.mockResolvedValueOnce('New main.go')
.mockResolvedValueOnce('New go.mod');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -642,17 +649,18 @@ describe('manager/gomod/artifacts', () => {
).toMatchSnapshot();
expect(execSnapshots).toMatchSnapshot();
});
it('updates import paths with specific tool version from constraint', async () => {
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum', 'main.go'],
} as StatusResult);
fs.readFile
.mockResolvedValueOnce('New go.sum' as any)
.mockResolvedValueOnce('New main.go' as any)
.mockResolvedValueOnce('New go.mod' as any);
fs.readLocalFile
.mockResolvedValueOnce('New go.sum')
.mockResolvedValueOnce('New main.go')
.mockResolvedValueOnce('New go.mod');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -675,17 +683,18 @@ describe('manager/gomod/artifacts', () => {
]);
expect(execSnapshots).toMatchSnapshot();
});
it('updates import paths with latest tool version on invalid version constraint', async () => {
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum', 'main.go'],
} as StatusResult);
fs.readFile
.mockResolvedValueOnce('New go.sum' as any)
.mockResolvedValueOnce('New main.go' as any)
.mockResolvedValueOnce('New go.mod' as any);
fs.readLocalFile
.mockResolvedValueOnce('New go.sum')
.mockResolvedValueOnce('New main.go')
.mockResolvedValueOnce('New go.mod');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -708,16 +717,17 @@ describe('manager/gomod/artifacts', () => {
]);
expect(execSnapshots).toMatchSnapshot();
});
it('skips updating import paths for gopkg.in dependencies', async () => {
fs.readFile.mockResolvedValueOnce('Current go.sum' as any);
fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll(exec);
git.getRepoStatus.mockResolvedValueOnce({
modified: ['go.sum'],
} as StatusResult);
fs.readFile
.mockResolvedValueOnce('New go.sum' as any)
.mockResolvedValueOnce('New go.mod' as any);
fs.readLocalFile
.mockResolvedValueOnce('New go.sum')
.mockResolvedValueOnce('New go.mod');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',