Skip to content

Commit 474c6ac

Browse files
authored
chore: include widgets in snapshot tests; starting with canary and waf [skip ci] (#97)
Related #91 POC, starting with WAF and CW Canaries. --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
1 parent dc84325 commit 474c6ac

File tree

5 files changed

+321
-3
lines changed

5 files changed

+321
-3
lines changed

test/monitoring/SnapshotUtil.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Executes a snapshot test for widgets, summary widgets and alarm widgets.
3+
* @param monitoring monitoring to test
4+
*/
5+
import { Stack } from "monocdk";
6+
import { Dashboard } from "monocdk/aws-cloudwatch";
7+
import { Monitoring } from "../../lib";
8+
9+
export function addMonitoringDashboardsToStack(
10+
stack: Stack,
11+
monitoring: Monitoring
12+
) {
13+
const summaryDashboard = new Dashboard(stack, "Summary");
14+
summaryDashboard.addWidgets(...monitoring.summaryWidgets());
15+
const alarmDashboard = new Dashboard(stack, "Alarm");
16+
alarmDashboard.addWidgets(...monitoring.alarmWidgets());
17+
const dashboard = new Dashboard(stack, "Default");
18+
dashboard.addWidgets(...monitoring.widgets());
19+
}

test/monitoring/aws-synthetics/SyntheticsCanaryMonitoring.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Canary, Code, Runtime, Schedule, Test } from "monocdk/aws-synthetics";
44

55
import { AlarmWithAnnotation } from "../../../lib";
66
import { SyntheticsCanaryMonitoring } from "../../../lib/monitoring/aws-synthetics";
7+
import { addMonitoringDashboardsToStack } from "../SnapshotUtil";
78
import { TestMonitoringScope } from "../TestMonitoringScope";
89

910
test("snapshot test: no alarms", () => {
@@ -19,8 +20,9 @@ test("snapshot test: no alarms", () => {
1920

2021
const scope = new TestMonitoringScope(stack, "Scope");
2122

22-
new SyntheticsCanaryMonitoring(scope, { canary });
23+
const monitoring = new SyntheticsCanaryMonitoring(scope, { canary });
2324

25+
addMonitoringDashboardsToStack(stack, monitoring);
2426
expect(Template.fromStack(stack)).toMatchSnapshot();
2527
});
2628

@@ -39,7 +41,7 @@ test("snapshot test: all alarms", () => {
3941

4042
let numAlarmsCreated = 0;
4143

42-
new SyntheticsCanaryMonitoring(scope, {
44+
const monitoring = new SyntheticsCanaryMonitoring(scope, {
4345
canary,
4446
addAverageLatencyAlarm: {
4547
Warning: {
@@ -74,5 +76,6 @@ test("snapshot test: all alarms", () => {
7476
});
7577

7678
expect(numAlarmsCreated).toStrictEqual(5);
79+
addMonitoringDashboardsToStack(stack, monitoring);
7780
expect(Template.fromStack(stack)).toMatchSnapshot();
7881
});

test/monitoring/aws-synthetics/__snapshots__/SyntheticsCanaryMonitoring.test.ts.snap

Lines changed: 238 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/monitoring/aws-wafv2/WafV2Monitoring.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Template } from "monocdk/assertions";
33
import { CfnWebACL } from "monocdk/aws-wafv2";
44

55
import { WafV2Monitoring } from "../../../lib";
6+
import { addMonitoringDashboardsToStack } from "../SnapshotUtil";
67
import { TestMonitoringScope } from "../TestMonitoringScope";
78

89
test("snapshot test: no alarms", () => {
@@ -19,7 +20,8 @@ test("snapshot test: no alarms", () => {
1920

2021
const scope = new TestMonitoringScope(stack, "Scope");
2122

22-
new WafV2Monitoring(scope, { acl });
23+
const monitoring = new WafV2Monitoring(scope, { acl });
2324

25+
addMonitoringDashboardsToStack(stack, monitoring);
2426
expect(Template.fromStack(stack)).toMatchSnapshot();
2527
});

0 commit comments

Comments
 (0)