Dav*_*vid 6 amazon-web-services aws-cdk
按照细粒度断言的方法,特别是https://docs.aws.amazon.com/cdk/v2/guide/testing.html#testing_fine_grainedAWS::StepFunctions::StateMachine中的
示例,我无法使用 来为自己工作状态机定义。Match.serializedJson()
这是我生成的 CloudFormation 模板的片段 -
"StateMachine985JK630": {
"Type": "AWS::StepFunctions::StateMachine",
"Properties": {
"RoleArn": {
"Fn::GetAtt": [
"StateMachineRoleJ4IK852F",
"Arn"
]
},
"DefinitionString": {
"Fn::Join": [
"",
[
"{\"StartAt\":\"My Task One\",\"States\":{\"My Task One \":{\"Next\":\"My Task Two\",\"Retry\":[{\"ErrorEquals\":[\"Lambda.ServiceException\",\"Lambda.AWSLambdaException\",\"Lambda.SdkClientException\"],\"IntervalSeconds\":2,\"MaxAttempts\":6,\"BackoffRate\":2}],\"Type\":\"Task\",\"ResultPath\":\"$.Auth\",\"ResultSelector\":{\"authString.$\":\"$.Payload\"},\"Resource\":\"arn:",
{
"Ref": "AWS::Partition"
},
":states:::lambda:invoke\",\"Parameters\":{\"FunctionName\":\"",
{
"Fn::GetAtt": [
"MyTaskOne",
"Arn"
]
},
"\",\"Payload.$\":\"$\"}},\"My Task Two\":{\"Next\":\"My Task Three\",\"Retry\"
...
]
...
Run Code Online (Sandbox Code Playgroud)
DefinitionString文档示例中的测试不处理Fn::Join上述 CloudFormation 模板中看到的数组或属性,该模板的粗略格式为DefinitionString: { 'Fn::Join': [ '', [Array] ] }. 我的下面的测试按原样工作,但是没有检查属性,例如StartAt它显然是无用的。
我的测试 -
// PASSES
it('should create My Task 1', () => {
template.hasResourceProperties('AWS::StepFunctions::StateMachine', {
DefinitionString: {
'Fn::Join': [
'',
Match.arrayWith([
// Match.serializedJson(Match.objectLike({ StartAt: 'My Task One' })), // FAILS
// Match.serializedJson({ StartAt: 'My Task One' }) // FAILS
// Match.objectLike(Match.serializedJson({ StartAt: 'My Task One' })) // FAILS
{
Ref: 'AWS::Partition',
},
]),
],
},
});
});
Run Code Online (Sandbox Code Playgroud)
我努力了
Expected JSON as a string but found object at /Properties/DefinitionString
Run Code Online (Sandbox Code Playgroud)
考虑到 DefinitionString 的构成,这是有道理的。
Match.arrayWith([])失败中Missing element at pattern index 0 at /Properties/DefinitionString/Fn::Join[1] (using arrayWith matcher)
Run Code Online (Sandbox Code Playgroud)
但我不太明白这一点,因为我使用的函数是“类似”匹配。
"{\"StartAt\":\"My Task One\"...直接粘贴到Match.arrayWith([])传递中,但远非理想。我的问题是如何解析字符串和对象数组,然后仅匹配我想要的内容?任何指导将不胜感激。
| 归档时间: |
|
| 查看次数: |
490 次 |
| 最近记录: |