Skip to content

Commit

Permalink
support workbench-image-recommended annotation being set to false
Browse files Browse the repository at this point in the history
add util test
  • Loading branch information
Gkrumbach07 committed Jan 2, 2024
1 parent 6b260d7 commit bbbde4a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AWS_KEYS } from '~/pages/projects/dataConnections/const';
import {
getExistingVersionsForImageStream,
isAWSValid,
checkVersionRecommended, // Added import for the new function
} from '~/pages/projects/screens/spawner/spawnerUtils';
import { EnvVariableDataEntry } from '~/pages/projects/types';
import { mockImageStreamK8sResource } from '~/__mocks__/mockImageStreamK8sResource';
Expand Down Expand Up @@ -135,3 +136,42 @@ describe('getExistingVersionsForImageStream', () => {
expect(result[0]).toEqual({ name: 'should-be-included' });
});
});

describe('checkVersionRecommended', () => {
it('should return true if the image version is recommended', () => {
const imageVersion = {
name: 'test-image',
annotations: {
[IMAGE_ANNOTATIONS.RECOMMENDED]: 'true',
},
};
expect(checkVersionRecommended(imageVersion)).toBe(true);
});

it('should return false if the image version is not recommended', () => {
const imageVersion = {
name: 'test-image',
annotations: {
[IMAGE_ANNOTATIONS.RECOMMENDED]: 'false',
},
};
expect(checkVersionRecommended(imageVersion)).toBe(false);
});

it('should return false if the image version does not have the recommended annotation', () => {
const imageVersion = {
name: 'test-image',
};
expect(checkVersionRecommended(imageVersion)).toBe(false);
});

it('should return false if the image version is invalid JSON', () => {
const imageVersion = {
name: 'test-image',
annotations: {
[IMAGE_ANNOTATIONS.RECOMMENDED]: 'invalid-json',
},
};
expect(checkVersionRecommended(imageVersion)).toBe(false);
});
});
6 changes: 3 additions & 3 deletions frontend/src/pages/projects/screens/spawner/spawnerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ export const compareTagVersions = (
b: ImageStreamSpecTagType,
): number => {
// Recommended tags should be first
if (a.annotations?.[IMAGE_ANNOTATIONS.RECOMMENDED]) {
if (checkVersionRecommended(a)) {
return -1;
} else if (b.annotations?.[IMAGE_ANNOTATIONS.RECOMMENDED]) {
} else if (checkVersionRecommended(b)) {
return 1;
}
if (compareVersions.validate(a.name) && compareVersions.validate(b.name)) {
Expand Down Expand Up @@ -322,7 +322,7 @@ export const checkVersionExistence = (
};

export const checkVersionRecommended = (imageVersion: ImageStreamSpecTagType): boolean =>
!!imageVersion.annotations?.[IMAGE_ANNOTATIONS.RECOMMENDED];
imageVersion.annotations?.[IMAGE_ANNOTATIONS.RECOMMENDED] === 'true';

export const isValidGenericKey = (key: string): boolean => !!key;

Expand Down

0 comments on commit bbbde4a

Please sign in to comment.