|
1 | 1 | import { AWS_KEYS } from '~/pages/projects/dataConnections/const';
|
2 |
| -import { isAWSValid } from '~/pages/projects/screens/spawner/spawnerUtils'; |
| 2 | +import { |
| 3 | + getExistingVersionsForImageStream, |
| 4 | + isAWSValid, |
| 5 | +} from '~/pages/projects/screens/spawner/spawnerUtils'; |
3 | 6 | import { EnvVariableDataEntry } from '~/pages/projects/types';
|
| 7 | +import { mockImageStreamK8sResource } from '~/__mocks__/mockImageStreamK8sResource'; |
| 8 | +import { IMAGE_ANNOTATIONS } from '~/pages/projects/screens/spawner/const'; |
4 | 9 |
|
5 | 10 | describe('isAWSValid', () => {
|
6 | 11 | const getMockAWSData = ({
|
@@ -67,3 +72,66 @@ describe('isAWSValid', () => {
|
67 | 72 | );
|
68 | 73 | });
|
69 | 74 | });
|
| 75 | + |
| 76 | +describe('getExistingVersionsForImageStream', () => { |
| 77 | + it('should handle no image tags', () => { |
| 78 | + const imageStream = mockImageStreamK8sResource({ |
| 79 | + opts: { spec: { tags: [] }, status: { tags: [] } }, |
| 80 | + }); |
| 81 | + expect(getExistingVersionsForImageStream(imageStream)).toHaveLength(0); |
| 82 | + }); |
| 83 | + |
| 84 | + it('should return the only default value', () => { |
| 85 | + expect(getExistingVersionsForImageStream(mockImageStreamK8sResource({}))).toHaveLength(1); |
| 86 | + }); |
| 87 | + |
| 88 | + it('should exclude the outdated items', () => { |
| 89 | + // Override the first value |
| 90 | + const imageStream = mockImageStreamK8sResource({ |
| 91 | + opts: { spec: { tags: [{ annotations: { [IMAGE_ANNOTATIONS.OUTDATED]: 'true' } }] } }, |
| 92 | + }); |
| 93 | + expect(getExistingVersionsForImageStream(imageStream)).toHaveLength(0); |
| 94 | + |
| 95 | + // Add an outdated 2nd value |
| 96 | + const imageStream2 = mockImageStreamK8sResource({ |
| 97 | + opts: { |
| 98 | + spec: { |
| 99 | + tags: [{}, { name: 'test', annotations: { [IMAGE_ANNOTATIONS.OUTDATED]: 'true' } }], |
| 100 | + }, |
| 101 | + }, |
| 102 | + }); |
| 103 | + expect(getExistingVersionsForImageStream(imageStream2)).toHaveLength(1); |
| 104 | + }); |
| 105 | + |
| 106 | + it('should exclude removed tags', () => { |
| 107 | + const imageStream = mockImageStreamK8sResource({ |
| 108 | + opts: { |
| 109 | + spec: { |
| 110 | + tags: [{ name: 'not-the-available-tag' }], |
| 111 | + }, |
| 112 | + }, |
| 113 | + }); |
| 114 | + expect(getExistingVersionsForImageStream(imageStream)).toHaveLength(0); |
| 115 | + }); |
| 116 | + |
| 117 | + it('should exclude removed tags & outdated ones', () => { |
| 118 | + const imageStream = mockImageStreamK8sResource({ |
| 119 | + opts: { |
| 120 | + spec: { |
| 121 | + tags: [ |
| 122 | + {}, |
| 123 | + { name: 'not-the-available-tag' }, |
| 124 | + { name: 'should-be-included' }, |
| 125 | + { name: 'outdated', annotations: { [IMAGE_ANNOTATIONS.OUTDATED]: 'true' } }, |
| 126 | + ], |
| 127 | + }, |
| 128 | + status: { |
| 129 | + tags: [{ tag: 'should-be-included' }, { tag: 'outdated' }], |
| 130 | + }, |
| 131 | + }, |
| 132 | + }); |
| 133 | + const result = getExistingVersionsForImageStream(imageStream); |
| 134 | + expect(result).toHaveLength(1); |
| 135 | + expect(result[0]).toEqual({ name: 'should-be-included' }); |
| 136 | + }); |
| 137 | +}); |
0 commit comments