Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Fully validate Condition property #12

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
44 changes: 42 additions & 2 deletions src/__tests__/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Array [
"Fn::And",
"0",
],
"value": "\\"\\"",
},
]
`;
Expand All @@ -25,6 +26,7 @@ Array [
"C",
"Fn::And",
],
"value": "\\"\\"",
},
]
`;
Expand Down Expand Up @@ -86,6 +88,7 @@ Array [
"Fn::Not",
"0",
],
"value": "\\"\\"",
},
]
`;
Expand All @@ -100,6 +103,7 @@ Array [
"C",
"Fn::Not",
],
"value": "\\"\\"",
},
]
`;
Expand All @@ -119,6 +123,7 @@ Array [
"Fn::Or",
"0",
],
"value": "\\"\\"",
},
]
`;
Expand All @@ -133,6 +138,7 @@ Array [
"C",
"Fn::Or",
],
"value": "\\"\\"",
},
]
`;
Expand All @@ -148,6 +154,7 @@ Array [
"And",
"0",
],
"value": "\\"\\"",
},
]
`;
Expand All @@ -162,6 +169,7 @@ Array [
"C",
"And",
],
"value": "\\"\\"",
},
]
`;
Expand Down Expand Up @@ -223,6 +231,7 @@ Array [
"Not",
"0",
],
"value": "\\"\\"",
},
]
`;
Expand All @@ -237,6 +246,7 @@ Array [
"C",
"Not",
],
"value": "\\"\\"",
},
]
`;
Expand All @@ -256,6 +266,7 @@ Array [
"Or",
"0",
],
"value": "\\"\\"",
},
]
`;
Expand All @@ -270,6 +281,7 @@ Array [
"C",
"Or",
],
"value": "\\"\\"",
},
]
`;
Expand Down Expand Up @@ -390,6 +402,7 @@ Array [
"BucketName",
"Fn::ImportValue",
],
"value": "[\\"\\",[\\"\\"],\\"\\"]",
},
]
`;
Expand All @@ -406,6 +419,7 @@ Array [
"BucketName",
"Fn::ImportValue",
],
"value": "[[],\\"\\"]",
},
]
`;
Expand All @@ -422,6 +436,7 @@ Array [
"BucketName",
"Fn::ImportValue",
],
"value": "{\\"a\\":\\"\\"}",
},
]
`;
Expand All @@ -438,6 +453,7 @@ Array [
"BucketName",
"Fn::ImportValue",
],
"value": "[\\"\\"]",
},
]
`;
Expand All @@ -454,6 +470,7 @@ Array [
"BucketName",
"ImportValue",
],
"value": "[\\"\\",[\\"\\"],\\"\\"]",
},
]
`;
Expand All @@ -470,6 +487,7 @@ Array [
"BucketName",
"ImportValue",
],
"value": "[[],\\"\\"]",
},
]
`;
Expand All @@ -486,6 +504,7 @@ Array [
"BucketName",
"ImportValue",
],
"value": "{\\"a\\":\\"\\"}",
},
]
`;
Expand All @@ -502,6 +521,7 @@ Array [
"BucketName",
"ImportValue",
],
"value": "[\\"\\"]",
},
]
`;
Expand All @@ -518,6 +538,7 @@ Array [
"Root",
"Mappings",
],
"value": "\\"\\"",
},
]
`;
Expand All @@ -532,6 +553,7 @@ Array [
"a",
"b",
],
"value": "\\"\\"",
},
]
`;
Expand All @@ -552,6 +574,7 @@ Array [
"Root",
"Outputs",
],
"value": "\\"\\"",
},
]
`;
Expand All @@ -566,6 +589,7 @@ Array [
"O",
"Description",
],
"value": "{}",
},
]
`;
Expand All @@ -581,6 +605,7 @@ Array [
"Export",
"Name",
],
"value": "{}",
},
]
`;
Expand All @@ -595,6 +620,7 @@ Array [
"O",
"Value",
],
"value": "{}",
},
]
`;
Expand Down Expand Up @@ -819,6 +845,7 @@ Array [
"BucketName",
"Fn::Join",
],
"value": "\\"\\"",
},
]
`;
Expand All @@ -836,6 +863,7 @@ Array [
"Fn::Join",
"0",
],
"value": "[]",
},
Object {
"message": "must be a List, got \\"\\"",
Expand All @@ -848,6 +876,7 @@ Array [
"Fn::Join",
"1",
],
"value": "\\"\\"",
},
]
`;
Expand Down Expand Up @@ -896,6 +925,7 @@ Array [
"BucketName",
"Join",
],
"value": "\\"\\"",
},
]
`;
Expand All @@ -913,6 +943,7 @@ Array [
"Join",
"0",
],
"value": "[]",
},
Object {
"message": "must be a List, got \\"\\"",
Expand All @@ -925,6 +956,7 @@ Array [
"Join",
"1",
],
"value": "\\"\\"",
},
]
`;
Expand Down Expand Up @@ -973,6 +1005,7 @@ Array [
"BucketName",
"Ref",
],
"value": "[\\"A\\"]",
},
]
`;
Expand Down Expand Up @@ -1005,6 +1038,7 @@ Array [
"BucketName",
"Ref",
],
"value": "[\\"A\\"]",
},
]
`;
Expand Down Expand Up @@ -1070,6 +1104,7 @@ Array [
"Fn::Sub",
"0",
],
"value": "{}",
},
Object {
"message": "must be an Object, got \\"\${A}\\"",
Expand All @@ -1082,6 +1117,7 @@ Array [
"Fn::Sub",
"1",
],
"value": "\\"\${A}\\"",
},
]
`;
Expand Down Expand Up @@ -1179,6 +1215,7 @@ Array [
"Sub",
"0",
],
"value": "{}",
},
Object {
"message": "must be an Object, got \\"\${A}\\"",
Expand All @@ -1191,6 +1228,7 @@ Array [
"Sub",
"1",
],
"value": "\\"\${A}\\"",
},
]
`;
Expand Down Expand Up @@ -1411,7 +1449,7 @@ Array [
exports[`lint with parameters string values invalid default 1`] = `
Array [
Object {
"message": "must be a Number, got Ref ExpirationInDays",
"message": "must be a Number, got {\\"Ref\\":\\"ExpirationInDays\\"}",
"path": Array [
"Root",
"Resources",
Expand All @@ -1422,14 +1460,15 @@ Array [
"0",
"ExpirationInDays",
],
"value": "{\\"Ref\\":\\"ExpirationInDays\\"}",
},
]
`;

exports[`lint with parameters string values invalid value 1`] = `
Array [
Object {
"message": "must be a Number, got Ref ExpirationInDays",
"message": "must be a Number, got {\\"Ref\\":\\"ExpirationInDays\\"}",
"path": Array [
"Root",
"Resources",
Expand All @@ -1440,6 +1479,7 @@ Array [
"0",
"ExpirationInDays",
],
"value": "{\\"Ref\\":\\"ExpirationInDays\\"}",
},
]
`;
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,12 @@ export function lint(template: string, parameters: object = {}) {
];
const validate = new Walker(validators);
validate.Root(input);
return errors;

return _.map(errors, (e) => {
if ('value' in e) {
return {...e, message: `${e.message}, got ${e.value}`};
} else {
return e;
}
});
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type Error = {
path: Path,
message: string,
source?: string,
value?: string,
};

export class ResourceSpecificationError extends Error {
Expand Down
Loading