我正在编写一个创建 ECS Fargate 堆栈的 AWS CDK 应用程序。它使用现有的 VPC 和现有的 ECR 存储库。简单地模拟我的接口,并返回 IVpc 和 IRepository 接口的模拟可以帮助我解决最初的问题,但是当 CDK 使用这些构造时,我会遇到更多错误。
const mockResources = mock<IExistingResources>(
{
getVpc: (scope: cdk.Construct, vpcId: string) => {
return mock<IVpc>();
},
getElasticContainerRepository: (scope: cdk.Construct, id: string, repositoryName: string) => {
return mock<IRepository>();
}
}
);
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
TypeError: Cannot destructure property 'subnetIds' of 'baseProps.vpc.selectSubnets(...)' as it is undefined.
Run Code Online (Sandbox Code Playgroud)
这似乎是一个可能的“黑洞”,我需要了解模拟的每种用法并解释它。我正在寻找一种更好的方法来对现有资源进行一致建模,以便我可以测试我的新代码。任何意见,将不胜感激。