Skip to content

Commit

Permalink
chore: added tests
Browse files Browse the repository at this point in the history
Signed-off-by: kvanzuijlen <[email protected]>
  • Loading branch information
kvanzuijlen committed Dec 27, 2023
1 parent ac5a360 commit 869fd72
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 33 deletions.
5 changes: 2 additions & 3 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,11 @@ Instead, set the old `branchPrefix` value as `branchPrefixOld` to allow Renovate
## branchTopic

This field is combined with `branchPrefix` and `additionalBranchPrefix` to form the full `branchName`. `branchName` uniqueness is important for dependency update grouping or non-grouping so be cautious about ever editing this field manually.
This is an advance field and it's recommend you seek a config review before applying it.
This is an advanced field, and it's recommend you seek a config review before applying it.

## bumpVersion

Currently this setting supports `helmv3`, `npm`, `nuget`, `maven`, `pep621` and `sbt` only, so raise a feature request if you have a use for it with other package managers.
Currently this setting supports `helmv3`, `npm`, `nuget`, `maven`, `pep621`, `poetry` and `sbt` only, so raise a feature request if you have a use for it with other package managers.
Currently, this setting supports `helmv3`, `helm-values`, `npm`, `nuget`, `maven`, `pep621`, `poetry` and `sbt` only, so raise a feature request if you have a use for it with other package managers.
Its purpose is if you want Renovate to update the `version` field within your package file any time it updates dependencies within.
Usually this is for automatic release purposes, so that you don't need to add another step after Renovate before you can release a new version.

Expand Down
29 changes: 29 additions & 0 deletions lib/modules/manager/helm-values/__snapshots__/update.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`lib/manager/helm-values/update .bumpPackageVersion() increments 1`] = `
"apiVersion: v2
name: test
version: 0.0.3
"
`;

exports[`lib/manager/helm-values/update .bumpPackageVersion() updates 1`] = `
"apiVersion: v2
name: test
version: 0.1.0
"
`;

exports[`modules/manager/helm-values/update .bumpPackageVersion() increments 1`] = `
"apiVersion: v2
name: test
version: 0.0.3
"
`;

exports[`modules/manager/helm-values/update .bumpPackageVersion() updates 1`] = `
"apiVersion: v2
name: test
version: 0.1.0
"
`;
73 changes: 63 additions & 10 deletions lib/modules/manager/helm-values/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Fixtures } from '../../../../test/fixtures';
import { fs } from '../../../../test/util';
import { extractPackageFile } from '.';

const helmDefaultChartInitValues = Fixtures.get(
Expand All @@ -11,18 +12,25 @@ const helmMultiAndNestedImageValues = Fixtures.get(

describe('modules/manager/helm-values/extract', () => {
describe('extractPackageFile()', () => {
it('returns null for invalid yaml file content', () => {
const result = extractPackageFile('nothing here: [');
beforeEach(() => {
fs.readLocalFile = jest.fn();
});

it('returns null for invalid yaml file content', async () => {
const result = await extractPackageFile('nothing here: [', 'some file');
expect(result).toBeNull();
});

it('returns null for empty yaml file content', () => {
const result = extractPackageFile('');
it('returns null for empty yaml file content', async () => {
const result = await extractPackageFile('', 'some file');
expect(result).toBeNull();
});

it('extracts from values.yaml correctly with same structure as "helm create"', () => {
const result = extractPackageFile(helmDefaultChartInitValues);
it('extracts from values.yaml correctly with same structure as "helm create"', async () => {
const result = await extractPackageFile(
helmDefaultChartInitValues,
'some file',
);
expect(result).toMatchSnapshot({
deps: [
{
Expand All @@ -33,17 +41,20 @@ describe('modules/manager/helm-values/extract', () => {
});
});

it('extracts from complex values file correctly"', () => {
const result = extractPackageFile(helmMultiAndNestedImageValues);
it('extracts from complex values file correctly"', async () => {
const result = await extractPackageFile(
helmMultiAndNestedImageValues,
'some file',
);
expect(result).toMatchSnapshot();
expect(result?.deps).toHaveLength(5);
});

it('extract data from file with multiple documents', () => {
it('extract data from file with multiple documents', async () => {
const multiDocumentFile = Fixtures.get(
'single_file_with_multiple_documents.yaml',
);
const result = extractPackageFile(multiDocumentFile);
const result = await extractPackageFile(multiDocumentFile, 'some file');
expect(result).toMatchObject({
deps: [
{
Expand All @@ -61,5 +72,47 @@ describe('modules/manager/helm-values/extract', () => {
],
});
});

it('returns the package file version from the sibling Chart.yaml"', async () => {
fs.readLocalFile.mockResolvedValueOnce(`
apiVersion: v2
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: example
version: 0.1.0
`);
const result = await extractPackageFile(
helmMultiAndNestedImageValues,
'values.yaml',
);
expect(result).not.toBeNull();
expect(result?.packageFileVersion).toBe('0.1.0');
});

it('does not fail if the sibling Chart.yaml is invalid', async () => {
fs.readLocalFile.mockResolvedValueOnce(`
invalidYaml: [
`);
const result = await extractPackageFile(
helmMultiAndNestedImageValues,
'values.yaml',
);
expect(result).not.toBeNull();
expect(result?.packageFileVersion).toBeUndefined();
});

it('does not fail if the sibling Chart.yaml does not contain the required fields', async () => {
fs.readLocalFile.mockResolvedValueOnce(`
apiVersion: v2
name: test
version-is: missing
`);
const result = await extractPackageFile(
helmMultiAndNestedImageValues,
'values.yaml',
);
expect(result).not.toBeNull();
expect(result?.packageFileVersion).toBeUndefined();
});
});
});
82 changes: 82 additions & 0 deletions lib/modules/manager/helm-values/update.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import yaml from 'js-yaml';
import { fs } from '../../../../test/util';
import * as helmValuesUpdater from './update';

describe('modules/manager/helm-values/update', () => {
describe('.bumpPackageVersion()', () => {
const chartContent = yaml.dump({
apiVersion: 'v2',
name: 'test',
version: '0.0.2',
});
const helmValuesContent = yaml.dump({
image: {
registry: 'docker.io',
repository: 'docker/whalesay',
tag: '1.0.0',
},
});

beforeEach(() => {
jest.resetAllMocks();
fs.readLocalFile = jest.fn();
fs.readLocalFile.mockResolvedValueOnce(chartContent);
});

it('increments', async () => {
const { bumpedContent, bumpedFiles } =
await helmValuesUpdater.bumpPackageVersion(
helmValuesContent,
'0.0.2',
'patch',
'values.yaml',
);
expect(bumpedContent).toEqual(helmValuesContent);
expect(bumpedFiles).toHaveLength(1);
const bumpedFile = bumpedFiles![0];
expect(bumpedFile.fileName).toBe('Chart.yaml');
expect(bumpedFile.newContent).toMatchSnapshot();
});

it('no ops', async () => {
const { bumpedContent, bumpedFiles } =
await helmValuesUpdater.bumpPackageVersion(
helmValuesContent,
'0.0.1',
'patch',
'values.yaml',
);
expect(bumpedContent).toEqual(helmValuesContent);
expect(bumpedFiles).toHaveLength(1);
const bumpedFile = bumpedFiles![0];
expect(bumpedFile.newContent).toEqual(chartContent);
});

it('updates', async () => {
const { bumpedContent, bumpedFiles } =
await helmValuesUpdater.bumpPackageVersion(
helmValuesContent,
'0.0.1',
'minor',
'values.yaml',
);
expect(bumpedContent).toEqual(helmValuesContent);
expect(bumpedFiles).toHaveLength(1);
const bumpedFile = bumpedFiles![0];
expect(bumpedFile.fileName).toBe('Chart.yaml');
expect(bumpedFile.newContent).toMatchSnapshot();
});

it('returns content if bumping errors', async () => {
const { bumpedContent, bumpedFiles } =
await helmValuesUpdater.bumpPackageVersion(
helmValuesContent,
'0.0.2',
true as any,
'values.yaml',
);
expect(bumpedContent).toEqual(helmValuesContent);
expect(bumpedFiles).toBeUndefined();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`workers/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions in all files if multiple files were bumped 1`] = `
Object {
"artifactErrors": Array [],
"reuseExistingBranch": undefined,
"updatedArtifacts": Array [],
"updatedPackageFiles": Array [
Object {
"contents": "version: 0.0.2",
"name": "/test/Chart.yaml",
},
Object {
"contents": "# Version 0.0.2",
"name": "/test/README.md",
},
],
}
`;

exports[`workers/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions with a bumpPackageFile different from the packageFile 1`] = `
Object {
"artifactErrors": Array [],
"reuseExistingBranch": undefined,
"updatedArtifacts": Array [],
"updatedPackageFiles": Array [
Object {
"contents": "version: 0.0.2",
"name": "/test/Chart.yaml",
},
],
}
`;

exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() bumps versions in autoReplace managers 1`] = `
{
"artifactErrors": [],
Expand Down Expand Up @@ -190,6 +222,39 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() h
}
`;

exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions 1`] = `
{
"artifactErrors": [],
"reuseExistingBranch": undefined,
"updatedArtifacts": [],
"updatedPackageFiles": [
{
"contents": "version: 0.0.2",
"path": "Chart.yaml",
"type": "addition",
},
],
}
`;

exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions in all files if multiple files were bumped 1`] = `
{
"artifactErrors": [],
"reuseExistingBranch": undefined,
"updatedArtifacts": [],
"updatedPackageFiles": [],
}
`;

exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions with a bumpPackageFile different from the packageFile 1`] = `
{
"artifactErrors": [],
"reuseExistingBranch": undefined,
"updatedArtifacts": [],
"updatedPackageFiles": [],
}
`;

exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() update artifacts on update-lockfile strategy 1`] = `
{
"artifactErrors": [],
Expand Down
Loading

0 comments on commit 869fd72

Please sign in to comment.