Skip to content

Commit 74ca08c

Browse files
committed
Ensure that all tests and test coverage pass
1 parent 65d3429 commit 74ca08c

File tree

5 files changed

+363
-54
lines changed

5 files changed

+363
-54
lines changed

__tests__/utils.test.ts

+273-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,50 @@ describe('Parse Parameters', () => {
8484
process.env = oldEnv
8585
})
8686

87+
test('returns parameters empty string', async () => {
88+
const json = parseParameters('')
89+
expect(json).toEqual([])
90+
})
91+
92+
test('returns parameters empty YAML', async () => {
93+
const json = parseParameters('0')
94+
expect(json).toEqual([])
95+
})
96+
97+
type CFParameterValue = string | string[] | boolean
98+
type CFParameterObject = Record<string, CFParameterValue>
99+
100+
test('handles empty parameter overrides object', () => {
101+
const parameterOverrides: CFParameterObject = {}
102+
const result = parseParameters(parameterOverrides)
103+
expect(result).toEqual([])
104+
})
105+
106+
test('handles undefined values in parameter overrides object', () => {
107+
const parameterOverrides: CFParameterObject = {
108+
ValidParam: 'value',
109+
EmptyParam: '',
110+
ListParam: ['value1', 'value2']
111+
}
112+
113+
const result = parseParameters(parameterOverrides)
114+
115+
expect(result).toEqual([
116+
{
117+
ParameterKey: 'ValidParam',
118+
ParameterValue: 'value'
119+
},
120+
{
121+
ParameterKey: 'EmptyParam',
122+
ParameterValue: ''
123+
},
124+
{
125+
ParameterKey: 'ListParam',
126+
ParameterValue: 'value1,value2'
127+
}
128+
])
129+
})
130+
87131
test('returns parameters list from string', async () => {
88132
const json = parseParameters('MyParam1=myValue1,MyParam2=myValue2')
89133
expect(json).toEqual([
@@ -116,7 +160,7 @@ describe('Parse Parameters', () => {
116160

117161
test('returns parameters list with an extra equal', async () => {
118162
const json = parseParameters(
119-
'MyParam1=myValue1,MyParam2=myValue2=myValue3,MyParam2=myValue4'
163+
'MyParam1=myValue1,MyParam2=myValue2=myValue3,MyParam2=myValue4 '
120164
)
121165
expect(json).toEqual([
122166
{
@@ -177,6 +221,85 @@ describe('Parse Parameters', () => {
177221
])
178222
})
179223

224+
test('returns parameters list from YAML array format', async () => {
225+
const yaml = `
226+
- ParameterKey: MyParam1
227+
ParameterValue: myValue1
228+
- ParameterKey: MyParam2
229+
ParameterValue: myValue2
230+
`
231+
const json = parseParameters(yaml)
232+
expect(json).toEqual([
233+
{
234+
ParameterKey: 'MyParam1',
235+
ParameterValue: 'myValue1'
236+
},
237+
{
238+
ParameterKey: 'MyParam2',
239+
ParameterValue: 'myValue2'
240+
}
241+
])
242+
})
243+
244+
test('handles YAML with nested values', async () => {
245+
const yaml = `
246+
MyParam1: myValue1
247+
MyParam2:
248+
- item1
249+
- item2
250+
MyParam3:
251+
key: value
252+
MyParam4: {"key":"value"}
253+
`
254+
const json = parseParameters(yaml)
255+
expect(json).toEqual([
256+
{
257+
ParameterKey: 'MyParam1',
258+
ParameterValue: 'myValue1'
259+
},
260+
{
261+
ParameterKey: 'MyParam2',
262+
ParameterValue: 'item1,item2'
263+
},
264+
{
265+
ParameterKey: 'MyParam3',
266+
ParameterValue: '{"key":"value"}'
267+
},
268+
{
269+
ParameterKey: 'MyParam4',
270+
ParameterValue: '{"key":"value"}'
271+
}
272+
])
273+
})
274+
275+
test('handles YAML with boolean and number values', async () => {
276+
const yaml = `
277+
BoolParam: true
278+
NumberParam: 123
279+
StringParam: 'hello'
280+
NullParam: null
281+
`
282+
const json = parseParameters(yaml)
283+
expect(json).toEqual([
284+
{
285+
ParameterKey: 'BoolParam',
286+
ParameterValue: 'true'
287+
},
288+
{
289+
ParameterKey: 'NumberParam',
290+
ParameterValue: '123'
291+
},
292+
{
293+
ParameterKey: 'StringParam',
294+
ParameterValue: 'hello'
295+
},
296+
{
297+
ParameterKey: 'NullParam',
298+
ParameterValue: ''
299+
}
300+
])
301+
})
302+
180303
test('throws error if file is not found', async () => {
181304
const filename = 'file://' + path.join(__dirname, 'params.tezt.json')
182305
expect(() => parseParameters(filename)).toThrow()
@@ -189,6 +312,155 @@ describe('Parse Parameters', () => {
189312
})
190313
})
191314

315+
describe('Parse Tags', () => {
316+
test('parses tags from YAML array format', () => {
317+
const yaml = `
318+
- Key: Environment
319+
Value: Production
320+
- Key: Project
321+
Value: MyApp
322+
- Key: CostCenter
323+
Value: '12345'
324+
`
325+
const result = parseTags(yaml)
326+
expect(result).toEqual([
327+
{
328+
Key: 'Environment',
329+
Value: 'Production'
330+
},
331+
{
332+
Key: 'Project',
333+
Value: 'MyApp'
334+
},
335+
{
336+
Key: 'CostCenter',
337+
Value: '12345'
338+
}
339+
])
340+
})
341+
342+
test('parses tags from YAML object format', () => {
343+
const yaml = `
344+
Environment: Production
345+
Project: MyApp
346+
CostCenter: '12345'
347+
`
348+
const result = parseTags(yaml)
349+
expect(result).toEqual([
350+
{
351+
Key: 'Environment',
352+
Value: 'Production'
353+
},
354+
{
355+
Key: 'Project',
356+
Value: 'MyApp'
357+
},
358+
{
359+
Key: 'CostCenter',
360+
Value: '12345'
361+
}
362+
])
363+
})
364+
365+
test('handles empty YAML input', () => {
366+
expect(parseTags('')).toEqual(undefined)
367+
expect(parseTags('0')).toEqual(undefined)
368+
})
369+
370+
test('handles YAML with different value types', () => {
371+
const yaml = `
372+
Environment: Production
373+
IsProduction: true
374+
InstanceCount: 5
375+
FloatValue: 3.14
376+
`
377+
const result = parseTags(yaml)
378+
expect(result).toEqual([
379+
{
380+
Key: 'Environment',
381+
Value: 'Production'
382+
},
383+
{
384+
Key: 'IsProduction',
385+
Value: 'true'
386+
},
387+
{
388+
Key: 'InstanceCount',
389+
Value: '5'
390+
},
391+
{
392+
Key: 'FloatValue',
393+
Value: '3.14'
394+
}
395+
])
396+
})
397+
398+
test('handles malformed YAML', () => {
399+
const malformedYaml = `
400+
This is not valid YAML
401+
- Key: Missing Value
402+
`
403+
expect(parseTags(malformedYaml)).toEqual(undefined)
404+
})
405+
406+
test('handles array format with missing required fields', () => {
407+
const yaml = `
408+
- Key: ValidTag
409+
Value: ValidValue
410+
- Value: MissingKey
411+
- Key: MissingValue
412+
`
413+
const result = parseTags(yaml)
414+
expect(result).toEqual([
415+
{
416+
Key: 'ValidTag',
417+
Value: 'ValidValue'
418+
}
419+
])
420+
})
421+
422+
test('handles object format with empty values', () => {
423+
const yaml = `
424+
Environment:
425+
Project: MyApp
426+
EmptyString: ''
427+
`
428+
const result = parseTags(yaml)
429+
expect(result).toEqual([
430+
{
431+
Key: 'Environment',
432+
Value: ''
433+
},
434+
{
435+
Key: 'Project',
436+
Value: 'MyApp'
437+
},
438+
{
439+
Key: 'EmptyString',
440+
Value: ''
441+
}
442+
])
443+
})
444+
445+
test('preserves whitespace in tag values', () => {
446+
const yaml = `
447+
Description: This is a long description with spaces
448+
Path: /path/to/something
449+
`
450+
const result = parseTags(yaml)
451+
expect(result).toEqual([
452+
{
453+
Key: 'Description',
454+
Value: 'This is a long description with spaces'
455+
},
456+
{
457+
Key: 'Path',
458+
Value: '/path/to/something'
459+
}
460+
])
461+
})
462+
})
463+
192464
describe('Configure Proxy', () => {
193465
beforeEach(() => {
194466
jest.clearAllMocks()

package-lock.json

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
},
4242
"devDependencies": {
4343
"@types/jest": "^29.2.3",
44+
"@types/js-yaml": "^4.0.9",
4445
"@types/node": "^14.0.26",
4546
"@typescript-eslint/eslint-plugin": "^5.43.0",
4647
"@typescript-eslint/parser": "^5.43.0",

src/main.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,26 @@ export async function run(): Promise<void> {
5555
.map(capability => capability.trim()) as Capability[]
5656

5757
// Get parameter overrides - could be a string or a parsed YAML object
58-
const rawParameterOverrides = core.getInput('parameter-overrides', {
58+
const parameterOverrides = core.getInput('parameter-overrides', {
5959
required: false
6060
})
6161

62-
type CFParameterValue = string | string[] | boolean
63-
type CFParameterObject = Record<string, CFParameterValue>
64-
// Try to parse as JSON in case it's a YAML object that was auto-converted to JSON
65-
let parameterOverrides: string | Record<string, CFParameterObject> =
66-
rawParameterOverrides
67-
try {
68-
if (rawParameterOverrides) {
69-
const possibleObject = JSON.parse(rawParameterOverrides)
70-
if (possibleObject && typeof possibleObject === 'object') {
71-
parameterOverrides = possibleObject
72-
}
73-
}
74-
} catch (e) {
75-
// If parsing fails, use the raw string value
76-
core.debug('Parameter overrides is not a JSON object, using as string')
77-
}
62+
// type CFParameterValue = string | string[] | boolean
63+
// type CFParameterObject = Record<string, CFParameterValue>
64+
// // Try to parse as JSON in case it's a YAML object that was auto-converted to JSON
65+
// let parameterOverrides: string | Record<string, CFParameterObject> =
66+
// rawParameterOverrides
67+
// try {
68+
// if (rawParameterOverrides) {
69+
// const possibleObject = JSON.parse(rawParameterOverrides)
70+
// if (possibleObject && typeof possibleObject === 'object') {
71+
// parameterOverrides = possibleObject
72+
// }
73+
// }
74+
// } catch (e) {
75+
// // If parsing fails, use the raw string value
76+
// core.debug('Parameter overrides is not a JSON object, using as string')
77+
// }
7878
const noEmptyChangeSet = !!+core.getInput('no-fail-on-empty-changeset', {
7979
required: false
8080
})
@@ -170,7 +170,7 @@ export async function run(): Promise<void> {
170170
}
171171

172172
if (parameterOverrides) {
173-
params.Parameters = parseParameters(parameterOverrides.trim())
173+
params.Parameters = parseParameters(parameterOverrides)
174174
}
175175

176176
const stackId = await deployStack(

0 commit comments

Comments
 (0)