(integ-tests): Can't make two awsApiCall for the same service and api in a given context #22043
Closed
Description
Describe the bug
While fumbling around with integration tests I received the following error
Error: There is already a Construct with name 'AwsApiCallRedshiftdescribeClusters' in Stack [DeployAssert]
I believe this is because I had two calls for the same service and api
Expected Behavior
I can make two calls to the same service API combo
Current Behavior
I can't make two calls to the same service API combo
Reproduction Steps
import * as integ from '@aws-cdk/integ-tests';
import * as cdk from '@aws-cdk/core';
const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-cdk-redshift-cluster-database');
const test = new integ.IntegTest(app, 'aws-cdk-redshift-reboot-test', {
testCases: [stack],
stackUpdateWorkflow: true,
diffAssets: true,
});
const describe = test.assertions.awsApiCall('Redshift', 'describeClusters', {
ClusterIdentifier: cluster.clusterName,
});
const describe2 = test.assertions.awsApiCall('Redshift', 'describeClusters', {
ClusterIdentifier: cluster.clusterName,
});
Possible Solution
Maybe something like this?
private static serviceAPICounter = new Map<string, number>();
...
public awsApiCall(service: string, api: string, parameters?: any): IAwsApiCall {
let combo = `AwsApiCall${service}${api}`
const count = (DeployAssert.serviceAPICounter.get(combo) ?? 0) + 1
DeployAssert.serviceAPICounter.set(combo, count)
return new AwsApiCall(this.scope, `${combo}${count}`, {
api,
service,
parameters,
});
}
Additional Information/Context
No response
CDK CLI Version
2.41.0
Framework Version
No response
Node.js Version
v16.16.0
OS
OsX
Language
Typescript
Language Version
No response
Other information
No response