From e8b1beba81e7cd77703e2d9d9172dacf2ecd8ec6 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Mon, 6 May 2024 11:56:31 -0300 Subject: [PATCH] test(gomod): Use "codeBlock" helper (#28874) --- lib/modules/manager/gomod/extract.spec.ts | 71 ++++++++++++----------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/lib/modules/manager/gomod/extract.spec.ts b/lib/modules/manager/gomod/extract.spec.ts index 86ed6321a6ce43..67b7f2c88a4b3f 100644 --- a/lib/modules/manager/gomod/extract.spec.ts +++ b/lib/modules/manager/gomod/extract.spec.ts @@ -1,3 +1,4 @@ +import { codeBlock } from 'common-tags'; import { Fixtures } from '../../../../test/fixtures'; import { extractPackageFile } from '.'; @@ -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', @@ -70,7 +72,7 @@ replace ( }, { managerData: { - lineNumber: 3, + lineNumber: 2, }, depName: 'github.com/pravesht/gocql', depType: 'replace', @@ -79,7 +81,7 @@ replace ( }, { managerData: { - lineNumber: 5, + lineNumber: 4, multiLine: true, }, depName: 'k8s.io/client-go', @@ -89,7 +91,7 @@ replace ( }, { managerData: { - lineNumber: 8, + lineNumber: 7, multiLine: true, }, depName: 'k8s.io/cloud-provider', @@ -99,7 +101,7 @@ replace ( }, { managerData: { - lineNumber: 9, + lineNumber: 8, multiLine: true, }, depName: 'k8s.io/cluster-bootstrap', @@ -110,7 +112,7 @@ replace ( }, { managerData: { - lineNumber: 10, + lineNumber: 9, multiLine: true, }, depName: 'k8s.io/code-generator', @@ -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', @@ -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', @@ -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',