|
1 | 1 | const _ = require('lodash'); |
| 2 | +const CFError = require('cf-errors'); |
2 | 3 | const helper = require('./image'); |
3 | 4 | const { createEntity, entityList } = require('./entitiesManifests'); |
| 5 | +const { prepareKeyValueObjectsFromCLIEnvOption } = require('./general'); |
4 | 6 |
|
5 | 7 | const { extractImages } = helper; |
6 | 8 |
|
@@ -32,6 +34,43 @@ describe('helpers unit tests', () => { |
32 | 34 | } |
33 | 35 | }); |
34 | 36 |
|
| 37 | + describe('general', () => { |
| 38 | + describe('prepareKeyValueObjectsFromCLIEnvOption', () => { |
| 39 | + it('should parse key value object from array', () => { |
| 40 | + const result = prepareKeyValueObjectsFromCLIEnvOption([ |
| 41 | + 'SECRET_PASS=YWJjZA===', |
| 42 | + 'USERNAME=testUserName', |
| 43 | + ]); |
| 44 | + expect(result).toEqual([ |
| 45 | + { |
| 46 | + key: 'SECRET_PASS', |
| 47 | + value: 'YWJjZA===', |
| 48 | + }, |
| 49 | + { |
| 50 | + key: 'USERNAME', |
| 51 | + value: 'testUserName', |
| 52 | + }, |
| 53 | + ]); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should parse key value object from string', () => { |
| 57 | + const result = prepareKeyValueObjectsFromCLIEnvOption('TEST=testData'); |
| 58 | + expect(result).toEqual([ |
| 59 | + { |
| 60 | + key: 'TEST', |
| 61 | + value: 'testData', |
| 62 | + }, |
| 63 | + ]); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should throw error when add incorrect environment variable', () => { |
| 67 | + expect( |
| 68 | + () => prepareKeyValueObjectsFromCLIEnvOption('TEST'), |
| 69 | + ).toThrow(new CFError('Invalid environment variable format. please enter [key]=[value]')); |
| 70 | + }); |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
35 | 74 | describe('images', () => { |
36 | 75 | describe('#extractImages', () => { |
37 | 76 | beforeAll(() => { |
@@ -93,10 +132,10 @@ describe('helpers unit tests', () => { |
93 | 132 | }, |
94 | 133 | ]; |
95 | 134 | const extracted = extractImages(images); |
96 | | - const extractedDates = _.map(extracted, i => i.info.created); |
| 135 | + const extractedDates = _.map(extracted, (i) => i.info.created); |
97 | 136 | const initialSortedDates = _.chain(images) |
98 | 137 | .orderBy(['created'], ['desc']) |
99 | | - .map(i => i.created) |
| 138 | + .map((i) => i.created) |
100 | 139 | .value(); |
101 | 140 | expect(extractedDates).toEqual(initialSortedDates); |
102 | 141 | }); |
|
0 commit comments