Update version check regex and fix tests

This commit is contained in:
Andrew Kahr 2024-03-17 10:25:47 -07:00
parent 2c1b4030c8
commit 84b41f77fc
4 changed files with 18 additions and 5 deletions

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View File

@ -2,7 +2,7 @@ import ImageTag from './image-tag';
describe('ImageTag', () => { describe('ImageTag', () => {
const testImageParameters = { const testImageParameters = {
editorVersion: '2099.9.f9f9', editorVersion: '2099.9.9f9',
targetPlatform: 'Test', targetPlatform: 'Test',
builderPlatform: '', builderPlatform: '',
containerRegistryRepository: 'unityci/editor', containerRegistryRepository: 'unityci/editor',
@ -37,6 +37,11 @@ describe('ImageTag', () => {
).not.toThrow(); ).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) => { test.each(['nonExisting'])('throws for unsupported target %p', (targetPlatform) => {
expect(() => new ImageTag({ targetPlatform })).toThrow(); expect(() => new ImageTag({ targetPlatform })).toThrow();
}); });
@ -45,23 +50,23 @@ describe('ImageTag', () => {
describe('toString', () => { describe('toString', () => {
it('returns the correct version', () => { it('returns the correct version', () => {
const image = new ImageTag({ const image = new ImageTag({
editorVersion: '2099.1.1111', editorVersion: '2099.1.1111f1',
targetPlatform: testImageParameters.targetPlatform, targetPlatform: testImageParameters.targetPlatform,
containerRegistryRepository: 'unityci/editor', containerRegistryRepository: 'unityci/editor',
containerRegistryImageVersion: '3', containerRegistryImageVersion: '3',
}); });
switch (process.platform) { switch (process.platform) {
case 'win32': 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; break;
case 'linux': 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; break;
} }
}); });
it('returns customImage if given', () => { it('returns customImage if given', () => {
const image = new ImageTag({ const image = new ImageTag({
editorVersion: '2099.1.1111', editorVersion: '2099.1.1111f1',
targetPlatform: testImageParameters.targetPlatform, targetPlatform: testImageParameters.targetPlatform,
customImage: `${defaults.image}:2099.1.1111@347598437689743986`, customImage: `${defaults.image}:2099.1.1111@347598437689743986`,
containerRegistryRepository: 'unityci/editor', containerRegistryRepository: 'unityci/editor',

View File

@ -20,6 +20,10 @@ class ImageTag {
providerStrategy, providerStrategy,
} = imageProperties; } = imageProperties;
if (!ImageTag.versionPattern.test(editorVersion)) {
throw new Error(`Invalid version "${editorVersion}".`);
}
// Todo we might as well skip this class for customImage. // Todo we might as well skip this class for customImage.
// Either // Either
this.customImage = customImage; this.customImage = customImage;
@ -37,6 +41,10 @@ class ImageTag {
this.imageRollingVersion = Number(containerRegistryImageVersion); // Will automatically roll to the latest non-breaking version. 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() { static get targetPlatformSuffixes() {
return { return {
generic: '', generic: '',