Skip to content

Commit 18e595c

Browse files
author
Eugene Cheung
authored
chore: migrate away from experimental assertions library (#57)
Should make the CDK v2 upgrade simpler. Doc: https://github.com/aws/aws-cdk/blob/master/packages/@aws-cdk/assertions/MIGRATING.md
1 parent e2e2f82 commit 18e595c

File tree

52 files changed

+416
-13094
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+416
-13094
lines changed

.projen/deps.json

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

.projen/tasks.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const project = new awscdk.AwsCdkConstructLibrary({
1515
cdkVersionPinning: true,
1616

1717
cdkDependencies: ["monocdk"],
18-
cdkTestDependencies: ["@monocdk-experiment/assert"],
1918

2019
srcdir: "lib",
2120
testdir: "test",

package.json

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

test/common/alarm/AlarmFactory.test.ts

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import {
2-
SynthUtils,
3-
expect as cdkExpect,
4-
haveResource,
5-
} from "@monocdk-experiment/assert";
61
import { Construct, Duration, Stack } from "monocdk";
2+
import { Template } from "monocdk/assertions";
73
import {
84
ComparisonOperator,
95
Metric,
@@ -118,43 +114,32 @@ test("addAlarm: verify actions enabled", () => {
118114
...props,
119115
alarmNameSuffix: "DisabledByDefault",
120116
});
121-
cdkExpect(stack).to(
122-
haveResource("AWS::CloudWatch::Alarm", {
123-
ActionsEnabled: true,
124-
AlarmName: "DummyServiceAlarms-prefix-EnabledByFlag",
125-
})
126-
);
127-
cdkExpect(stack).to(
128-
haveResource("AWS::CloudWatch::Alarm", {
129-
ActionsEnabled: false,
130-
AlarmName: "DummyServiceAlarms-prefix-DisabledByFlag",
131-
})
132-
);
133-
cdkExpect(stack).to(
134-
haveResource("AWS::CloudWatch::Alarm", {
135-
ActionsEnabled: true,
136-
AlarmName: "DummyServiceAlarms-prefix-EnabledByDisambiguator-Critical",
137-
})
138-
);
139-
cdkExpect(stack).to(
140-
haveResource("AWS::CloudWatch::Alarm", {
141-
ActionsEnabled: false,
142-
AlarmName: "DummyServiceAlarms-prefix-DisabledByDisambiguator-Warning",
143-
})
144-
);
145-
cdkExpect(stack).to(
146-
haveResource("AWS::CloudWatch::Alarm", {
147-
ActionsEnabled: false,
148-
AlarmName:
149-
"DummyServiceAlarms-prefix-DisabledByInvalidDisambiguator-Invalid",
150-
})
151-
);
152-
cdkExpect(stack).to(
153-
haveResource("AWS::CloudWatch::Alarm", {
154-
ActionsEnabled: false,
155-
AlarmName: "DummyServiceAlarms-prefix-DisabledByDefault",
156-
})
157-
);
117+
const template = Template.fromStack(stack);
118+
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
119+
ActionsEnabled: true,
120+
AlarmName: "DummyServiceAlarms-prefix-EnabledByFlag",
121+
});
122+
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
123+
ActionsEnabled: false,
124+
AlarmName: "DummyServiceAlarms-prefix-DisabledByFlag",
125+
});
126+
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
127+
ActionsEnabled: true,
128+
AlarmName: "DummyServiceAlarms-prefix-EnabledByDisambiguator-Critical",
129+
});
130+
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
131+
ActionsEnabled: false,
132+
AlarmName: "DummyServiceAlarms-prefix-DisabledByDisambiguator-Warning",
133+
});
134+
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
135+
ActionsEnabled: false,
136+
AlarmName:
137+
"DummyServiceAlarms-prefix-DisabledByInvalidDisambiguator-Invalid",
138+
});
139+
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
140+
ActionsEnabled: false,
141+
AlarmName: "DummyServiceAlarms-prefix-DisabledByDefault",
142+
});
158143
});
159144

160145
test("addAlarm: description can be overridden", () => {
@@ -192,7 +177,7 @@ test("addAlarm: evaluateLowSampleCountPercentile can be overridden", () => {
192177
evaluateLowSampleCountPercentile: true,
193178
alarmNameSuffix: "TrueValue",
194179
});
195-
expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
180+
expect(Template.fromStack(stack)).toMatchSnapshot();
196181
});
197182

198183
test("addAlarm: period override is propagated to alarm metric", () => {
@@ -278,5 +263,5 @@ test("addCompositeAlarm: snapshot for operator", () => {
278263
alarmNameSuffix: "CompositeOr",
279264
compositeOperator: CompositeAlarmOperator.OR,
280265
});
281-
expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
266+
expect(Template.fromStack(stack)).toMatchSnapshot();
282267
});

test/common/alarm/MultipleAlarmActionStrategy.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { SynthUtils } from "@monocdk-experiment/assert";
21
import { Stack } from "monocdk";
2+
import { Template } from "monocdk/assertions";
33
import { Alarm, Metric } from "monocdk/aws-cloudwatch";
44
import { Topic } from "monocdk/aws-sns";
55

@@ -22,5 +22,5 @@ test("snapshot test: multiple actions", () => {
2222
);
2323
action.addAlarmActions({ alarm, action });
2424

25-
expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
25+
expect(Template.fromStack(stack)).toMatchSnapshot();
2626
});

test/common/alarm/SnsAlarmActionStrategy.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { SynthUtils } from "@monocdk-experiment/assert";
21
import { Stack } from "monocdk";
2+
import { Template } from "monocdk/assertions";
33
import { Alarm, Metric } from "monocdk/aws-cloudwatch";
44
import { Topic } from "monocdk/aws-sns";
55

@@ -16,7 +16,7 @@ test("snapshot test: default action only", () => {
1616
const action = new SnsAlarmActionStrategy({ onAlarmTopic });
1717
action.addAlarmActions({ alarm, action });
1818

19-
expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
19+
expect(Template.fromStack(stack)).toMatchSnapshot();
2020
});
2121

2222
test("snapshot test: all actions", () => {
@@ -39,5 +39,5 @@ test("snapshot test: all actions", () => {
3939
});
4040
action.addAlarmActions({ alarm, action });
4141

42-
expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
42+
expect(Template.fromStack(stack)).toMatchSnapshot();
4343
});

test/common/alarm/actions.test.ts

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { ABSENT, haveResource } from "@monocdk-experiment/assert";
2-
import { expect as cdkExpect } from "@monocdk-experiment/assert/lib/expect";
31
import { Stack } from "monocdk";
2+
import { Match, Template } from "monocdk/assertions";
43
import { ComparisonOperator, Metric } from "monocdk/aws-cloudwatch";
54
import { Topic } from "monocdk/aws-sns";
65

@@ -60,28 +59,23 @@ test("test actions", () => {
6059
],
6160
});
6261

63-
cdkExpect(stack).to(
64-
haveResource("AWS::CloudWatch::Alarm", {
65-
AlarmName: "Test-DummyAlarmName-AlarmForDummyMetric1-NoActionOverride",
66-
AlarmActions: ABSENT,
67-
OKActions: ABSENT,
68-
InsufficientDataActions: ABSENT,
69-
})
70-
);
71-
cdkExpect(stack).to(
72-
haveResource("AWS::CloudWatch::Alarm", {
73-
AlarmName: "Test-DummyAlarmName-AlarmForDummyMetric1-SimpleSnsAction",
74-
AlarmActions: [{ Ref: "OnAlarmTopicF22649A2" }],
75-
OKActions: ABSENT,
76-
InsufficientDataActions: ABSENT,
77-
})
78-
);
79-
cdkExpect(stack).to(
80-
haveResource("AWS::CloudWatch::Alarm", {
81-
AlarmName: "Test-DummyAlarmName-AlarmForDummyMetric1-ComplexSnsAction",
82-
AlarmActions: [{ Ref: "OnAlarmTopicF22649A2" }],
83-
OKActions: [{ Ref: "OnOkTopic5903F4A2" }],
84-
InsufficientDataActions: [{ Ref: "OnNoDataTopic5F9CF206" }],
85-
})
86-
);
62+
const template = Template.fromStack(stack);
63+
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
64+
AlarmName: "Test-DummyAlarmName-AlarmForDummyMetric1-NoActionOverride",
65+
AlarmActions: Match.absentProperty(),
66+
OKActions: Match.absentProperty(),
67+
InsufficientDataActions: Match.absentProperty(),
68+
});
69+
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
70+
AlarmName: "Test-DummyAlarmName-AlarmForDummyMetric1-SimpleSnsAction",
71+
AlarmActions: [{ Ref: "OnAlarmTopicF22649A2" }],
72+
OKActions: Match.absentProperty(),
73+
InsufficientDataActions: Match.absentProperty(),
74+
});
75+
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
76+
AlarmName: "Test-DummyAlarmName-AlarmForDummyMetric1-ComplexSnsAction",
77+
AlarmActions: [{ Ref: "OnAlarmTopicF22649A2" }],
78+
OKActions: [{ Ref: "OnOkTopic5903F4A2" }],
79+
InsufficientDataActions: [{ Ref: "OnNoDataTopic5F9CF206" }],
80+
});
8781
});

test/dashboard/BitmapDashboard.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { haveResource } from "@monocdk-experiment/assert";
2-
import { expect as cdkExpect } from "@monocdk-experiment/assert/lib/expect";
31
import { Stack } from "monocdk";
2+
import { Template } from "monocdk/assertions";
43
import { Column, GraphWidget, Metric, Row } from "monocdk/aws-cloudwatch";
54

65
import { BitmapDashboard } from "../../lib";
@@ -49,5 +48,5 @@ test("check the bitmap dashboard is generated with rows/columns", () => {
4948
)
5049
);
5150

52-
cdkExpect(stack).to(haveResource("AWS::CloudWatch::Dashboard"));
51+
Template.fromStack(stack).resourceCountIs("AWS::CloudWatch::Dashboard", 1);
5352
});
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { haveResource } from "@monocdk-experiment/assert";
2-
import { expect as cdkExpect } from "@monocdk-experiment/assert/lib/expect";
31
import { Stack } from "monocdk";
2+
import { Template } from "monocdk/assertions";
43

54
import { DashboardWithBitmapCopy } from "../../lib";
65

@@ -11,13 +10,11 @@ test("named dashboard has a bitmap copy", () => {
1110
dashboardName: "DummyDashboard",
1211
});
1312

14-
cdkExpect(stack).to(
15-
haveResource("AWS::CloudWatch::Dashboard", {
16-
DashboardName: "DummyDashboard",
17-
}).and(
18-
haveResource("AWS::CloudWatch::Dashboard", {
19-
DashboardName: "Bitmap-DummyDashboard",
20-
})
21-
)
22-
);
13+
const template = Template.fromStack(stack);
14+
template.hasResourceProperties("AWS::CloudWatch::Dashboard", {
15+
DashboardName: "DummyDashboard",
16+
});
17+
template.hasResourceProperties("AWS::CloudWatch::Dashboard", {
18+
DashboardName: "Bitmap-DummyDashboard",
19+
});
2320
});

0 commit comments

Comments
 (0)