Skip to content

Commit c74a28e

Browse files
committed
chore: fixed bug in a condition, added missing tests
1 parent 94e6095 commit c74a28e

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
@@ -1201,7 +1201,7 @@ describe('Deploy CloudFormation Stack', () => {
12011201
expect(mockExecuteChangeSet).toHaveBeenCalledTimes(0)
12021202
})
12031203

1204-
test('deploys the stack with template', async () => {
1204+
test('deploys the stack with prefixed envs', async () => {
12051205
const inputs: Inputs = {
12061206
name: 'MockStack',
12071207
template: 'template.yaml',
@@ -1225,6 +1225,8 @@ describe('Deploy CloudFormation Stack', () => {
12251225

12261226
await run()
12271227

1228+
delete process.env.CFD_AdminNickname
1229+
12281230
expect(core.setFailed).toHaveBeenCalledTimes(0)
12291231
expect(mockDescribeStacks).toHaveBeenCalledTimes(2)
12301232
expect(mockDescribeStacks).toHaveBeenNthCalledWith(1, {
@@ -1248,6 +1250,95 @@ describe('Deploy CloudFormation Stack', () => {
12481250
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'stack-id', mockStackId)
12491251
})
12501252

1253+
test('deploys the stack with prefixed envs but no envs are passed', async () => {
1254+
const inputs: Inputs = {
1255+
name: 'MockStack',
1256+
template: 'template.yaml',
1257+
capabilities: 'CAPABILITY_IAM',
1258+
'parameter-overrides': '[email protected]',
1259+
'envs-prefix-for-parameter-overrides': 'CFD_',
1260+
'no-fail-on-empty-changeset': '0',
1261+
'disable-rollback': '0',
1262+
'timeout-in-minutes': '',
1263+
'notification-arns': '',
1264+
'role-arn': '',
1265+
tags: '',
1266+
'termination-protection': ''
1267+
}
1268+
1269+
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
1270+
return inputs[name]
1271+
})
1272+
1273+
await run()
1274+
1275+
expect(core.setFailed).toHaveBeenCalledTimes(0)
1276+
expect(mockDescribeStacks).toHaveBeenCalledTimes(2)
1277+
expect(mockDescribeStacks).toHaveBeenNthCalledWith(1, {
1278+
StackName: 'MockStack'
1279+
})
1280+
expect(mockDescribeStacks).toHaveBeenNthCalledWith(2, {
1281+
StackName: mockStackId
1282+
})
1283+
expect(mockCreateStack).toHaveBeenNthCalledWith(1, {
1284+
StackName: 'MockStack',
1285+
TemplateBody: mockTemplate,
1286+
Capabilities: ['CAPABILITY_IAM'],
1287+
Parameters: [
1288+
{ ParameterKey: 'AdminEmail', ParameterValue: '[email protected]' }
1289+
],
1290+
DisableRollback: false,
1291+
EnableTerminationProtection: false
1292+
})
1293+
expect(core.setOutput).toHaveBeenCalledTimes(1)
1294+
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'stack-id', mockStackId)
1295+
})
1296+
1297+
test('deploys the stack with prefixed envs but no other parameter overrides are passed', async () => {
1298+
const inputs: Inputs = {
1299+
name: 'MockStack',
1300+
template: 'template.yaml',
1301+
capabilities: 'CAPABILITY_IAM',
1302+
'envs-prefix-for-parameter-overrides': 'CFD_',
1303+
'no-fail-on-empty-changeset': '0',
1304+
'disable-rollback': '0',
1305+
'timeout-in-minutes': '',
1306+
'notification-arns': '',
1307+
'role-arn': '',
1308+
tags: '',
1309+
'termination-protection': ''
1310+
}
1311+
1312+
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
1313+
return inputs[name]
1314+
})
1315+
1316+
process.env = Object.assign(process.env, { CFD_AdminNickname: 'root' })
1317+
1318+
await run()
1319+
1320+
delete process.env.CFD_AdminNickname
1321+
1322+
expect(core.setFailed).toHaveBeenCalledTimes(0)
1323+
expect(mockDescribeStacks).toHaveBeenCalledTimes(2)
1324+
expect(mockDescribeStacks).toHaveBeenNthCalledWith(1, {
1325+
StackName: 'MockStack'
1326+
})
1327+
expect(mockDescribeStacks).toHaveBeenNthCalledWith(2, {
1328+
StackName: mockStackId
1329+
})
1330+
expect(mockCreateStack).toHaveBeenNthCalledWith(1, {
1331+
StackName: 'MockStack',
1332+
TemplateBody: mockTemplate,
1333+
Capabilities: ['CAPABILITY_IAM'],
1334+
Parameters: [{ ParameterKey: 'AdminNickname', ParameterValue: 'root' }],
1335+
DisableRollback: false,
1336+
EnableTerminationProtection: false
1337+
})
1338+
expect(core.setOutput).toHaveBeenCalledTimes(1)
1339+
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'stack-id', mockStackId)
1340+
})
1341+
12511342
test('error is caught by core.setFailed', async () => {
12521343
mockDescribeStacks.mockReset()
12531344
mockDescribeStacks.mockImplementation(() => {

dist/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ function run() {
300300
if (parameterOverrides) {
301301
params.Parameters = (0, utils_1.parseParameters)(parameterOverrides.trim());
302302
}
303-
if (envsPrefixForParameterOverrides.length > 0) {
303+
if (envsPrefixForParameterOverrides) {
304304
const envParameters = (0, utils_1.parseParametersFromEnvs)(envsPrefixForParameterOverrides, process.env);
305305
params.Parameters = params.Parameters
306306
? [...params.Parameters, ...envParameters]

src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export async function run(): Promise<void> {
132132
params.Parameters = parseParameters(parameterOverrides.trim())
133133
}
134134

135-
if (envsPrefixForParameterOverrides.length > 0) {
135+
if (envsPrefixForParameterOverrides) {
136136
const envParameters = parseParametersFromEnvs(
137137
envsPrefixForParameterOverrides,
138138
process.env

0 commit comments

Comments
 (0)