mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-31 17:51:49 +00:00
a36eed3365
As this is the only place in the codebase we're currently doing this, we should remove the usage of `shell` semantics for file redirection, which isn't needed. Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
186 lines
5.0 KiB
TypeScript
186 lines
5.0 KiB
TypeScript
import { mockExecAll } from '~test/exec-util.ts';
|
|
import { fs } from '~test/util.ts';
|
|
import { GlobalConfig } from '../../../config/global.ts';
|
|
import { updateArtifacts } from './index.ts';
|
|
|
|
vi.mock('../../../util/fs/index.ts');
|
|
|
|
describe('modules/manager/flux/artifacts', () => {
|
|
beforeAll(() => {
|
|
GlobalConfig.set({
|
|
localDir: '',
|
|
binarySource: 'global',
|
|
});
|
|
});
|
|
|
|
it('replaces existing value', async () => {
|
|
const snapshots = mockExecAll({ stdout: 'test', stderr: '' });
|
|
fs.readLocalFile.mockResolvedValueOnce('old');
|
|
|
|
const res = await updateArtifacts({
|
|
packageFileName: 'clusters/my-cluster/flux-system/gotk-components.yaml',
|
|
updatedDeps: [
|
|
{
|
|
newVersion: '1.0.1',
|
|
managerData: {
|
|
components:
|
|
'source-controller,kustomize-controller,helm-controller,notification-controller',
|
|
},
|
|
},
|
|
],
|
|
newPackageFileContent: '',
|
|
config: {},
|
|
});
|
|
|
|
expect(res).toEqual([
|
|
{
|
|
file: {
|
|
type: 'addition',
|
|
path: 'clusters/my-cluster/flux-system/gotk-components.yaml',
|
|
contents: 'test',
|
|
},
|
|
},
|
|
]);
|
|
expect(fs.writeLocalFile).toHaveBeenCalledWith(
|
|
'clusters/my-cluster/flux-system/gotk-components.yaml',
|
|
'test',
|
|
);
|
|
expect(snapshots).toMatchObject([
|
|
{
|
|
cmd: {
|
|
command: [
|
|
'flux',
|
|
'install',
|
|
'--export',
|
|
'--components',
|
|
'source-controller,kustomize-controller,helm-controller,notification-controller',
|
|
],
|
|
},
|
|
},
|
|
]);
|
|
});
|
|
|
|
it('detects system manifests in subdirectories', async () => {
|
|
const snapshots = mockExecAll({ stdout: 'test', stderr: '' });
|
|
fs.readLocalFile.mockResolvedValueOnce('old');
|
|
|
|
const res = await updateArtifacts({
|
|
packageFileName:
|
|
'clusters/my-cluster/flux-system/gitops-toolkit/gotk-components.yaml',
|
|
updatedDeps: [
|
|
{
|
|
newVersion: '1.0.1',
|
|
managerData: {
|
|
components:
|
|
'source-controller,kustomize-controller,helm-controller,notification-controller',
|
|
},
|
|
},
|
|
],
|
|
newPackageFileContent: '',
|
|
config: {},
|
|
});
|
|
|
|
expect(res).toEqual([
|
|
{
|
|
file: {
|
|
type: 'addition',
|
|
path: 'clusters/my-cluster/flux-system/gitops-toolkit/gotk-components.yaml',
|
|
contents: 'test',
|
|
},
|
|
},
|
|
]);
|
|
expect(snapshots).toMatchObject([
|
|
{
|
|
cmd: {
|
|
command: [
|
|
'flux',
|
|
'install',
|
|
'--export',
|
|
'--components',
|
|
'source-controller,kustomize-controller,helm-controller,notification-controller',
|
|
],
|
|
},
|
|
},
|
|
]);
|
|
});
|
|
|
|
it('ignores non-system manifests', async () => {
|
|
const res = await updateArtifacts({
|
|
packageFileName: 'not-a-system-manifest.yaml',
|
|
updatedDeps: [{ newVersion: '1.0.1' }],
|
|
newPackageFileContent: '',
|
|
config: {},
|
|
});
|
|
|
|
expect(res).toBeNull();
|
|
});
|
|
|
|
it('ignores unchanged system manifests', async () => {
|
|
const execSnapshots = mockExecAll({ stdout: 'old', stderr: '' });
|
|
fs.readLocalFile.mockResolvedValueOnce('old');
|
|
const res = await updateArtifacts({
|
|
packageFileName: 'clusters/my-cluster/flux-system/gotk-components.yaml',
|
|
updatedDeps: [{ newVersion: '1.0.1' }],
|
|
newPackageFileContent: '',
|
|
config: {},
|
|
});
|
|
|
|
expect(res).toBeNull();
|
|
expect(execSnapshots).toMatchObject([
|
|
{
|
|
cmd: { command: ['flux', 'install', '--export'] },
|
|
},
|
|
]);
|
|
});
|
|
|
|
it('ignores system manifests without a new version', async () => {
|
|
const res = await updateArtifacts({
|
|
packageFileName: 'clusters/my-cluster/flux-system/gotk-components.yaml',
|
|
updatedDeps: [{ newVersion: undefined }],
|
|
newPackageFileContent: '',
|
|
config: {},
|
|
});
|
|
|
|
expect(res).toBeNull();
|
|
});
|
|
|
|
it('failed to generate system manifest', async () => {
|
|
mockExecAll(new Error('failed'));
|
|
const res = await updateArtifacts({
|
|
packageFileName: 'clusters/my-cluster/flux-system/gotk-components.yaml',
|
|
updatedDeps: [{ newVersion: '1.0.1' }],
|
|
newPackageFileContent: '',
|
|
config: {},
|
|
});
|
|
|
|
expect(res).toStrictEqual([
|
|
{
|
|
artifactError: {
|
|
fileName: 'clusters/my-cluster/flux-system/gotk-components.yaml',
|
|
stderr: 'failed',
|
|
},
|
|
},
|
|
]);
|
|
});
|
|
|
|
it('failed to read system manifest', async () => {
|
|
mockExecAll({ stdout: '', stderr: 'Error' });
|
|
fs.readLocalFile.mockResolvedValueOnce('old');
|
|
const res = await updateArtifacts({
|
|
packageFileName: 'clusters/my-cluster/flux-system/gotk-components.yaml',
|
|
updatedDeps: [{ newVersion: '1.0.1' }],
|
|
newPackageFileContent: '',
|
|
config: {},
|
|
});
|
|
|
|
expect(res).toStrictEqual([
|
|
{
|
|
artifactError: {
|
|
fileName: 'clusters/my-cluster/flux-system/gotk-components.yaml',
|
|
stderr: 'Error',
|
|
},
|
|
},
|
|
]);
|
|
});
|
|
});
|