Skip to content

Commit ddee98e

Browse files
committed
fix(e2e): delete cloudwatch alarms in After call
1 parent 8ed83f0 commit ddee98e

File tree

2 files changed

+29
-48
lines changed

2 files changed

+29
-48
lines changed

features/cloudwatch/cloudwatch.feature

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ Feature: Amazon CloudWatch
88
Given I create a CloudWatch alarm with prefix "aws-js-sdk-alarm"
99
And I list the CloudWatch alarms
1010
Then the list should contain the CloudWatch alarm
11-
And I delete the CloudWatch alarm
1211

1312
Scenario: Error handling
14-
Given I create a CloudWatch alarm with name ""
13+
Given I create a CloudWatch alarm with prefix ""
1514
Then the error code should be "ValidationError"
Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,43 @@
1-
const { Before, Given, Then } = require("@cucumber/cucumber");
1+
const { After, Before, Given, Then } = require("@cucumber/cucumber");
22

3-
Before({ tags: "@cloudwatch" }, function (scenario, callback) {
3+
Before({ tags: "@cloudwatch" }, function () {
44
const { CloudWatch } = require("../../../clients/client-cloudwatch");
55
this.service = new CloudWatch({});
6-
callback();
76
});
87

9-
Given("I create a CloudWatch alarm with prefix {string}", function (name, callback) {
10-
const timestamp = new Date().getTime();
11-
this.cloudWatchAlarm = {
12-
AlarmName: name,
13-
MetricName: "aws-sdk-js-metric-" + timestamp,
14-
Namespace: "aws-sdk-js-namespace" + timestamp,
15-
ComparisonOperator: "GreaterThanThreshold",
16-
EvaluationPeriods: 5,
17-
Period: 60,
18-
Statistic: "Average",
19-
Threshold: 50.0,
20-
};
21-
22-
this.cloudWatchAlarm.AlarmName += "-" + timestamp;
23-
24-
this.request(null, "putMetricAlarm", this.cloudWatchAlarm, callback, undefined);
8+
After({ tags: "@cloudwatch" }, async function () {
9+
if (this.alarmName) {
10+
await this.service.deleteAlarms({ AlarmNames: [this.alarmName] });
11+
this.alarmName = undefined;
12+
}
2513
});
2614

27-
Given("I create a CloudWatch alarm with name {string}", function (name, callback) {
28-
const timestamp = new Date().getTime();
29-
this.cloudWatchAlarm = {
30-
AlarmName: name,
31-
MetricName: "aws-sdk-js-metric-" + timestamp,
32-
Namespace: "aws-sdk-js-namespace" + timestamp,
33-
ComparisonOperator: "GreaterThanThreshold",
34-
EvaluationPeriods: 5,
35-
Period: 60,
36-
Statistic: "Average",
37-
Threshold: 50.0,
38-
};
39-
40-
this.request(null, "putMetricAlarm", this.cloudWatchAlarm, callback, false);
15+
Given("I create a CloudWatch alarm with prefix {string}", async function (prefix) {
16+
const alarmName = this.uniqueName(prefix);
17+
try {
18+
this.data = await this.service.putMetricAlarm({
19+
AlarmName: alarmName,
20+
ComparisonOperator: "GreaterThanThreshold",
21+
EvaluationPeriods: 5,
22+
MetricName: "CPUUtilization",
23+
Namespace: "AWS/EC2",
24+
Period: 60,
25+
Statistic: "Average",
26+
Threshold: 50.0,
27+
});
28+
this.alarmName = alarmName;
29+
} catch (error) {
30+
this.error = error;
31+
}
4132
});
4233

43-
Given("I list the CloudWatch alarms", function (callback) {
44-
const params = {
45-
MetricName: this.cloudWatchAlarm.MetricName,
46-
Namespace: this.cloudWatchAlarm.Namespace,
47-
};
48-
this.request(null, "describeAlarmsForMetric", params, callback);
34+
Given("I list the CloudWatch alarms", async function () {
35+
this.data = await this.service.describeAlarms({ AlarmNames: [this.alarmName] });
4936
});
5037

51-
Then("the list should contain the CloudWatch alarm", function (callback) {
52-
const name = this.cloudWatchAlarm.AlarmName;
38+
Then("the list should contain the CloudWatch alarm", function () {
39+
const name = this.alarmName;
5340
this.assert.contains(this.data.MetricAlarms, function (alarm) {
5441
return alarm.AlarmName === name;
5542
});
56-
callback();
57-
});
58-
59-
Then("I delete the CloudWatch alarm", function (callback) {
60-
this.request(null, "deleteAlarms", { AlarmNames: [this.cloudWatchAlarm.AlarmName] }, callback);
6143
});

0 commit comments

Comments
 (0)