This repository has been archived by the owner on Apr 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Fn::Select #104
Merged
Merged
Fn::Select #104
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
886de44
Fn::Select functionality
kcculhwch 0a0abd7
parse the number
kcculhwch 5b05558
udating with lots of json tests
kcculhwch 0bafc75
small fix for console.log call
kcculhwch 93b0798
Checking for more possiblities of valid and invalid usages, more test…
kcculhwch 0ace222
Merge pull request #1 from martysweet/master
kcculhwch a754adc
handling commaDelimiedList default data, turning into array
kcculhwch d992705
updates for yaml tests, minor corrections to crit messages, and chang…
kcculhwch 67b7d98
fixing typo and spacing
kcculhwch a1d8af7
updated test with better comments, and explicit checking of error mes…
kcculhwch 4c3f420
package.json needs to specify approx 2.6.2, otherwise tyepscript 2.7.…
kcculhwch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ function cleanupYaml(ref: any){ | |
let key = Object.keys(ref)[i]; | ||
|
||
// Resolve the function | ||
if(ref[key].hasOwnProperty('class') && ref[key].hasOwnProperty('data')){ | ||
if( ref[key] !== null && ref[key].hasOwnProperty('class') && ref[key].hasOwnProperty('data')){ | ||
|
||
// We have a Yaml generated object | ||
|
||
|
@@ -96,12 +96,12 @@ function cleanupYaml(ref: any){ | |
ref[key] = {}; | ||
ref[key][outputKeyName] = outputData; | ||
|
||
}else if(key != 'Attributes' && typeof ref[key] == "object"){ | ||
}else if(key != 'Attributes' && typeof ref[key] == "object" && ref[key] !== null){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here too. The result of this was that I had to modify the invalid json doc, so that it would also be invalid yaml |
||
lastPlaceInTemplate = ref; | ||
lastKeyInTemplate = key; | ||
cleanupYaml(ref[key]); | ||
} | ||
|
||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,247 @@ describe('validator', () => { | |
expect(result).to.have.deep.property('templateValid', true); | ||
expect(result['errors']['warn']).to.have.lengthOf(1); | ||
}); | ||
describe('Fn::Select', () => { | ||
it("should pass validation, with flat list and intrinsic list", () => { | ||
const input = require('../../testData/valid/json/5_valid_intrinsic_select.json'); | ||
let result = validator.validateJsonObject(input); | ||
expect(result).to.have.deep.property('templateValid', true); | ||
expect(result['errors']['crit']).to.have.lengthOf(0); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
}); | ||
it("should pass validation with Parameter Collection", () => { | ||
const input = require('../../testData/valid/json/5_valid_intrinsic_select_2.json'); | ||
let result = validator.validateJsonObject(input); | ||
expect(result).to.have.deep.property('templateValid', true); | ||
expect(result['errors']['crit']).to.have.lengthOf(0); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
}); | ||
|
||
|
||
it("should error if index is greater than list size", () => { | ||
const input = require('../../testData/invalid/json/5_invalid_intrinsic_select_1.json'); | ||
let result = validator.validateJsonObject(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
// console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if second element is not a list or a function", () => { | ||
const input = require('../../testData/invalid/json/5_invalid_intrinsic_select_2.json'); | ||
let result = validator.validateJsonObject(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
// console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if first element is not a number or does not parse to a number", () => { | ||
const input = require('../../testData/invalid/json/5_invalid_intrinsic_select_3.json'); | ||
let result = validator.validateJsonObject(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
// console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if first element is not defined or is null", () => { | ||
const input = require('../../testData/invalid/json/5_invalid_intrinsic_select_4.json'); | ||
let result = validator.validateJsonObject(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
// console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if only one element as argument list", () => { | ||
const input = require('../../testData/invalid/json/5_invalid_intrinsic_select_5.json'); | ||
let result = validator.validateJsonObject(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
// console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if second element is null or undefined", () => { | ||
const input = require('../../testData/invalid/json/5_invalid_intrinsic_select_6.json'); | ||
let result = validator.validateJsonObject(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
// console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if second element does not resolve to a list", () => { | ||
const input = require('../../testData/invalid/json/5_invalid_intrinsic_select_7.json'); | ||
let result = validator.validateJsonObject(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
// console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if first element does not resolve to a number", () => { | ||
const input = require('../../testData/invalid/json/5_invalid_intrinsic_select_8.json'); | ||
let result = validator.validateJsonObject(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
// console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if first element attempts an invalid intrinsic function", () => { | ||
const input = require('../../testData/invalid/json/5_invalid_intrinsic_select_9.json'); | ||
let result = validator.validateJsonObject(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
// console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if first element is anything other than non-array object, number or string", () => { | ||
const input = require('../../testData/invalid/json/5_invalid_intrinsic_select_10.json'); | ||
let result = validator.validateJsonObject(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
// console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would also be good to ensure the YAML shorthand is working as expected.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep |
||
|
||
it("should error if second element attempts an invalid intrinsic function", () => { | ||
const input = require('../../testData/invalid/json/5_invalid_intrinsic_select_11.json'); | ||
let result = validator.validateJsonObject(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
// console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if second element contains a list with null values", () => { | ||
const input = require('../../testData/invalid/json/5_invalid_intrinsic_select_12.json'); | ||
let result = validator.validateJsonObject(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
// console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
|
||
}); | ||
|
||
|
||
}); | ||
|
||
describe('Fn::Select', () => { | ||
it('should validate in yaml with literal and intrinic elements in array', () => { | ||
const input = './testData/valid/yaml/5_valid_intrinsic_select.yaml'; | ||
let result = validator.validateFile(input); | ||
expect(result).to.have.deep.property('templateValid', true); | ||
expect(result['errors']['crit']).to.have.lengthOf(0); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
|
||
|
||
}); | ||
|
||
it('should validate in yaml with Comma Separated List Param', () => { | ||
const input = './testData/valid/yaml/5_valid_intrinsic_select_2.yaml'; | ||
let result = validator.validateFile(input); | ||
expect(result).to.have.deep.property('templateValid', true); | ||
expect(result['errors']['crit']).to.have.lengthOf(0); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
|
||
|
||
}); | ||
|
||
|
||
it("should error if index is greater than list size", () => { | ||
const input = './testData/invalid/yaml/5_invalid_intrinsic_select_1.yaml'; | ||
let result = validator.validateFile(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if second element is not a list or a function", () => { | ||
const input = './testData/invalid/yaml/5_invalid_intrinsic_select_2.yaml'; | ||
let result = validator.validateFile(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if first element is not a number or does not parse to a number", () => { | ||
const input = './testData/invalid/yaml/5_invalid_intrinsic_select_3.yaml'; | ||
let result = validator.validateFile(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if first element is not defined or is null", () => { | ||
const input = './testData/invalid/yaml/5_invalid_intrinsic_select_4.yaml'; | ||
let result = validator.validateFile(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if only one element as argument list", () => { | ||
const input = './testData/invalid/yaml/5_invalid_intrinsic_select_5.yaml'; | ||
let result = validator.validateFile(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if second element is null or undefined", () => { | ||
const input = './testData/invalid/yaml/5_invalid_intrinsic_select_6.yaml'; | ||
let result = validator.validateFile(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if second element does not resolve to a list", () => { | ||
const input = './testData/invalid/yaml/5_invalid_intrinsic_select_7.yaml'; | ||
let result = validator.validateFile(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if first element does not resolve to a number", () => { | ||
const input = './testData/invalid/yaml/5_invalid_intrinsic_select_8.yaml'; | ||
let result = validator.validateFile(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if first element attempts an invalid intrinsic function", () => { | ||
const input = './testData/invalid/yaml/5_invalid_intrinsic_select_9.yaml'; | ||
let result = validator.validateFile(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if first element is anything other than non-array object, number or string", () => { | ||
const input = './testData/invalid/yaml/5_invalid_intrinsic_select_10.yaml'; | ||
let result = validator.validateFile(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
|
||
it("should error if second element attempts an invalid intrinsic function", () => { | ||
const input = './testData/invalid/yaml/5_invalid_intrinsic_select_11.yaml'; | ||
let result = validator.validateFile(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
it("should error if second element contains a list with null values", () => { | ||
const input = './testData/invalid/yaml/5_invalid_intrinsic_select_12.yaml'; | ||
let result = validator.validateFile(input); | ||
expect(result).to.have.deep.property('templateValid', false); | ||
expect(result['errors']['crit']).to.have.lengthOf(1); | ||
expect(result['errors']['warn']).to.have.lengthOf(0); | ||
console.log(result['errors']['crit'][0]['message']); | ||
}); | ||
|
||
|
||
|
||
}); | ||
|
||
|
@@ -836,4 +1077,4 @@ describe('validator', () => { | |
|
||
}) | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that I needed to make a couple of changes to the parser to block the script from trying to parse out null entries in yaml arrays.