|
1 |
| -const { Before, Given, Then } = require("@cucumber/cucumber"); |
| 1 | +const { After, Before, Given, Then } = require("@cucumber/cucumber"); |
2 | 2 |
|
3 |
| -Before({ tags: "@cloudwatch" }, function (scenario, callback) { |
| 3 | +Before({ tags: "@cloudwatch" }, function () { |
4 | 4 | const { CloudWatch } = require("../../../clients/client-cloudwatch");
|
5 | 5 | this.service = new CloudWatch({});
|
6 |
| - callback(); |
7 | 6 | });
|
8 | 7 |
|
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 | + } |
25 | 13 | });
|
26 | 14 |
|
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 | + this.alarmName = this.uniqueName(prefix); |
| 17 | + try { |
| 18 | + this.data = await this.service.putMetricAlarm({ |
| 19 | + AlarmName: this.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 | + console.log({ data: this.data }); |
| 29 | + } catch (error) { |
| 30 | + this.error = error; |
| 31 | + } |
41 | 32 | });
|
42 | 33 |
|
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 | + console.log({ alarmName: this.alarmName }); |
| 36 | + this.data = this.service.describeAlarms({ AlarmNames: [this.alarmName] }); |
49 | 37 | });
|
50 | 38 |
|
51 |
| -Then("the list should contain the CloudWatch alarm", function (callback) { |
52 |
| - const name = this.cloudWatchAlarm.AlarmName; |
| 39 | +Then("the list should contain the CloudWatch alarm", function () { |
| 40 | + const name = this.alarmName; |
53 | 41 | this.assert.contains(this.data.MetricAlarms, function (alarm) {
|
54 | 42 | return alarm.AlarmName === name;
|
55 | 43 | });
|
56 |
| - callback(); |
57 |
| -}); |
58 |
| - |
59 |
| -Then("I delete the CloudWatch alarm", function (callback) { |
60 |
| - this.request(null, "deleteAlarms", { AlarmNames: [this.cloudWatchAlarm.AlarmName] }, callback); |
61 | 44 | });
|
0 commit comments