I am writing an AWS CDK application that creates a ECS Fargate stack. It uses an existing VPC and existing ECR repositories. Simply mocking my Interface, and returning mocks of the IVpc and IRepository interfaces gets me past initial problems, but when the CDK goes to use those constructs, I get more errors.
const mockResources = mock<IExistingResources>(
{
getVpc: (scope: cdk.Construct, vpcId: string) => {
return mock<IVpc>();
},
getElasticContainerRepository: (scope: cdk.Construct, id: string, repositoryName: string) => {
return mock<IRepository>();
}
}
);
I get this error:
TypeError: Cannot destructure property 'subnetIds' of 'baseProps.vpc.selectSubnets(...)' as it is undefined.
This seems like a possible "black hole" where I will need to understand every usage of the mock and account for it. I'm looking for a better way to consistently model my existing resources so that I can test my new code. Any advice would be appreciated.