forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(assertions): support for conditions (aws#18577)
Add conditions matcher to assertion package. Required by aws#18560. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
64f92d6
commit 4f98db7
Showing
5 changed files
with
207 additions
and
4 deletions.
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { filterLogicalId, formatFailure, matchSection } from './section'; | ||
import { Template } from './template'; | ||
|
||
export function findConditions(template: Template, logicalId: string, props: any = {}): { [key: string]: { [key: string]: any } } { | ||
const section: { [key: string] : {} } = template.Conditions; | ||
const result = matchSection(filterLogicalId(section, logicalId), props); | ||
|
||
if (!result.match) { | ||
return {}; | ||
} | ||
|
||
return result.matches; | ||
} | ||
|
||
export function hasCondition(template: Template, logicalId: string, props: any): string | void { | ||
const section: { [key: string] : {} } = template.Conditions; | ||
const result = matchSection(filterLogicalId(section, logicalId), props); | ||
if (result.match) { | ||
return; | ||
} | ||
|
||
if (result.closestResult === undefined) { | ||
return 'No conditions found in the template'; | ||
} | ||
|
||
return [ | ||
`Template has ${result.analyzedCount} conditions, but none match as expected.`, | ||
formatFailure(result.closestResult), | ||
].join('\n'); | ||
} |
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
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