Skip to content

Commit bd9f82f

Browse files
committed
chore: fixed bug in a condition, added missing tests
1 parent 95ae279 commit bd9f82f

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

__tests__/main.test.ts

+92-1
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ describe('Deploy CloudFormation Stack', () => {
13891389
expect(mockCfnClient).toHaveReceivedCommandTimes(ExecuteChangeSetCommand, 0)
13901390
})
13911391

1392-
test('deploys the stack with template', async () => {
1392+
test('deploys the stack with prefixed envs', async () => {
13931393
const inputs: Inputs = {
13941394
name: 'MockStack',
13951395
template: 'template.yaml',
@@ -1413,6 +1413,8 @@ describe('Deploy CloudFormation Stack', () => {
14131413

14141414
await run()
14151415

1416+
delete process.env.CFD_AdminNickname
1417+
14161418
expect(core.setFailed).toHaveBeenCalledTimes(0)
14171419
expect(mockDescribeStacks).toHaveBeenCalledTimes(2)
14181420
expect(mockDescribeStacks).toHaveBeenNthCalledWith(1, {
@@ -1436,6 +1438,95 @@ describe('Deploy CloudFormation Stack', () => {
14361438
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'stack-id', mockStackId)
14371439
})
14381440

1441+
test('deploys the stack with prefixed envs but no envs are passed', async () => {
1442+
const inputs: Inputs = {
1443+
name: 'MockStack',
1444+
template: 'template.yaml',
1445+
capabilities: 'CAPABILITY_IAM',
1446+
'parameter-overrides': '[email protected]',
1447+
'envs-prefix-for-parameter-overrides': 'CFD_',
1448+
'no-fail-on-empty-changeset': '0',
1449+
'disable-rollback': '0',
1450+
'timeout-in-minutes': '',
1451+
'notification-arns': '',
1452+
'role-arn': '',
1453+
tags: '',
1454+
'termination-protection': ''
1455+
}
1456+
1457+
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
1458+
return inputs[name]
1459+
})
1460+
1461+
await run()
1462+
1463+
expect(core.setFailed).toHaveBeenCalledTimes(0)
1464+
expect(mockDescribeStacks).toHaveBeenCalledTimes(2)
1465+
expect(mockDescribeStacks).toHaveBeenNthCalledWith(1, {
1466+
StackName: 'MockStack'
1467+
})
1468+
expect(mockDescribeStacks).toHaveBeenNthCalledWith(2, {
1469+
StackName: mockStackId
1470+
})
1471+
expect(mockCreateStack).toHaveBeenNthCalledWith(1, {
1472+
StackName: 'MockStack',
1473+
TemplateBody: mockTemplate,
1474+
Capabilities: ['CAPABILITY_IAM'],
1475+
Parameters: [
1476+
{ ParameterKey: 'AdminEmail', ParameterValue: '[email protected]' }
1477+
],
1478+
DisableRollback: false,
1479+
EnableTerminationProtection: false
1480+
})
1481+
expect(core.setOutput).toHaveBeenCalledTimes(1)
1482+
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'stack-id', mockStackId)
1483+
})
1484+
1485+
test('deploys the stack with prefixed envs but no other parameter overrides are passed', async () => {
1486+
const inputs: Inputs = {
1487+
name: 'MockStack',
1488+
template: 'template.yaml',
1489+
capabilities: 'CAPABILITY_IAM',
1490+
'envs-prefix-for-parameter-overrides': 'CFD_',
1491+
'no-fail-on-empty-changeset': '0',
1492+
'disable-rollback': '0',
1493+
'timeout-in-minutes': '',
1494+
'notification-arns': '',
1495+
'role-arn': '',
1496+
tags: '',
1497+
'termination-protection': ''
1498+
}
1499+
1500+
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
1501+
return inputs[name]
1502+
})
1503+
1504+
process.env = Object.assign(process.env, { CFD_AdminNickname: 'root' })
1505+
1506+
await run()
1507+
1508+
delete process.env.CFD_AdminNickname
1509+
1510+
expect(core.setFailed).toHaveBeenCalledTimes(0)
1511+
expect(mockDescribeStacks).toHaveBeenCalledTimes(2)
1512+
expect(mockDescribeStacks).toHaveBeenNthCalledWith(1, {
1513+
StackName: 'MockStack'
1514+
})
1515+
expect(mockDescribeStacks).toHaveBeenNthCalledWith(2, {
1516+
StackName: mockStackId
1517+
})
1518+
expect(mockCreateStack).toHaveBeenNthCalledWith(1, {
1519+
StackName: 'MockStack',
1520+
TemplateBody: mockTemplate,
1521+
Capabilities: ['CAPABILITY_IAM'],
1522+
Parameters: [{ ParameterKey: 'AdminNickname', ParameterValue: 'root' }],
1523+
DisableRollback: false,
1524+
EnableTerminationProtection: false
1525+
})
1526+
expect(core.setOutput).toHaveBeenCalledTimes(1)
1527+
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'stack-id', mockStackId)
1528+
})
1529+
14391530
test('error is caught by core.setFailed', async () => {
14401531
mockCfnClient.reset().on(DescribeStacksCommand).rejects(new Error())
14411532

dist/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ function run() {
319319
if (parameterOverrides) {
320320
params.Parameters = (0, utils_1.parseParameters)(parameterOverrides.trim());
321321
}
322-
if (envsPrefixForParameterOverrides.length > 0) {
322+
if (envsPrefixForParameterOverrides) {
323323
const envParameters = (0, utils_1.parseParametersFromEnvs)(envsPrefixForParameterOverrides, process.env);
324324
params.Parameters = params.Parameters
325325
? [...params.Parameters, ...envParameters]

src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export async function run(): Promise<void> {
157157
params.Parameters = parseParameters(parameterOverrides.trim())
158158
}
159159

160-
if (envsPrefixForParameterOverrides.length > 0) {
160+
if (envsPrefixForParameterOverrides) {
161161
const envParameters = parseParametersFromEnvs(
162162
envsPrefixForParameterOverrides,
163163
process.env

0 commit comments

Comments
 (0)