Skip to content

Commit

Permalink
adding some code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
corymhall committed Sep 26, 2022
1 parent d74fc3e commit 4d0a4eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent
console.log(`Event: ${JSON.stringify({ ...event, ResponseURL: '...' })}`);
const provider = createResourceHandler(event, context);
try {
// if we are deleting the custom resource, just respond
// with 'SUCCESS' since there is nothing to do.
if (event.RequestType === 'Delete') {
await provider.respond({
status: 'SUCCESS',
Expand All @@ -16,6 +18,8 @@ export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent
}
const result = await provider.handle();
const actualPath = event.ResourceProperties.actualPath;
// if we are providing a path to make the assertion at, that means that we have
// flattened the response, otherwise the path to assert against in the entire response
const actual = actualPath ? (result as { [key: string]: string })[`apiCallResponse.${actualPath}`] : (result as types.AwsApiCallResult).apiCallResponse;
if ('expected' in event.ResourceProperties) {
const assertion = new AssertionHandler({
Expand All @@ -31,6 +35,7 @@ export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent
await provider.respond({
status: 'SUCCESS',
reason: 'OK',
// return both the result of the API call _and_ the assertion results
data: {
...assertionResult,
...result,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export function flatten(object: object): { [key: string]: any } {
return [].concat(...Object.keys(child)
.map(key => {
let childKey = Buffer.isBuffer(child[key]) ? child[key].toString('utf8') : child[key];
// if the value is a json string then treat it as an object
// and keep recursing. This allows for easier assertions against complex json strings
if (typeof childKey === 'string') {
childKey = isJsonString(childKey);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/integ-tests/lib/assertions/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export class AwsApiCall extends ApiCallBase {
// Needed so that all the policies set up by the provider should be available before the custom resource is provisioned.
this.apiCallResource.node.addDependency(this.provider);

// if expectedResult has been configured then that means
// we are making assertions and we should output the results
Aspects.of(this).add({
visit(node: IConstruct) {
if (node instanceof AwsApiCall) {
Expand Down

0 comments on commit 4d0a4eb

Please sign in to comment.