Skip to content

Commit

Permalink
refactor(tests): Use codeBlock tagged literal (#18916)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Nov 15, 2022
1 parent 07f72a0 commit 3c56aec
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 251 deletions.
166 changes: 88 additions & 78 deletions lib/modules/manager/flux/extract.spec.ts
@@ -1,3 +1,4 @@
import { codeBlock } from 'common-tags';
import { Fixtures } from '../../../../test/fixtures';
import { GlobalConfig } from '../../../config/global';
import type { RepoGlobalConfig } from '../../../config/types';
Expand Down Expand Up @@ -86,133 +87,142 @@ describe('modules/manager/flux/extract', () => {

it('ignores HelmRepository resources without metadata', () => {
const result = extractPackageFile(
`${Fixtures.get('release.yaml')}
---
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: HelmRepository
`,
codeBlock`
${Fixtures.get('release.yaml')}
---
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: HelmRepository
`,
'test.yaml'
);
expect(result?.deps[0].skipReason).toBe('unknown-registry');
});

it('ignores HelmRelease resources without a chart name', () => {
const result = extractPackageFile(
`apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: sealed-secrets
namespace: kube-system
spec:
chart:
spec:
sourceRef:
kind: HelmRepository
name: sealed-secrets
version: "2.0.2"
`,
codeBlock`
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: sealed-secrets
namespace: kube-system
spec:
chart:
spec:
sourceRef:
kind: HelmRepository
name: sealed-secrets
version: "2.0.2"
`,
'test.yaml'
);
expect(result).toBeNull();
});

it('does not match HelmRelease resources without a namespace to HelmRepository resources without a namespace', () => {
const result = extractPackageFile(
`apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: HelmRepository
metadata:
name: sealed-secrets
spec:
url: https://bitnami-labs.github.io/sealed-secrets
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
spec:
chart:
spec:
chart: sealed-secrets
sourceRef:
kind: HelmRepository
name: sealed-secrets
version: "2.0.2"
`,
codeBlock`
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: HelmRepository
metadata:
name: sealed-secrets
spec:
url: https://bitnami-labs.github.io/sealed-secrets
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
spec:
chart:
spec:
chart: sealed-secrets
sourceRef:
kind: HelmRepository
name: sealed-secrets
version: "2.0.2"
`,
'test.yaml'
);
expect(result?.deps[0].skipReason).toBe('unknown-registry');
});

it('does not match HelmRelease resources without a sourceRef', () => {
const result = extractPackageFile(
`${Fixtures.get('source.yaml')}
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: sealed-secrets
spec:
chart:
spec:
chart: sealed-secrets
version: "2.0.2"
`,
codeBlock`
${Fixtures.get('source.yaml')}
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: sealed-secrets
spec:
chart:
spec:
chart: sealed-secrets
version: "2.0.2"
`,
'test.yaml'
);
expect(result?.deps[0].skipReason).toBe('unknown-registry');
});

it('does not match HelmRelease resources without a namespace', () => {
const result = extractPackageFile(
`${Fixtures.get('source.yaml')}
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
spec:
chart:
spec:
chart: sealed-secrets
sourceRef:
kind: HelmRepository
name: sealed-secrets
version: "2.0.2"
`,
codeBlock`
${Fixtures.get('source.yaml')}
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
spec:
chart:
spec:
chart: sealed-secrets
sourceRef:
kind: HelmRepository
name: sealed-secrets
version: "2.0.2"
`,
'test.yaml'
);
expect(result?.deps[0].skipReason).toBe('unknown-registry');
});

it('ignores HelmRepository resources without a namespace', () => {
const result = extractPackageFile(
`${Fixtures.get('release.yaml')}
---
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: HelmRepository
metadata:
name: test
`,
codeBlock`
${Fixtures.get('release.yaml')}
---
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: HelmRepository
metadata:
name: test
`,
'test.yaml'
);
expect(result?.deps[0].skipReason).toBe('unknown-registry');
});

it('ignores HelmRepository resources without a URL', () => {
const result = extractPackageFile(
`${Fixtures.get('release.yaml')}
---
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: HelmRepository
metadata:
name: sealed-secrets
namespace: kube-system
`,
codeBlock`
${Fixtures.get('release.yaml')}
---
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: HelmRepository
metadata:
name: sealed-secrets
namespace: kube-system
`,
'test.yaml'
);
expect(result?.deps[0].skipReason).toBe('unknown-registry');
});

it('ignores resources of an unknown kind', () => {
const result = extractPackageFile(
`kind: SomethingElse
apiVersion: helm.toolkit.fluxcd.io/v2beta1`,
codeBlock`
kind: SomethingElse
apiVersion: helm.toolkit.fluxcd.io/v2beta1
`,
'test.yaml'
);
expect(result).toBeNull();
Expand Down
31 changes: 16 additions & 15 deletions lib/modules/manager/gomod/artifacts.spec.ts
@@ -1,3 +1,4 @@
import { codeBlock } from 'common-tags';
import { join } from 'upath';
import { envMock, mockExecAll } from '../../../../test/exec-util';
import { env, fs, git, mocked } from '../../../../test/util';
Expand All @@ -22,25 +23,25 @@ process.env.BUILDPACK = 'true';
const datasource = mocked(_datasource);
const hostRules = mocked(_hostRules);

const gomod1 = `module github.com/renovate-tests/gomod1
const gomod1 = codeBlock`
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
require go.uber.org/zap v1.20.0
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
require go.uber.org/zap v1.20.0
replace github.com/pkg/errors => ../errors
replace github.com/pkg/errors => ../errors
replace (golang.org/x/foo => github.com/pravesht/gocql v0.0.0)
replace (
// TODO: this comment breaks renovatebot (>v0.11.1)
go.uber.org/zap => go.uber.org/zap v1.21.0
)
replace (golang.org/x/foo => github.com/pravesht/gocql v0.0.0)
replace (
// TODO: this comment breaks renovatebot (>v0.11.1)
go.uber.org/zap => go.uber.org/zap v1.21.0
)
`;

const adminConfig: RepoGlobalConfig = {
Expand Down
16 changes: 10 additions & 6 deletions lib/modules/manager/hermit/update.spec.ts
@@ -1,19 +1,23 @@
import { codeBlock } from 'common-tags';
import { updateDependency } from '.';

describe('modules/manager/hermit/update', () => {
describe('updateDependency', () => {
it('should append a new marking line at the end to trigger the artifact update', () => {
const fileContent = `#!/bin/bash
#some hermit content
`;
const fileContent = codeBlock`
#!/bin/bash
#some hermit content
`;
const ret = updateDependency({ fileContent, upgrade: {} });
expect(ret).toBe(`${fileContent}\n#hermit updated`);
});

it('should not update again if the new line has been appended', () => {
const fileContent = `#!/bin/bash
#some hermit content
#hermit updated`;
const fileContent = codeBlock`
#!/bin/bash
#some hermit content
#hermit updated
`;
const ret = updateDependency({ fileContent, upgrade: {} });
expect(ret).toBe(`${fileContent}`);
});
Expand Down
51 changes: 23 additions & 28 deletions lib/modules/manager/mint/extract.spec.ts
@@ -1,33 +1,15 @@
import { codeBlock } from 'common-tags';
import { extractPackageFile } from '.';

const simpleMintfile = `
SwiftGen/SwiftGen@6.6.1
yonaskolb/xcodegen@2.30.0
realm/SwiftLint @ 0.48.0
#realm/SwiftLint @ 0.48.0
`;

const noVersionMintfileContent = `
yonaskolb/xcodegen
realm/SwiftLint
`;

const complexMintFileContent = `
SwiftGen/SwiftGen@6.6.1
yonaskolb/xcodegen
realm/SwiftLint @ 0.48.0`;

const includesCommentedOutMintFileContent = `
SwiftGen/SwiftGen@6.6.1
yonaskolb/xcodegen
#yonaskolb/xcodegen
realm/SwiftLint@0.48.0 #commented out
`;

describe('modules/manager/mint/extract', () => {
describe('extractPackageFile()', () => {
it('Mintfile With Version Description', () => {
const res = extractPackageFile(simpleMintfile);
const res = extractPackageFile(codeBlock`
SwiftGen/SwiftGen@6.6.1
yonaskolb/xcodegen@2.30.0
realm/SwiftLint @ 0.48.0
#realm/SwiftLint @ 0.48.0
`);
expect(res).toEqual({
deps: [
{
Expand All @@ -53,7 +35,10 @@ describe('modules/manager/mint/extract', () => {
});

it('Mintfile Without Version Description', () => {
const res = extractPackageFile(noVersionMintfileContent);
const res = extractPackageFile(codeBlock`
yonaskolb/xcodegen
realm/SwiftLint
`);
expect(res).toEqual({
deps: [
{
Expand All @@ -69,7 +54,11 @@ describe('modules/manager/mint/extract', () => {
});

it('Complex Mintfile', () => {
const res = extractPackageFile(complexMintFileContent);
const res = extractPackageFile(codeBlock`
SwiftGen/SwiftGen@6.6.1
yonaskolb/xcodegen
realm/SwiftLint @ 0.48.0
`);
expect(res).toEqual({
deps: [
{
Expand All @@ -93,7 +82,13 @@ describe('modules/manager/mint/extract', () => {
});

it('Mintfile Includes Commented Out', () => {
const res = extractPackageFile(includesCommentedOutMintFileContent);
const res = extractPackageFile(codeBlock`
SwiftGen/SwiftGen@6.6.1
yonaskolb/xcodegen
#yonaskolb/xcodegen
realm/SwiftLint@0.48.0 #commented out
`);
expect(res).toEqual({
deps: [
{
Expand Down

0 comments on commit 3c56aec

Please sign in to comment.