Skip to content

Commit

Permalink
test(gomod): Use "codeBlock" helper (#28874)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov authored May 6, 2024
1 parent 04692b6 commit e8b1beb
Showing 1 changed file with 37 additions and 34 deletions.
71 changes: 37 additions & 34 deletions lib/modules/manager/gomod/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { codeBlock } from 'common-tags';
import { Fixtures } from '../../../../test/fixtures';
import { extractPackageFile } from '.';

Expand Down Expand Up @@ -29,38 +30,39 @@ describe('modules/manager/gomod/extract', () => {
});

it('ignores empty spaces in multi-line requires', () => {
const goMod = `
module github.com/renovate-tests/gomod
go 1.19
require (
cloud.google.com/go v0.45.1
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
)
`;
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 = `
module github.com/renovate-tests/gomod
go 1.18
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 goMod = codeBlock`
module github.com/renovate-tests/gomod
go 1.18
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: 2,
lineNumber: 1,
},
depName: 'go',
depType: 'golang',
Expand All @@ -70,7 +72,7 @@ replace (
},
{
managerData: {
lineNumber: 3,
lineNumber: 2,
},
depName: 'github.com/pravesht/gocql',
depType: 'replace',
Expand All @@ -79,7 +81,7 @@ replace (
},
{
managerData: {
lineNumber: 5,
lineNumber: 4,
multiLine: true,
},
depName: 'k8s.io/client-go',
Expand All @@ -89,7 +91,7 @@ replace (
},
{
managerData: {
lineNumber: 8,
lineNumber: 7,
multiLine: true,
},
depName: 'k8s.io/cloud-provider',
Expand All @@ -99,7 +101,7 @@ replace (
},
{
managerData: {
lineNumber: 9,
lineNumber: 8,
multiLine: true,
},
depName: 'k8s.io/cluster-bootstrap',
Expand All @@ -110,7 +112,7 @@ replace (
},
{
managerData: {
lineNumber: 10,
lineNumber: 9,
multiLine: true,
},
depName: 'k8s.io/code-generator',
Expand All @@ -123,17 +125,18 @@ replace (
});

it('extracts the toolchain directive', () => {
const goMod = `
module github.com/renovate-tests/gomod
go 1.21
toolchain go1.21.7
replace golang.org/x/foo => github.com/pravesht/gocql v0.0.0`;
const goMod = codeBlock`
module github.com/renovate-tests/gomod
go 1.21
toolchain go1.21.7
replace golang.org/x/foo => github.com/pravesht/gocql v0.0.0
`;
const res = extractPackageFile(goMod);
expect(res).toEqual({
deps: [
{
managerData: {
lineNumber: 2,
lineNumber: 1,
},
depName: 'go',
depType: 'golang',
Expand All @@ -143,7 +146,7 @@ replace golang.org/x/foo => github.com/pravesht/gocql v0.0.0`;
},
{
managerData: {
lineNumber: 3,
lineNumber: 2,
},
depName: 'go',
depType: 'toolchain',
Expand All @@ -152,7 +155,7 @@ replace golang.org/x/foo => github.com/pravesht/gocql v0.0.0`;
},
{
managerData: {
lineNumber: 4,
lineNumber: 3,
},
depName: 'github.com/pravesht/gocql',
depType: 'replace',
Expand Down

0 comments on commit e8b1beb

Please sign in to comment.