Skip to content
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

Fix ArrayNode #2

Merged
merged 1 commit into from
Dec 12, 2019
Merged
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "1.1.0",
"description": "Library that resolves AWS Cloudformation templates with exact values",
"main": "src/index.js",
"type": "module",
"scripts": {
"test": "mocha --recursive",
"coverage": "nyc --all --reporter cobertura --reporter text --report-dir ./coverage npm run test",
Expand Down
4 changes: 2 additions & 2 deletions src/convertNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const azMapping = require('./AZMap.json');

const convertNode = (node, nodeAccessor, srcObj, params, convRoot, enableVerboseLogging) => {
// keeping backward compatibility because of typo in previos versions
const refResolvers = params.RefResolvers || params.RefResolevers;
const refResolvers = params.RefResolvers || params.RefResolevers || {};

switch (nodeAccessor.key) {
case "Fn::FindInMap":
Expand Down Expand Up @@ -55,7 +55,7 @@ const convertNode = (node, nodeAccessor, srcObj, params, convRoot, enableVerbose
case "Ref":
return new RefNode(node, nodeAccessor, enableVerboseLogging, refResolvers);
case "Fn::GetAtt":
return new FnGetAttNode(node, nodeAccessor, enableVerboseLogging, params["Fn::GetAttResolvers"]);
return new FnGetAttNode(node, nodeAccessor, enableVerboseLogging, params["Fn::GetAttResolvers"] || {});
}

if( _.isArray(nodeAccessor.node)){
Expand Down
2 changes: 1 addition & 1 deletion src/nodeEvaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { convertNode } = require("./convertNode");
class NodeEvaluator {
constructor(srcObj, params, enableVerboseLogging){
this.srcObj = srcObj;
this.params = params;
this.params = params || {};
this.enableVerboseLogging = enableVerboseLogging;
}

Expand Down
25 changes: 11 additions & 14 deletions src/nodeTypes/ArrayNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,18 @@ class ArrayNode extends Node {
super.log("Eval: ", this.nodeAccessor.path.join('/'));
if(this.isLeaf){
super.log("Leaf: ", this.node, this.nodeAccessor.path.join('/'));
console.warn("Invalid Array: has no items, how to evaluate??");
throw "Invalid Array: has no items, how to evaluate??";
return ""; // Simple value (number, string)
} else {
const result = []
this.directDependencies.forEach( (dep) => {
const depRes = dep.evaluate();
result[dep.nodeAccessor.key] = depRes;
});

super.log("Array evaluated: ");
super.log(result);

return this.evaluateResultedArray(result);
}

const result = []
this.directDependencies.forEach( (dep) => {
const depRes = dep.evaluate();
result[dep.nodeAccessor.key] = depRes;
});

super.log("Array evaluated: ");
super.log(result);

return this.evaluateResultedArray(result);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/nodeTypes/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class Node {
this.enableVerboseLogging = enableVerboseLogging;
}

log(str) {
log(...str) {
if(this.enableVerboseLogging){
console.log(str);
console.log(...str);
}
}

Expand Down
6 changes: 5 additions & 1 deletion test/nodeTypes/ArrayNode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ describe('ArrayNode', () => {
expect(actual).to.deep.equal(["item0", nestedArray , "item2"])
});

// TODO: testcase when array is empty
it('evaluate empty arrays', () => {
const actual = target.evaluate();

expect(actual).to.deep.equal([])
});
});