Skip to content

Commit

Permalink
Update version check regex and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKahr committed Mar 17, 2024
1 parent 2c1b403 commit 84b41f7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
6 changes: 6 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions src/model/image-tag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ImageTag from './image-tag';

describe('ImageTag', () => {
const testImageParameters = {
editorVersion: '2099.9.f9f9',
editorVersion: '2099.9.9f9',
targetPlatform: 'Test',
builderPlatform: '',
containerRegistryRepository: 'unityci/editor',
Expand Down Expand Up @@ -37,6 +37,11 @@ describe('ImageTag', () => {
).not.toThrow();
});

test.each(['some version', ''])('throws for incorrect version %p', (editorVersion) => {
const { targetPlatform } = testImageParameters;
expect(() => new ImageTag({ editorVersion, targetPlatform })).toThrow();
});

test.each(['nonExisting'])('throws for unsupported target %p', (targetPlatform) => {
expect(() => new ImageTag({ targetPlatform })).toThrow();
});
Expand All @@ -45,23 +50,23 @@ describe('ImageTag', () => {
describe('toString', () => {
it('returns the correct version', () => {
const image = new ImageTag({
editorVersion: '2099.1.1111',
editorVersion: '2099.1.1111f1',
targetPlatform: testImageParameters.targetPlatform,
containerRegistryRepository: 'unityci/editor',
containerRegistryImageVersion: '3',
});
switch (process.platform) {
case 'win32':
expect(image.toString()).toStrictEqual(`${defaults.image}:windows-2099.1.1111-3`);
expect(image.toString()).toStrictEqual(`${defaults.image}:windows-2099.1.1111f1-3`);
break;
case 'linux':
expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2099.1.1111-3`);
expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2099.1.1111f1-3`);
break;
}
});
it('returns customImage if given', () => {
const image = new ImageTag({
editorVersion: '2099.1.1111',
editorVersion: '2099.1.1111f1',
targetPlatform: testImageParameters.targetPlatform,
customImage: `${defaults.image}:2099.1.1111@347598437689743986`,
containerRegistryRepository: 'unityci/editor',
Expand Down
8 changes: 8 additions & 0 deletions src/model/image-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class ImageTag {
providerStrategy,
} = imageProperties;

if (!ImageTag.versionPattern.test(editorVersion)) {
throw new Error(`Invalid version "${editorVersion}".`);
}

// Todo we might as well skip this class for customImage.
// Either
this.customImage = customImage;
Expand All @@ -37,6 +41,10 @@ class ImageTag {
this.imageRollingVersion = Number(containerRegistryImageVersion); // Will automatically roll to the latest non-breaking version.
}

static get versionPattern(): RegExp {
return /^\d+\.\d+\.\d+[a-z]\d+$/;
}

static get targetPlatformSuffixes() {
return {
generic: '',
Expand Down

0 comments on commit 84b41f7

Please sign in to comment.