-
Notifications
You must be signed in to change notification settings - Fork 4k
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 parameters (#18469)
Add the ability to match parameters in the template. Closes #16720 ---- *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
f511c17
commit d0d6fc5
Showing
4 changed files
with
214 additions
and
3 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
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 findParameters(template: Template, logicalId: string, props: any = {}): { [key: string]: { [key: string]: any } } { | ||
const section: { [key: string] : {} } = template.Parameters; | ||
const result = matchSection(filterLogicalId(section, logicalId), props); | ||
|
||
if (!result.match) { | ||
return {}; | ||
} | ||
|
||
return result.matches; | ||
} | ||
|
||
export function hasParameter(template: Template, logicalId: string, props: any): string | void { | ||
const section: { [key: string] : {} } = template.Parameters; | ||
const result = matchSection(filterLogicalId(section, logicalId), props); | ||
if (result.match) { | ||
return; | ||
} | ||
|
||
if (result.closestResult === undefined) { | ||
return 'No parameters found in the template'; | ||
} | ||
|
||
return [ | ||
`Template has ${result.analyzedCount} parameters, 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