-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into niroam-ec2-instance-type-p5
- Loading branch information
Showing
4 changed files
with
78 additions
and
2 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
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
74 changes: 74 additions & 0 deletions
74
packages/aws-cdk-lib/core/test/private/cfn-utils-provider-handler.test.ts
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,74 @@ | ||
import { CfnUtilsResourceType } from '../../lib/private/cfn-utils-provider/consts'; | ||
import { handler } from '../../lib/private/cfn-utils-provider/index'; | ||
|
||
test('parses value as JSON', async () => { | ||
// GIVEN | ||
const event: Partial<AWSLambda.CloudFormationCustomResourceEvent> = { | ||
ResourceType: CfnUtilsResourceType.CFN_JSON, | ||
ResourceProperties: { | ||
ServiceToken: 'Foo', | ||
RepositoryName: 'MyRepo', | ||
Value: JSON.stringify({ | ||
test: 'Random', | ||
}), | ||
}, | ||
}; | ||
|
||
// WHEN | ||
const response = await invokeHandler(event); | ||
|
||
// THEN | ||
expect(response).toEqual({ | ||
Data: { | ||
Value: { | ||
test: 'Random', | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
test('format JSON value as string', async () => { | ||
// GIVEN | ||
const event: Partial<AWSLambda.CloudFormationCustomResourceEvent> = { | ||
ResourceType: CfnUtilsResourceType.CFN_JSON_STRINGIFY, | ||
ResourceProperties: { | ||
ServiceToken: 'Foo', | ||
RepositoryName: 'MyRepo', | ||
Value: { | ||
test: 'Random', | ||
}, | ||
}, | ||
}; | ||
|
||
// WHEN | ||
const response = await invokeHandler(event); | ||
|
||
// THEN | ||
expect(response).toEqual({ | ||
Data: { | ||
Value: JSON.stringify({ | ||
test: 'Random', | ||
}), | ||
}, | ||
}); | ||
}); | ||
|
||
test('fails if wrong resource type', async () => { | ||
// GIVEN | ||
const event: Partial<AWSLambda.CloudFormationCustomResourceEvent> = { | ||
ResourceType: 'Create', | ||
ResourceProperties: { | ||
ServiceToken: 'Foo', | ||
RepositoryName: 'MyRepo', | ||
}, | ||
}; | ||
|
||
// WHEN | ||
await expect(() => invokeHandler(event)).rejects.toThrow(/unexpected resource type "Create"/); | ||
}); | ||
|
||
// helper function to get around TypeScript expecting a complete event object, | ||
// even though our tests only need some of the fields | ||
async function invokeHandler(event: Partial<AWSLambda.CloudFormationCustomResourceEvent>) { | ||
return handler(event as AWSLambda.CloudFormationCustomResourceEvent); | ||
} |