Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Commit

Permalink
Fixes issue #191 - tests should always return the environment to a pr… (
Browse files Browse the repository at this point in the history
#192)

* Fixes issue #191 - tests should always return the environment to a pristine state.

* Update CHANGELOG.md
  • Loading branch information
RazzM13 authored and martysweet committed Sep 7, 2018
1 parent c3aa2fc commit a3c0a14
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 74 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,9 @@ Versioning](http://semver.org/spec/v2.0.0.html).
### Changed
- Update CloudFormation specification (downloaded 05-Sep-2018) - version: 2.6.0

### Fixed
- Merge PR #192, fixing incorrect exit codes from the test suite during CI/CD

## [1.8.0] - 2018-08-02
### Added
- Merge PR #185, implement CLI argument support for import values
Expand Down
159 changes: 85 additions & 74 deletions src/test/indexTest.ts
Expand Up @@ -6,6 +6,9 @@ const exec = childProcess.exec;

const proxyquire = require('proxyquire-2').noPreserveCache();

let realProcessARGV: any = null;
let realProcessExit: any = null;

let logToConsole = true;
let _log = console.log;
console.log = function() {
Expand All @@ -23,8 +26,7 @@ console.error = function() {
describe('index', () => {


describe('CLI', () => {

describe('CLI - functional tests', () => {

it('no parameters', (done) => {
exec('node lib/index.js', function(error, stdout, stderr) {
Expand All @@ -40,7 +42,6 @@ describe('index', () => {
});
}).timeout(5000);;


it('validate simple yaml', (done) => {

exec('node lib/index.js validate testData/valid/yaml/issue-28-custom-resource.yaml', function(error, stdout, stderr) {
Expand Down Expand Up @@ -80,7 +81,6 @@ describe('index', () => {
});
}).timeout(5000);


it('validate pseudo + parameter flag', (done) => {

exec('node lib/index.js validate testData/valid/yaml/pseudo-w-parameter.yaml ' +
Expand All @@ -99,7 +99,6 @@ describe('index', () => {
});
}).timeout(5000);


it('guess-parameters should explicitely opt in to parameter mocking', (done) => {
exec('node lib/index.js validate testData/valid/yaml/no-guess-parameters.yaml --guess-parameters', function(error, stdout, stderr) {
expect(stdout).to.contain('0 crit');
Expand Down Expand Up @@ -166,78 +165,90 @@ describe('index', () => {
});
}).timeout(5000);

it('custom resource attribute parameter should accept an arbitrary attribute value using resource-type notation', (done) => {
process.exit = () => { return undefined as never; };
process.argv = ['', '', 'validate', 'testData/valid/yaml/smoke.yaml', '--custom-resource-attributes', 'AWS::CloudFormation::CustomResource.SomeAttribute=[1\\,2]'];
logToConsole = false;
proxyquire('../index', {
'./validator': {
addCustomResourceAttributeValue: (x: any, y: any, z: any) => {
logToConsole = true;
expect(x).to.equal('AWS::CloudFormation::CustomResource');
expect(y).to.equal('SomeAttribute');
expect(z).to.deep.equal([1, 2]);
done();
logToConsole = false;
},
validateFile: () => { return {errors: {info: [], warn: [], crit: []}}},
'@global': true
}
});
logToConsole = true;
}).timeout(5000);
});

it('custom resource attribute parameter should accept an arbitrary attribute value using logical-name notation', (done) => {
process.exit = () => { return undefined as never; };
process.argv = ['', '', 'validate', 'testData/valid/yaml/smoke.yaml', '--custom-resource-attributes', 'SomethingBeautiful.SomeAttribute=test'];
logToConsole = false;
proxyquire('../index', {
'./validator': {
addCustomResourceAttributeValue: (x: any, y: any, z: any) => {
logToConsole = true;
expect(x).to.equal('SomethingBeautiful');
expect(y).to.equal('SomeAttribute');
expect(z).to.equal('test');

describe('CLI - unit tests', () => {

beforeEach(() => {
realProcessARGV = process.argv;
realProcessExit = process.exit;
logToConsole = false;
});

afterEach(() => {
process.argv = realProcessARGV;
process.exit = realProcessExit;
logToConsole = true;
});

it('custom resource attribute parameter should accept an arbitrary attribute value using resource-type notation', (done) => {
process.exit = () => { return undefined as never; };
process.argv = ['', '', 'validate', 'testData/valid/yaml/smoke.yaml', '--custom-resource-attributes', 'AWS::CloudFormation::CustomResource.SomeAttribute=[1\\,2]'];
proxyquire('../index', {
'./validator': {
addCustomResourceAttributeValue: (x: any, y: any, z: any) => {
logToConsole = true;
expect(x).to.equal('AWS::CloudFormation::CustomResource');
expect(y).to.equal('SomeAttribute');
expect(z).to.deep.equal([1, 2]);
done();
logToConsole = false;
},
validateFile: () => { return {errors: {info: [], warn: [], crit: []}}},
'@global': true
}
});
}).timeout(5000);

it('custom resource attribute parameter should accept an arbitrary attribute value using logical-name notation', (done) => {
process.exit = () => { return undefined as never; };
process.argv = ['', '', 'validate', 'testData/valid/yaml/smoke.yaml', '--custom-resource-attributes', 'SomethingBeautiful.SomeAttribute=test'];
proxyquire('../index', {
'./validator': {
addCustomResourceAttributeValue: (x: any, y: any, z: any) => {
logToConsole = true;
expect(x).to.equal('SomethingBeautiful');
expect(y).to.equal('SomeAttribute');
expect(z).to.equal('test');
done();
logToConsole = false;
},
validateFile: () => { return {errors: {info: [], warn: [], crit: []}}},
'@global': true
}
});
}).timeout(5000);

it('custom resource attribute parameter should accept an arbitrary attribute value using mixed notation', (done) => {
process.exit = () => { return undefined as never; };
process.argv = ['', '', 'validate', 'testData/valid/yaml/smoke.yaml', '--custom-resource-attributes', 'AWS::CloudFormation::CustomResource.SomeAttribute=hello,SomethingBeautiful.SomeAttribute=test,Custom::Dooby.SomeAttribute=blabla'];
let expectedValues = [
['AWS::CloudFormation::CustomResource', 'SomeAttribute', 'hello'],
['SomethingBeautiful', 'SomeAttribute', 'test'],
['Custom::Dooby', 'SomeAttribute', 'blabla'],
];
proxyquire('../index', {
'./validator': {
addCustomResourceAttributeValue: (x: any, y: any, z: any) => {
logToConsole = true;
let expected = expectedValues.shift();
if (!!expected) {
expect(x).to.equal(expected[0]);
expect(y).to.equal(expected[1]);
expect(z).to.equal(expected[2]);
}
if (expectedValues.length == 0) {
done();
logToConsole = false;
},
validateFile: () => { return {errors: {info: [], warn: [], crit: []}}},
'@global': true
}
});
logToConsole = true;
}).timeout(5000);
}
logToConsole = false;
},
validateFile: () => { return {errors: {info: [], warn: [], crit: []}}},
'@global': true
}
});
}).timeout(5000);

it('custom resource attribute parameter should accept an arbitrary attribute value using mixed notation', (done) => {
process.exit = () => { return undefined as never; };
process.argv = ['', '', 'validate', 'testData/valid/yaml/smoke.yaml', '--custom-resource-attributes', 'AWS::CloudFormation::CustomResource.SomeAttribute=hello,SomethingBeautiful.SomeAttribute=test,Custom::Dooby.SomeAttribute=blabla'];
logToConsole = false;
let expectedValues = [
['AWS::CloudFormation::CustomResource', 'SomeAttribute', 'hello'],
['SomethingBeautiful', 'SomeAttribute', 'test'],
['Custom::Dooby', 'SomeAttribute', 'blabla'],
];
proxyquire('../index', {
'./validator': {
addCustomResourceAttributeValue: (x: any, y: any, z: any) => {
logToConsole = true;
let expected = expectedValues.shift();
if (!!expected) {
expect(x).to.equal(expected[0]);
expect(y).to.equal(expected[1]);
expect(z).to.equal(expected[2]);
}
if (expectedValues.length == 0) {
done();
}
logToConsole = false;
},
validateFile: () => { return {errors: {info: [], warn: [], crit: []}}},
'@global': true
}
});
logToConsole = true;
}).timeout(5000);
});

});

0 comments on commit a3c0a14

Please sign in to comment.