Skip to content
Snippets Groups Projects
Unverified Commit c3de9f94 authored by dali546's avatar dali546 Committed by GitHub
Browse files

fix(terraform): Replace correct currentValue match in constraint with new value (#26867)

parent d8342813
Branches
Tags 37.165.4
No related merge requests found
......@@ -1118,6 +1118,32 @@ describe('modules/manager/terraform/lockfile/index', () => {
).toBe('>= 2.36.0, 2.46.0');
});
it('update constraint when current version is matched multiple times', () => {
expect(
getNewConstraint(
{
currentValue: '2.41.0',
newValue: '2.46.0',
newVersion: '2.46.0',
},
'>= 2.41.0, 2.41.0',
),
).toBe('>= 2.41.0, 2.46.0');
});
it('update constraint when current version is in a complicated constraint', () => {
expect(
getNewConstraint(
{
currentValue: '<= 2.41.0',
newValue: '<= 2.46.0',
newVersion: '2.46.0',
},
'>= 2.41.0, <= 2.41.0, >= 2.0.0',
),
).toBe('>= 2.41.0, <= 2.46.0, >= 2.0.0');
});
it('create constraint with full version', () => {
expect(
getNewConstraint(
......
......@@ -99,8 +99,8 @@ export function getNewConstraint(
);
//remove surplus .0 version
return oldConstraint.replace(
regEx(`${escapeRegExp(currentValue)}(\\.0)*`),
newValue,
regEx(`(,\\s|^)${escapeRegExp(currentValue)}(\\.0)*`),
`$1${newValue}`,
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment