-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(assertions): queries and assertions against the Outputs and Mappings sections #15892
Conversation
Outputs
and Templates
sectionsOutputs
and Mappings
sections
Outputs
and Mappings
sectionsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing blocking, but consider some of the DRY ideas in my first comment. The rest is nitpicking.
import { StackInspector } from '../vendored/assert'; | ||
import { formatFailure, matchSection } from './section'; | ||
|
||
export function findMappings(inspector: StackInspector, props: any = {}): { [key: string]: any }[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider DRYing up mappings/outputs/resources, or am I over-optimizing too soon? It seems like they could all be written as one method with two extra inputs. I just see a lot of copy/paste between all three files.
function findSection(inspector: StackInspector, props: any = {}, sectionFn: (x: StackInspector) => any): MatchSuccess | MatchFailure {
const matcher = Matcher.isMatcher(props) ? props : Match.objectLike(props);
return matchSection(sectionFn(inspector), matcher);
}
function hasSection(inspector: StackInspector, props: any = {}, sectionFn: (x: StackInspector) => any, sectionName: string): string | void {
const result = findSection(inspector, props, sectionFn);
if (result.match) {
return;
}
if (result.closestResult === undefined) {
return `No ${sectionName} found in the template`;
}
return [
`Template has ${result.analyzedCount} ${sectionName}, but none match as expected.`,
formatFailure(result.closestResult),
].join('\n');
}
export function findMappings(inspector: StackInspector, props: any = {}): { [key: string]: any }[] {
const result = findSection(inspector, props, (x) => x.value.Mappings ?? {});
return result.match ? result.matches : [];
}
export function hasMapping(inspector: StackInspector, props: any): string | void {
return hasSection(inspector, props, (x) => x.value.Mappings ?? {}, 'mappings');
}
export function findOutputs(inspector: StackInspector, props: any = {}): { [key: string]: any }[] {
const result = findSection(inspector, props, (x) => x.value.Outputs ?? {});
return result.match ? result.matches : [];
}
export function hasOutput(inspector: StackInspector, props: any): string | void {
return hasSection(inspector, props, (x) => x.value.Outputs ?? {}, 'outputs');
}
(Now that I've seen section.ts
: Maybe it's just that some/all of this could be moved into matchSection? Certainly the const matcher = Matcher.isMatcher(props) ? props : Match.objectLike(props);
line could be moved, right?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have considered this and played around with how much control these methods should retain. It was the usual design choices of 'separation of concerns' and 'layering'.
I decided to not expose StackInspector
into the section
methods (lower layer) and let the individual methods keep control over the values returned / exception messages thrown.
Certainly the
const matcher = Matcher.isMatcher(props) ? props : Match.objectLike(props);
line could be moved, right?
You are correct about this. Moved this to the layer below.
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
…ings sections (aws#15892) Introduce APIs `hasOutput()`, `findOutputs()`, `hasMapping()` and `findMappings()` to assert the `Mappings` and `Outputs` section of the CloudFormation template. Also, refactored the implementation of `hasResource()` to increase re-usability of its implementation across these new APIs. Migrated the modules `aws-kinesisfirehose` and `aws-neptune` that use these new APIs. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
…ings sections (aws#15892) Introduce APIs `hasOutput()`, `findOutputs()`, `hasMapping()` and `findMappings()` to assert the `Mappings` and `Outputs` section of the CloudFormation template. Also, refactored the implementation of `hasResource()` to increase re-usability of its implementation across these new APIs. Migrated the modules `aws-kinesisfirehose` and `aws-neptune` that use these new APIs. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
…ings sections (aws#15892) Introduce APIs `hasOutput()`, `findOutputs()`, `hasMapping()` and `findMappings()` to assert the `Mappings` and `Outputs` section of the CloudFormation template. Also, refactored the implementation of `hasResource()` to increase re-usability of its implementation across these new APIs. Migrated the modules `aws-kinesisfirehose` and `aws-neptune` that use these new APIs. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Introduce APIs
hasOutput()
,findOutputs()
,hasMapping()
and
findMappings()
to assert theMappings
andOutputs
section of the CloudFormation template.
Also, refactored the implementation of
hasResource()
toincrease re-usability of its implementation across these new APIs.
Migrated the modules
aws-kinesisfirehose
andaws-neptune
that use these new APIs.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license