【发布时间】:2021-04-23 10:56:01
【问题描述】:
如何测试传递给 s3.Bucket 的所有道具? 我想测试传递给 s3.Bucket 的所有道具(无快照)。 测试在 WebsiteConfiguration 上给了我一个错误... 要检查如何在 toHaveResource fn 中编写 prop obj,我使用了 this doc
谁能帮帮我?
import * as cdk from "@aws-cdk/core";
import * as s3 from "@aws-cdk/aws-s3";
export class S3CdkStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new s3.Bucket(this, "ReactGitHubActionBucket", {
versioned: true,
publicReadAccess: true,
websiteIndexDocument: "index.html",
removalPolicy: cdk.RemovalPolicy.DESTROY,
autoDeleteObjects: true,
});
}
}
import { expect as expectCDK, haveResource } from '@aws-cdk/assert';
import * as cdk from '@aws-cdk/core';
import * as Stacks from '../lib/s3-cdk-stack';
test('First test', () => {
const app = new cdk.App();
const stack = new Stacks.S3CdkStack(app, 'S3CdkTestStack');
expectCDK(stack).to(haveResource("AWS::S3::Bucket",{
VersioningConfiguration: {
Status: "Enabled"
},
WebsiteConfiguration: {
IndexDocument: "index.html"
}
}))
});
$ jest
FAIL test/stacks.test.ts
✕ First test (68 ms)
● First test
None of 1 resources matches resource 'AWS::S3::Bucket' with {
"$objectLike": {
"VersioningConfiguration": {
"Status": "Enabled"
},
"WebsiteConfiguration": {
"IndexDocument": "index.html"
}
}
}.
- Field WebsiteConfiguration missing in:
{
"Type": "AWS::S3::Bucket",
"Properties": {
"VersioningConfiguration": {
"Status": "Enabled"
}
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
}
【问题讨论】:
-
您使用的是哪个 cdk 版本?
-
版本 1.99.0 @nirvana124
标签: amazon-web-services amazon-s3 aws-cdk