Skip to content

Commit

Permalink
Fix ArrayNode
Browse files Browse the repository at this point in the history
  • Loading branch information
bboure committed Dec 12, 2019
1 parent fcc9a6f commit 7a376b1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
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([])
});
});

0 comments on commit 7a376b1

Please sign in to comment.