0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 21:48:32 +00:00
renovatebot_renovate/lib/modules/manager/gomod/extract.spec.ts
Ed Harrod 894250d392
chore(manager/gomod): Update go version to 1.23.3 in tests/examples (#32514)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2024-11-13 15:45:18 +00:00

170 lines
5.0 KiB
TypeScript

import { codeBlock } from 'common-tags';
import { Fixtures } from '../../../../test/fixtures';
import { extractPackageFile } from '.';
const gomod1 = Fixtures.get('1/go-mod');
const gomod2 = Fixtures.get('2/go-mod');
describe('modules/manager/gomod/extract', () => {
describe('extractPackageFile()', () => {
it('returns null for empty', () => {
expect(extractPackageFile('nothing here')).toBeNull();
});
it('extracts single-line requires', () => {
const res = extractPackageFile(gomod1)?.deps;
expect(res).toMatchSnapshot();
expect(res).toHaveLength(10);
expect(res?.filter((e) => e.depType === 'require')).toHaveLength(7);
expect(res?.filter((e) => e.depType === 'indirect')).toHaveLength(1);
expect(res?.filter((e) => e.skipReason)).toHaveLength(2);
expect(res?.filter((e) => e.depType === 'replace')).toHaveLength(2);
});
it('extracts multi-line requires', () => {
const res = extractPackageFile(gomod2)?.deps;
expect(res).toMatchSnapshot();
expect(res).toHaveLength(59);
expect(res?.filter((e) => e.skipReason)).toHaveLength(0);
expect(res?.filter((e) => e.depType === 'indirect')).toHaveLength(1);
});
it('ignores empty spaces in multi-line requires', () => {
const goMod = codeBlock`
module github.com/renovate-tests/gomod
go 1.19
require (
cloud.google.com/go v0.45.1
github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 // indirect
)
`;
const res = extractPackageFile(goMod)?.deps;
expect(res).toHaveLength(3);
});
it('extracts replace directives from multi-line and single line', () => {
const goMod = codeBlock`
module github.com/renovate-tests/gomod
go 1.23
replace golang.org/x/foo => github.com/pravesht/gocql v0.0.0
replace (
k8s.io/client-go => k8s.io/client-go v0.21.9
)
replace (
k8s.io/cloud-provider => k8s.io/cloud-provider v0.17.3
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.17.3 // indirect
k8s.io/code-generator => k8s.io/code-generator v0.17.3
)
`;
const res = extractPackageFile(goMod);
expect(res).toEqual({
deps: [
{
managerData: {
lineNumber: 1,
},
depName: 'go',
depType: 'golang',
currentValue: '1.23',
datasource: 'golang-version',
versioning: 'go-mod-directive',
},
{
managerData: {
lineNumber: 2,
},
depName: 'github.com/pravesht/gocql',
depType: 'replace',
currentValue: 'v0.0.0',
datasource: 'go',
},
{
managerData: {
lineNumber: 4,
multiLine: true,
},
depName: 'k8s.io/client-go',
depType: 'replace',
currentValue: 'v0.21.9',
datasource: 'go',
},
{
managerData: {
lineNumber: 7,
multiLine: true,
},
depName: 'k8s.io/cloud-provider',
depType: 'replace',
currentValue: 'v0.17.3',
datasource: 'go',
},
{
managerData: {
lineNumber: 8,
multiLine: true,
},
depName: 'k8s.io/cluster-bootstrap',
depType: 'indirect',
enabled: false,
currentValue: 'v0.17.3',
datasource: 'go',
},
{
managerData: {
lineNumber: 9,
multiLine: true,
},
depName: 'k8s.io/code-generator',
depType: 'replace',
currentValue: 'v0.17.3',
datasource: 'go',
},
],
});
});
it('extracts the toolchain directive', () => {
const goMod = codeBlock`
module github.com/renovate-tests/gomod
go 1.23
toolchain go1.23.3
replace golang.org/x/foo => github.com/pravesht/gocql v0.0.0
`;
const res = extractPackageFile(goMod);
expect(res).toEqual({
deps: [
{
managerData: {
lineNumber: 1,
},
depName: 'go',
depType: 'golang',
currentValue: '1.23',
datasource: 'golang-version',
versioning: 'go-mod-directive',
},
{
managerData: {
lineNumber: 2,
},
depName: 'go',
depType: 'toolchain',
currentValue: '1.23.3',
datasource: 'golang-version',
},
{
managerData: {
lineNumber: 3,
},
depName: 'github.com/pravesht/gocql',
depType: 'replace',
currentValue: 'v0.0.0',
datasource: 'go',
},
],
});
});
});
});