Skip to content

Commit 4f6194c

Browse files
committed
test: Ensure proper awsRequest use in integration setup scripts
1 parent 22802ef commit 4f6194c

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

scripts/test/integration-setup/index.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ const log = require('log').get('serverless');
99
const awsRequest = require('@serverless/test/aws-request');
1010
const fsp = require('fs').promises;
1111
const path = require('path');
12+
const CloudFormationService = require('aws-sdk').CloudFormation;
13+
const SecretsManagerService = require('aws-sdk').SecretsManager;
14+
const KafkaService = require('aws-sdk').Kafka;
15+
1216
const {
1317
SHARED_INFRA_TESTS_CLOUDFORMATION_STACK,
1418
SHARED_INFRA_TESTS_ACTIVE_MQ_CREDENTIALS_NAME,
@@ -22,7 +26,7 @@ const ensureActiveMQCredentialsSecret = async () => {
2226
};
2327
log.notice('Creating SecretsManager ActiveMQ Credentials secret...');
2428
try {
25-
await awsRequest('SecretsManager', 'createSecret', {
29+
await awsRequest(SecretsManagerService, 'createSecret', {
2630
Name: SHARED_INFRA_TESTS_ACTIVE_MQ_CREDENTIALS_NAME,
2731
SecretString: JSON.stringify(ssmMqCredentials),
2832
});
@@ -40,7 +44,7 @@ const ensureRabbitMQCredentialsSecret = async () => {
4044
};
4145
log.notice('Creating SecretsManager RabbitMQ Credentials secret...');
4246
try {
43-
await awsRequest('SecretsManager', 'createSecret', {
47+
await awsRequest(SecretsManagerService, 'createSecret', {
4448
Name: SHARED_INFRA_TESTS_RABBITMQ_CREDENTIALS_NAME,
4549
SecretString: JSON.stringify(ssmMqCredentials),
4650
});
@@ -67,7 +71,7 @@ async function handleInfrastructureCreation() {
6771
const clusterConfName = 'integration-tests-msk-cluster-configuration';
6872

6973
log.notice('Creating MSK Cluster configuration...');
70-
const clusterConfResponse = await awsRequest('Kafka', 'createConfiguration', {
74+
const clusterConfResponse = await awsRequest(KafkaService, 'createConfiguration', {
7175
Name: clusterConfName,
7276
ServerProperties: kafkaServerProperties,
7377
KafkaVersions: ['2.2.1'],
@@ -77,7 +81,7 @@ async function handleInfrastructureCreation() {
7781
const clusterConfigurationRevision = clusterConfResponse.LatestRevision.Revision.toString();
7882

7983
log.notice('Deploying integration tests CloudFormation stack...');
80-
await awsRequest('CloudFormation', 'createStack', {
84+
await awsRequest(CloudFormationService, 'createStack', {
8185
StackName: SHARED_INFRA_TESTS_CLOUDFORMATION_STACK,
8286
TemplateBody: cfnTemplate,
8387
Parameters: [
@@ -108,7 +112,7 @@ async function handleInfrastructureCreation() {
108112
],
109113
});
110114

111-
await awsRequest('CloudFormation', 'waitFor', 'stackCreateComplete', {
115+
await awsRequest(CloudFormationService, 'waitFor', 'stackCreateComplete', {
112116
StackName: SHARED_INFRA_TESTS_CLOUDFORMATION_STACK,
113117
});
114118
log.notice('Deployed integration tests CloudFormation stack!');
@@ -123,7 +127,7 @@ async function handleInfrastructureUpdate() {
123127
const cfnTemplate = await fsp.readFile(path.join(__dirname, 'cloudformation.yml'), 'utf8');
124128

125129
try {
126-
await awsRequest('CloudFormation', 'updateStack', {
130+
await awsRequest(CloudFormationService, 'updateStack', {
127131
StackName: SHARED_INFRA_TESTS_CLOUDFORMATION_STACK,
128132
TemplateBody: cfnTemplate,
129133
Parameters: [
@@ -161,7 +165,7 @@ async function handleInfrastructureUpdate() {
161165
throw e;
162166
}
163167

164-
await awsRequest('CloudFormation', 'waitFor', 'stackUpdateComplete', {
168+
await awsRequest(CloudFormationService, 'waitFor', 'stackUpdateComplete', {
165169
StackName: SHARED_INFRA_TESTS_CLOUDFORMATION_STACK,
166170
});
167171
log.notice('Updated integration tests CloudFormation stack!');
@@ -206,7 +210,7 @@ async function handleInfrastructureUpdate() {
206210

207211
log.notice('Checking if integration tests CloudFormation stack already exists...');
208212
try {
209-
describeResponse = await awsRequest('CloudFormation', 'describeStacks', {
213+
describeResponse = await awsRequest(CloudFormationService, 'describeStacks', {
210214
StackName: SHARED_INFRA_TESTS_CLOUDFORMATION_STACK,
211215
});
212216
log.notice('Integration tests CloudFormation stack already exists');

scripts/test/integration-teardown.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,25 @@ require('log-node')();
77

88
const log = require('log').get('serverless');
99
const awsRequest = require('@serverless/test/aws-request');
10+
const CloudFormationService = require('aws-sdk').CloudFormation;
11+
const EC2Service = require('aws-sdk').EC2;
12+
const KafkaService = require('aws-sdk').Kafka;
13+
1014
const {
1115
SHARED_INFRA_TESTS_CLOUDFORMATION_STACK,
1216
getDependencyStackOutputMap,
1317
} = require('../../test/utils/cloudformation');
1418

1519
(async () => {
1620
log.notice('Starting teardown of integration infrastructure...');
17-
const describeClustersResponse = await awsRequest('Kafka', 'listClusters');
21+
const describeClustersResponse = await awsRequest(KafkaService, 'listClusters');
1822
const clusterConfArn =
1923
describeClustersResponse.ClusterInfoList[0].CurrentBrokerSoftwareInfo.ConfigurationArn;
2024

2125
const outputMap = await getDependencyStackOutputMap();
2226

2327
log.notice('Removing leftover ENI...');
24-
const describeResponse = await awsRequest('EC2', 'describeNetworkInterfaces', {
28+
const describeResponse = await awsRequest(EC2Service, 'describeNetworkInterfaces', {
2529
Filters: [
2630
{
2731
Name: 'vpc-id',
@@ -36,7 +40,7 @@ const {
3640
try {
3741
await Promise.all(
3842
describeResponse.NetworkInterfaces.map((networkInterface) =>
39-
awsRequest('EC2', 'deleteNetworkInterface', {
43+
awsRequest(EC2Service, 'deleteNetworkInterface', {
4044
NetworkInterfaceId: networkInterface.NetworkInterfaceId,
4145
})
4246
)
@@ -45,15 +49,15 @@ const {
4549
log.error(`Error: ${e} while trying to remove leftover ENIs\n`);
4650
}
4751
log.notice('Removing integration tests CloudFormation stack...');
48-
await awsRequest('CloudFormation', 'deleteStack', {
52+
await awsRequest(CloudFormationService, 'deleteStack', {
4953
StackName: SHARED_INFRA_TESTS_CLOUDFORMATION_STACK,
5054
});
51-
await awsRequest('CloudFormation', 'waitFor', 'stackDeleteComplete', {
55+
await awsRequest(CloudFormationService, 'waitFor', 'stackDeleteComplete', {
5256
StackName: SHARED_INFRA_TESTS_CLOUDFORMATION_STACK,
5357
});
5458
log.notice('Removed integration tests CloudFormation stack!');
5559
log.notice('Removing MSK Cluster configuration...');
56-
await awsRequest('Kafka', 'deleteConfiguration', {
60+
await awsRequest(KafkaService, 'deleteConfiguration', {
5761
Arn: clusterConfArn,
5862
});
5963
log.notice('Removed MSK Cluster configuration');

0 commit comments

Comments
 (0)