From 30067ddc42dc05779e90060c9aea0600aacad356 Mon Sep 17 00:00:00 2001 From: David Manning Date: Mon, 16 May 2022 15:02:41 +0100 Subject: [PATCH 1/3] Add noDeploy option to serverless command options --- index.js | 6 ++++++ test/tests.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/index.js b/index.js index 24ac52b..c97534c 100644 --- a/index.js +++ b/index.js @@ -60,6 +60,12 @@ class AdditionalStacksPlugin { required: false, type: "string", }, + noDeploy: { + usage: "Generate the template but don't deploy the additional stacks(s)", + shortcut: 'n', + required: false, + type: "boolean", + }, }, }, }, diff --git a/test/tests.js b/test/tests.js index 84afe6b..3121806 100644 --- a/test/tests.js +++ b/test/tests.js @@ -75,6 +75,25 @@ function describeStack(stackName) { }) } +function describeStackEvents(stackName) { + return cloudformation.describeStackEvents({ + StackName: stackName, + }) + .promise() + .then(response => { + return response.StackEvents || [] + }) + .then(null, err => { + if (err.message && err.message.match(/does not exist$/)) { + // Stack doesn't exist yet + return null + } else { + // Some other error, let it throw + return Promise.reject(err) + } + }) +} + function deleteStack(stackName) { return Promise.resolve() .then(() => { @@ -419,3 +438,38 @@ describe('Stack Info', () => { }) }) }) + +describe('Dry run (--noDeploy) mode', () => { + before(() => { + // Clean up before tests + return deleteAllStacks().then(() => { + return sls(['deploy']); + }) + }) + + function getLatestStackEventTimestamp() { + return describeStackEvents(SECONDARY_STACK_FULLNAME).then((response) => { + return new Date(response[0].Timestamp) + }); + } + + it('Should not attempt to create or update stack when --noDeploy arg specified', () => { + return Promise.resolve() + .then(() => { + return sls(['deploy', 'additionalstacks', '--stack', SECONDARY_STACK]) //, '--topicname', 'newname']) + }).then(getLatestStackEventTimestamp).then((previous) => { + return sls(['deploy', 'additionalstacks', '--stack', SECONDARY_STACK, '--topicname', 'newname', '--noDeploy']) + .then(getLatestStackEventTimestamp) + .then((latest) => { + assert.deepEqual(previous, latest) // should be no new events + return latest; + }) + }).then(getLatestStackEventTimestamp).then((previous) => { + return sls(['deploy', 'additionalstacks', '--stack', SECONDARY_STACK, '--topicname', 'newname']) + .then(getLatestStackEventTimestamp) + .then((latest) => { + assert.isAbove(latest.getTime(), previous.getTime()) // should be new events now + }) + }) + }) +}) From deb1416aaa2f1cb21f4fb49d2b771dbb6b00bcde Mon Sep 17 00:00:00 2001 From: David Manning Date: Mon, 16 May 2022 15:48:39 +0100 Subject: [PATCH 2/3] Switch new test to async/await --- test/tests.js | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/test/tests.js b/test/tests.js index 3121806..67ab3e7 100644 --- a/test/tests.js +++ b/test/tests.js @@ -18,7 +18,7 @@ const chalk = require('chalk') // set region if not set (as not set by the SDK by default) if (!AWS.config.region) { AWS.config.update({ - region: 'us-east-1' + region: 'eu-west-2' }); } @@ -440,36 +440,25 @@ describe('Stack Info', () => { }) describe('Dry run (--noDeploy) mode', () => { - before(() => { + before(async () => { // Clean up before tests - return deleteAllStacks().then(() => { - return sls(['deploy']); - }) + await deleteAllStacks() + return await sls(['deploy', 'additionalstacks', '--stack', SECONDARY_STACK]); }) - function getLatestStackEventTimestamp() { - return describeStackEvents(SECONDARY_STACK_FULLNAME).then((response) => { - return new Date(response[0].Timestamp) - }); + const getLatestStackEventTimestamp = async() => { + const response = await describeStackEvents(SECONDARY_STACK_FULLNAME) + return new Date(response[0].Timestamp) } - it('Should not attempt to create or update stack when --noDeploy arg specified', () => { - return Promise.resolve() - .then(() => { - return sls(['deploy', 'additionalstacks', '--stack', SECONDARY_STACK]) //, '--topicname', 'newname']) - }).then(getLatestStackEventTimestamp).then((previous) => { - return sls(['deploy', 'additionalstacks', '--stack', SECONDARY_STACK, '--topicname', 'newname', '--noDeploy']) - .then(getLatestStackEventTimestamp) - .then((latest) => { - assert.deepEqual(previous, latest) // should be no new events - return latest; - }) - }).then(getLatestStackEventTimestamp).then((previous) => { - return sls(['deploy', 'additionalstacks', '--stack', SECONDARY_STACK, '--topicname', 'newname']) - .then(getLatestStackEventTimestamp) - .then((latest) => { - assert.isAbove(latest.getTime(), previous.getTime()) // should be new events now - }) - }) + it('Should not attempt to create or update stack when --noDeploy arg specified', async () => { + const previous = await getLatestStackEventTimestamp() + await sls(['deploy', 'additionalstacks', '--stack', SECONDARY_STACK, '--topicname', 'newname', '--noDeploy']) + const latestAfterNoDeploy = await getLatestStackEventTimestamp() + assert.deepEqual(previous, latestAfterNoDeploy) // should be no new events + + await sls(['deploy', 'additionalstacks', '--stack', SECONDARY_STACK, '--topicname', 'newname']) + const latestAfterDeploy = await getLatestStackEventTimestamp() + assert.isAbove(latestAfterDeploy.getTime(), latestAfterNoDeploy.getTime()) // should be new events now }) }) From 950ace57212f2a97e167cc65685c110a8c120b0f Mon Sep 17 00:00:00 2001 From: David Manning Date: Mon, 16 May 2022 15:49:45 +0100 Subject: [PATCH 3/3] Revert region switch --- test/tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests.js b/test/tests.js index 67ab3e7..ce085f9 100644 --- a/test/tests.js +++ b/test/tests.js @@ -18,7 +18,7 @@ const chalk = require('chalk') // set region if not set (as not set by the SDK by default) if (!AWS.config.region) { AWS.config.update({ - region: 'eu-west-2' + region: 'us-east-1' }); }