Skip to content

Commit

Permalink
feat(API): Adding support for passing a template string (#15)
Browse files Browse the repository at this point in the history
* master

adding support for passing a template string

* the template string needs to be promised in this chain

* templateString tests

* resolving lint errors

* fixing a lint error on test

* master

adding update stack test
  • Loading branch information
KerryRitter authored May 25, 2020
1 parent fab6b5e commit baaf47e
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ Write your application:
const cfnDeploy = require('cfn-deploy');

const eventStream = cfnDeploy({
region: 'us-east-1',
stackname: 'fancy-stack',
template: 'cfn/cfn-stack.yaml',
template: 'cfn/cfn-stack.yaml', // if referencing external file
templateString: JSON.stringify(myCloudFormationJson), // if using a template string already in memory
});

eventStream.on('EXECUTING_CHANGESET', () => {
Expand Down
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ module.exports = (args) => {
new Promise((resolve) => resolve())
// Load files
.then(() => events.emit('LOADING_FILES'))
.then(() => loadTemplateFile(args.template))
.then(() => {
if (args.templateString && args.templateString.length) {
return Promise.resolve(args.templateString);
}
return loadTemplateFile(args.template);
})
.then((newTemplateString) => { templateString = newTemplateString; })

// Parse params & tags
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`cfn-deploy should successfully create new stack 1`] = `
Object {
"Capabilities": Array [],
"ChangeSetName": "cfn-deploy",
"ChangeSetType": "CREATE",
"Description": "Created with cfn-deploy",
"Parameters": Array [],
"StackName": "new-stack",
"Tags": Array [],
"TemplateBody": "Resources:
S3Bucket:
Type: AWS::S3::Bucket
",
}
`;

exports[`cfn-deploy should successfully create new stack 2`] = `
Object {
"StackStatus": "REVIEW_IN_PROGRESS",
}
`;
22 changes: 22 additions & 0 deletions tests/create-stack/create-stack-string-template.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { readFileSync } = require('fs');
const mockCreateStack = require('../mocks/createStack');
const lib = require('../..');

describe('cfn-deploy', () => {
beforeAll(() => mockCreateStack.beforeAll());

it('should successfully create new stack', (done) => {
const events = lib({
region: 'us-east-1',
stackname: 'new-stack',
templateString: readFileSync('./tests/templates/simple-template.yaml').toString(),
});
events.on('ERROR', (err) => done(err));
events.on('COMPLETE', (data) => {
expect(data).toMatchSnapshot();
});
events.on('FINALLY', done);
});

afterAll(() => mockCreateStack.afterAll());
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`cfn-deploy should successfully create new stack 1`] = `
Object {
"Capabilities": Array [],
"ChangeSetName": "cfn-deploy",
"ChangeSetType": "UPDATE",
"Description": "Created with cfn-deploy",
"Parameters": Array [],
"StackName": "existing-stack",
"Tags": Array [],
"TemplateBody": "Resources:
S3Bucket:
Type: AWS::S3::Bucket
",
}
`;

exports[`cfn-deploy should successfully create new stack 2`] = `
Object {
"StackStatus": "UPDATE_COMPLETE",
}
`;
22 changes: 22 additions & 0 deletions tests/update-stack/update-stack-string-template.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { readFileSync } = require('fs');
const mockCreateStack = require('../mocks/updateStack');
const lib = require('../..');

describe('cfn-deploy', () => {
beforeAll(() => mockCreateStack.beforeAll());

it('should successfully create new stack', (done) => {
const events = lib({
region: 'us-east-1',
stackname: 'existing-stack',
templateString: readFileSync('./tests/templates/simple-template.yaml').toString(),
});
events.on('ERROR', (err) => done(err));
events.on('COMPLETE', (data) => {
expect(data).toMatchSnapshot();
});
events.on('FINALLY', done);
});

afterAll(() => mockCreateStack.afterAll());
});

0 comments on commit baaf47e

Please sign in to comment.