Skip to content

Add noDeploy option to serverless command options #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
},
Expand Down
43 changes: 43 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -419,3 +438,27 @@ describe('Stack Info', () => {
})
})
})

describe('Dry run (--noDeploy) mode', () => {
before(async () => {
// Clean up before tests
await deleteAllStacks()
return await sls(['deploy', 'additionalstacks', '--stack', SECONDARY_STACK]);
})

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', 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
})
})