fix(auto-replace): should fail on wrong replace (#8062)

This commit is contained in:
Michael Kriese 2020-12-18 11:39:27 +01:00 committed by GitHub
parent 32459d313d
commit 2f432626f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -1,6 +1,7 @@
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
import { resolve } from 'upath'; import { resolve } from 'upath';
import { defaultConfig } from '../../../test/util'; import { defaultConfig } from '../../../test/util';
import { WORKER_FILE_UPDATE_FAILED } from '../../constants/error-messages';
import { extractPackageFile } from '../../manager/html'; import { extractPackageFile } from '../../manager/html';
import { BranchUpgradeConfig } from '../common'; import { BranchUpgradeConfig } from '../common';
import { doAutoReplace } from './auto-replace'; import { doAutoReplace } from './auto-replace';
@ -141,5 +142,23 @@ describe('workers/branch/auto-replace', () => {
const res = await doAutoReplace(upgrade, dockerfile, reuseExistingBranch); const res = await doAutoReplace(upgrade, dockerfile, reuseExistingBranch);
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
}); });
it('fails with oldversion in depname', async () => {
const yml =
'image: "1111111111.dkr.ecr.us-east-1.amazonaws.com/my-repository:1"\n\n';
upgrade.manager = 'regex';
upgrade.depName =
'1111111111.dkr.ecr.us-east-1.amazonaws.com/my-repository';
upgrade.currentValue = '1';
upgrade.newValue = '42';
upgrade.depIndex = 0;
upgrade.replaceString =
'image: "1111111111.dkr.ecr.us-east-1.amazonaws.com/my-repository:1"\n\n';
upgrade.packageFile = 'k8s/base/defaults.yaml';
upgrade.matchStrings = [
'image:\\s*\\\'?\\"?(?<depName>[^:]+):(?<currentValue>[^\\s\\\'\\"]+)\\\'?\\"?\\s*',
];
const res = doAutoReplace(upgrade, yml, reuseExistingBranch);
await expect(res).rejects.toThrow(WORKER_FILE_UPDATE_FAILED);
});
}); });
}); });

View file

@ -37,7 +37,7 @@ export async function confirmIfDepUpdated(
logger.debug({ manager, packageFile }, 'No newUpgrade'); logger.debug({ manager, packageFile }, 'No newUpgrade');
return false; return false;
} }
// istanbul ignore if
if (upgrade.depName !== newUpgrade.depName) { if (upgrade.depName !== newUpgrade.depName) {
logger.debug( logger.debug(
{ {
@ -48,6 +48,7 @@ export async function confirmIfDepUpdated(
}, },
'depName mismatch' 'depName mismatch'
); );
return false;
} }
if (newUpgrade.currentValue !== newValue) { if (newUpgrade.currentValue !== newValue) {
logger.debug( logger.debug(