Skip to content

Commit

Permalink
feat(versioning): added test cases and fix code coverage
Browse files Browse the repository at this point in the history
Signed-off-by: ivan katliarchuk <[email protected]>
  • Loading branch information
ivankatliarchuk committed Jan 3, 2025
1 parent d324456 commit d4dd226
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 50 deletions.
130 changes: 85 additions & 45 deletions lib/modules/versioning/aws-eks-addon/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,56 @@ describe('modules/versioning/aws-eks-addon/index', () => {
});

describe('isValid(version)', () => {
it('should return true', () => {
expect(aws.isValid('v1.11.7-eksbuild.23')).toBeTruthy();
});

it('should return false', () => {
expect(aws.isValid('v1.11.7-noneksbuild.23')).toBeFalsy();
it.each`
input | expected
${''} | ${false}
${'.1..'} | ${false}
${'abrakadabra'} | ${false}
${'v1'} | ${false}
${'v1.'} | ${false}
${'v1...-eksbuild.1'} | ${false}
${'v1-eksbuild.1'} | ${false}
${'v1.a-eksbuild.1'} | ${false}
${'v1.23-eksbuild.1'} | ${false}
${'1.23.1-eksbuild.a'} | ${false}
${'v1.11.7'} | ${false}
${'v1.11.7.6'} | ${false}
${'v1.11.7-noneksbuild'} | ${false}
${'v1.11.7-noneksbuild.1'} | ${false}
${'v1.11.7-eksbuild'} | ${false}
${'v1.11.7.3-eksbuild.1'} | ${false}
${'v1.23.1-eksbuild.1'} | ${true}
${'1.23.1-eksbuild.1'} | ${true}
${'v1.23.1-eksbuild.11'} | ${true}
`('isValid("$input") === $expected', ({ input, expected }) => {
const actual = aws.isValid(input);
expect(actual).toBe(expected);
});
});

describe('isVersion(version)', () => {
it('should return true', () => {
expect(aws.isVersion('v1.11.7-eksbuild.1')).toBeTruthy();
});

it('should return false', () => {
expect(aws.isVersion('v1.11.7')).toBeFalsy();
it.each`
input | expected
${''} | ${false}
${'abrakadabra'} | ${false}
${'v1'} | ${false}
${'v1.'} | ${false}
${'v1-eksbuild.1'} | ${false}
${'v1.a-eksbuild.1'} | ${false}
${'v1.23-eksbuild.1'} | ${false}
${'1.23.1-eksbuild.a'} | ${false}
${'v1.11.7'} | ${false}
${'v1.11.7.6'} | ${false}
${'v1.11.7-noneksbuild'} | ${false}
${'v1.11.7-noneksbuild.1'} | ${false}
${'v1.11.7-eksbuild'} | ${false}
${'v1.11.7.3-eksbuild.1'} | ${false}
${'v1.23.1-eksbuild.1'} | ${true}
${'1.23.1-eksbuild.1'} | ${true}
${'v1.23.1-eksbuild.11'} | ${true}
`('isValid("$input") === $expected', ({ input, expected }) => {
const actual = aws.isVersion(input);
expect(actual).toBe(expected);
});
});

Expand All @@ -34,6 +68,13 @@ describe('modules/versioning/aws-eks-addon/index', () => {
input | expected
${''} | ${false}
${'abrakadabra'} | ${false}
${'v1'} | ${false}
${'v1.'} | ${false}
${'v1-eksbuild.1'} | ${false}
${'v1.a-eksbuild.1'} | ${false}
${'v1.23-eksbuild.1'} | ${false}
${'1.23.1-eksbuild.1'} | ${false}
${'1.23.1-eksbuild.a'} | ${false}
${'v1.11.7'} | ${false}
${'v1.11.7.6'} | ${false}
${'v1.11.7-noneksbuild'} | ${false}
Expand All @@ -47,42 +88,41 @@ describe('modules/versioning/aws-eks-addon/index', () => {
});

describe('isCompatible(version,range)', () => {
it('should return true', () => {
expect(
aws.isCompatible('v1.11.7-eksbuild.1', 'v1.2.7-eksbuild.1'),
).toBeTruthy();
});

it('should return false', () => {
expect(
aws.isCompatible('v1.11.7-eksbuild.1', 'v1.11.7-noneksbuild.1'),
).toBeFalsy();
});
it.each`
version | current | expected
${'1.23.1-eksbuild.1'} | ${'1.23.1-eksbuild.2'} | ${true}
${'v1.23.1-eksbuild.1'} | ${'1.23.1-eksbuild.2'} | ${true}
${'v1.23.1-eksbuild.1'} | ${'1.23.1-eksbuild.21'} | ${true}
${'v1.11.7-eksbuild.1'} | ${'v1.11.7-noneksbuild.1'} | ${false}
${'v1.11.7'} | ${'v1.11.7-noneksbuild.1'} | ${false}
${'v1-eksbuild.1'} | ${'artful'} | ${false}
${'v1.11.7.1-eksbuild.1'} | ${'v1.11.7-eksbuild.1'} | ${false}
`(
'isCompatible($version, $current) === $expected',
({ version, current, expected }) => {
const actual = aws.isCompatible(version, current);
expect(actual).toBe(expected);
},
);
});

describe('isGreaterThan(version1, version2)', () => {
it('should return true', () => {
expect(
aws.isGreaterThan('v1.11.7-eksbuild.1', 'v1.11.7-eksbuild.0'),
).toBeTrue();
expect(
aws.isGreaterThan('v1.20.7-eksbuild.2', 'v1.20.7-eksbuild.1'),
).toBeTrue();
expect(
aws.isGreaterThan('v1.22.7-eksbuild.2', 'v1.20.7-eksbuild.1'),
).toBeTrue();
expect(aws.isGreaterThan('v1.22.7-eksbuild.2', 'v1.22.7')).toBeTrue();
expect(aws.isGreaterThan('v1.20.7-eksbuild.1', 'v2.0.0')).toBeTrue();
});

it('should return false', () => {
expect(
aws.isGreaterThan('v1.20.7-eksbuild.1', 'v1.20.7-eksbuild.2'),
).toBeFalsy();
expect(
aws.isGreaterThan('v1.20.7-eksbuild.1', 'v2.0.0-eksbuild.1'),
).toBeFalsy();
});
it.each`
version | other | expected
${'v1.11.7-eksbuild.1'} | ${'v1.11.7-eksbuild.0'} | ${true}
${'v1.22.7-eksbuild.2'} | ${'v1.20.7-eksbuild.1'} | ${true}
${'v1.22.7-eksbuild.2'} | ${'v1.22.7'} | ${true}
${'v1.20.7-eksbuild.1'} | ${'v2.0.0'} | ${true}
${'v1.20.7-eksbuild.1'} | ${'v1.20.7-eksbuild.2'} | ${false}
${'v1.20.6-eksbuild.1'} | ${'v1.20.7-eksbuild.2'} | ${false}
${'v1.20.7-eksbuild.1'} | ${'v2.0.0-eksbuild.1'} | ${false}
`(
'isGreaterThan($version, other) === $expected',
({ version, other, expected }) => {
const actual = aws.isGreaterThan(version, other);
expect(actual).toBe(expected);
},
);
});

it('getSatisfyingVersion', () => {
Expand Down
10 changes: 5 additions & 5 deletions lib/modules/versioning/aws-eks-addon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const urls = [];
export const supportsRanges = false;

const versionPattern = regEx(
'^v?(?<major>\\d+)\\.(?<minor>\\d+)?\\.(?<patch>\\d+)?(?<metadata>-eksbuild\\.\\d+)?$',
'^v?(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(?<metadata>-eksbuild\\.\\d+)?$',
);

export class AwsEKSAddonVersioningApi extends GenericVersioningApi {
Expand All @@ -21,14 +21,14 @@ export class AwsEKSAddonVersioningApi extends GenericVersioningApi {
return null;
}
const matches = versionPattern.exec(version);
if (!matches?.groups?.metadata) {
if (!matches?.groups) {
return null;
}
const [, major, minor, patch, suffix] = matches;
if (!major || !minor || !patch || !suffix) {
const { major, minor, patch, metadata: suffix } = matches.groups;
if (!suffix) {
return null;
}
const release: number[] = [Number(major), Number(minor), Number(patch)];
const release = [Number(major), Number(minor), Number(patch)];
return { release, suffix };
}

Expand Down

0 comments on commit d4dd226

Please sign in to comment.