Skip to content

Commit

Permalink
refactoring(presets/workarounds): use matchRegexOrGlob helper (renova…
Browse files Browse the repository at this point in the history
  • Loading branch information
mvitz committed Aug 29, 2024
1 parent 50aa298 commit 6200e1c
Showing 1 changed file with 14 additions and 30 deletions.
44 changes: 14 additions & 30 deletions lib/config/presets/internal/workarounds.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import * as versionings from '../../../modules/versioning';
import { regEx } from '../../../util/regex';
import { matchRegexOrGlob } from '../../../util/string-match';
import { presets } from './workarounds';

describe('config/presets/internal/workarounds', () => {
describe('bitnamiDockerImageVersioning', () => {
const versioning = versionings.get(
presets.bitnamiDockerImageVersioning.packageRules![0]
.versioning as string,
);
const matchCurrentValue = presets.bitnamiDockerImageVersioning
.packageRules![0].matchCurrentValue as string;
const matchCurrentValueRe = regEx(
matchCurrentValue.substring(1, matchCurrentValue.length - 1),
);
const preset = presets.bitnamiDockerImageVersioning;
const packageRule = preset.packageRules![0];

const versioning = versionings.get(packageRule.versioning as string);
const matchCurrentValue = packageRule.matchCurrentValue!;

it.each`
input | expected
Expand Down Expand Up @@ -41,7 +37,7 @@ describe('config/presets/internal/workarounds', () => {
${'1.24.0-debian-12'} | ${true}
${'1.24.0-debian-12-r24'} | ${true}
`('matchCurrentValue("$input") == "$expected"', ({ input, expected }) => {
expect(matchCurrentValueRe.test(input)).toEqual(expected);
expect(matchRegexOrGlob(input, matchCurrentValue)).toEqual(expected);
});
});

Expand All @@ -53,10 +49,7 @@ describe('config/presets/internal/workarounds', () => {

const versioning = versionings.get(packageRule.versioning as string);

const matchCurrentValue = packageRule.matchCurrentValue as string;
const matchCurrentValueRe = regEx(
matchCurrentValue.substring(1, matchCurrentValue.length - 1),
);
const matchCurrentValue = packageRule.matchCurrentValue!;

it.each`
input | expected
Expand Down Expand Up @@ -85,7 +78,7 @@ describe('config/presets/internal/workarounds', () => {
${'jdk-all-11-slim-musl'} | ${false}
${'jre-11-slim-musl'} | ${false}
`('matchCurrentValue("$input") == "$expected"', ({ input, expected }) => {
expect(matchCurrentValueRe.test(input)).toEqual(expected);
expect(matchRegexOrGlob(input, matchCurrentValue)).toEqual(expected);
});
});

Expand All @@ -94,10 +87,7 @@ describe('config/presets/internal/workarounds', () => {

const versioning = versionings.get(packageRule.versioning as string);

const matchCurrentValue = packageRule.matchCurrentValue as string;
const matchCurrentValueRe = regEx(
matchCurrentValue.substring(1, matchCurrentValue.length - 1),
);
const matchCurrentValue = packageRule.matchCurrentValue!;

it.each`
input | expected
Expand Down Expand Up @@ -126,7 +116,7 @@ describe('config/presets/internal/workarounds', () => {
${'jdk-all-11-slim-musl'} | ${true}
${'jre-11-slim-musl'} | ${false}
`('matchCurrentValue("$input") == "$expected"', ({ input, expected }) => {
expect(matchCurrentValueRe.test(input)).toEqual(expected);
expect(matchRegexOrGlob(input, matchCurrentValue)).toEqual(expected);
});
});

Expand All @@ -135,10 +125,7 @@ describe('config/presets/internal/workarounds', () => {

const versioning = versionings.get(packageRule.versioning as string);

const matchCurrentValue = packageRule.matchCurrentValue as string;
const matchCurrentValueRe = regEx(
matchCurrentValue.substring(1, matchCurrentValue.length - 1),
);
const matchCurrentValue = packageRule.matchCurrentValue!;

it.each`
input | expected
Expand Down Expand Up @@ -167,7 +154,7 @@ describe('config/presets/internal/workarounds', () => {
${'jdk-all-11-slim-musl'} | ${false}
${'jre-11-slim-musl'} | ${true}
`('matchCurrentValue("$input") == "$expected"', ({ input, expected }) => {
expect(matchCurrentValueRe.test(input)).toEqual(expected);
expect(matchRegexOrGlob(input, matchCurrentValue)).toEqual(expected);
});
});
});
Expand All @@ -179,9 +166,6 @@ describe('config/presets/internal/workarounds', () => {
const packageRule = preset.packageRules![2];

const allowedVersions = packageRule.allowedVersions as string;
const allowedVersionsRe = regEx(
allowedVersions.substring(1, allowedVersions.length - 1),
);

it.each`
input | expected
Expand All @@ -198,7 +182,7 @@ describe('config/presets/internal/workarounds', () => {
${'jdk-all-22-crac-slim-glibc'} | ${false}
${'jre-22-crac-slim-glibc'} | ${false}
`('allowedVersisons("$input") == "$expected"', ({ input, expected }) => {
expect(allowedVersionsRe.test(input)).toEqual(expected);
expect(matchRegexOrGlob(input, allowedVersions)).toEqual(expected);
});
});
});
Expand Down

0 comments on commit 6200e1c

Please sign in to comment.