Skip to content

Commit

Permalink
chore: migrate away from experimental assertions library (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
echeung-amzn authored Mar 8, 2022
1 parent e2e2f82 commit 18e595c
Show file tree
Hide file tree
Showing 52 changed files with 416 additions and 13,094 deletions.
5 changes: 0 additions & 5 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const project = new awscdk.AwsCdkConstructLibrary({
cdkVersionPinning: true,

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

srcdir: "lib",
testdir: "test",
Expand Down
1 change: 0 additions & 1 deletion package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 29 additions & 44 deletions test/common/alarm/AlarmFactory.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
SynthUtils,
expect as cdkExpect,
haveResource,
} from "@monocdk-experiment/assert";
import { Construct, Duration, Stack } from "monocdk";
import { Template } from "monocdk/assertions";
import {
ComparisonOperator,
Metric,
Expand Down Expand Up @@ -118,43 +114,32 @@ test("addAlarm: verify actions enabled", () => {
...props,
alarmNameSuffix: "DisabledByDefault",
});
cdkExpect(stack).to(
haveResource("AWS::CloudWatch::Alarm", {
ActionsEnabled: true,
AlarmName: "DummyServiceAlarms-prefix-EnabledByFlag",
})
);
cdkExpect(stack).to(
haveResource("AWS::CloudWatch::Alarm", {
ActionsEnabled: false,
AlarmName: "DummyServiceAlarms-prefix-DisabledByFlag",
})
);
cdkExpect(stack).to(
haveResource("AWS::CloudWatch::Alarm", {
ActionsEnabled: true,
AlarmName: "DummyServiceAlarms-prefix-EnabledByDisambiguator-Critical",
})
);
cdkExpect(stack).to(
haveResource("AWS::CloudWatch::Alarm", {
ActionsEnabled: false,
AlarmName: "DummyServiceAlarms-prefix-DisabledByDisambiguator-Warning",
})
);
cdkExpect(stack).to(
haveResource("AWS::CloudWatch::Alarm", {
ActionsEnabled: false,
AlarmName:
"DummyServiceAlarms-prefix-DisabledByInvalidDisambiguator-Invalid",
})
);
cdkExpect(stack).to(
haveResource("AWS::CloudWatch::Alarm", {
ActionsEnabled: false,
AlarmName: "DummyServiceAlarms-prefix-DisabledByDefault",
})
);
const template = Template.fromStack(stack);
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
ActionsEnabled: true,
AlarmName: "DummyServiceAlarms-prefix-EnabledByFlag",
});
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
ActionsEnabled: false,
AlarmName: "DummyServiceAlarms-prefix-DisabledByFlag",
});
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
ActionsEnabled: true,
AlarmName: "DummyServiceAlarms-prefix-EnabledByDisambiguator-Critical",
});
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
ActionsEnabled: false,
AlarmName: "DummyServiceAlarms-prefix-DisabledByDisambiguator-Warning",
});
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
ActionsEnabled: false,
AlarmName:
"DummyServiceAlarms-prefix-DisabledByInvalidDisambiguator-Invalid",
});
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
ActionsEnabled: false,
AlarmName: "DummyServiceAlarms-prefix-DisabledByDefault",
});
});

test("addAlarm: description can be overridden", () => {
Expand Down Expand Up @@ -192,7 +177,7 @@ test("addAlarm: evaluateLowSampleCountPercentile can be overridden", () => {
evaluateLowSampleCountPercentile: true,
alarmNameSuffix: "TrueValue",
});
expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
expect(Template.fromStack(stack)).toMatchSnapshot();
});

test("addAlarm: period override is propagated to alarm metric", () => {
Expand Down Expand Up @@ -278,5 +263,5 @@ test("addCompositeAlarm: snapshot for operator", () => {
alarmNameSuffix: "CompositeOr",
compositeOperator: CompositeAlarmOperator.OR,
});
expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
expect(Template.fromStack(stack)).toMatchSnapshot();
});
4 changes: 2 additions & 2 deletions test/common/alarm/MultipleAlarmActionStrategy.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SynthUtils } from "@monocdk-experiment/assert";
import { Stack } from "monocdk";
import { Template } from "monocdk/assertions";
import { Alarm, Metric } from "monocdk/aws-cloudwatch";
import { Topic } from "monocdk/aws-sns";

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

expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
expect(Template.fromStack(stack)).toMatchSnapshot();
});
6 changes: 3 additions & 3 deletions test/common/alarm/SnsAlarmActionStrategy.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SynthUtils } from "@monocdk-experiment/assert";
import { Stack } from "monocdk";
import { Template } from "monocdk/assertions";
import { Alarm, Metric } from "monocdk/aws-cloudwatch";
import { Topic } from "monocdk/aws-sns";

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

expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
expect(Template.fromStack(stack)).toMatchSnapshot();
});

test("snapshot test: all actions", () => {
Expand All @@ -39,5 +39,5 @@ test("snapshot test: all actions", () => {
});
action.addAlarmActions({ alarm, action });

expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
expect(Template.fromStack(stack)).toMatchSnapshot();
});
46 changes: 20 additions & 26 deletions test/common/alarm/actions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ABSENT, haveResource } from "@monocdk-experiment/assert";
import { expect as cdkExpect } from "@monocdk-experiment/assert/lib/expect";
import { Stack } from "monocdk";
import { Match, Template } from "monocdk/assertions";
import { ComparisonOperator, Metric } from "monocdk/aws-cloudwatch";
import { Topic } from "monocdk/aws-sns";

Expand Down Expand Up @@ -60,28 +59,23 @@ test("test actions", () => {
],
});

cdkExpect(stack).to(
haveResource("AWS::CloudWatch::Alarm", {
AlarmName: "Test-DummyAlarmName-AlarmForDummyMetric1-NoActionOverride",
AlarmActions: ABSENT,
OKActions: ABSENT,
InsufficientDataActions: ABSENT,
})
);
cdkExpect(stack).to(
haveResource("AWS::CloudWatch::Alarm", {
AlarmName: "Test-DummyAlarmName-AlarmForDummyMetric1-SimpleSnsAction",
AlarmActions: [{ Ref: "OnAlarmTopicF22649A2" }],
OKActions: ABSENT,
InsufficientDataActions: ABSENT,
})
);
cdkExpect(stack).to(
haveResource("AWS::CloudWatch::Alarm", {
AlarmName: "Test-DummyAlarmName-AlarmForDummyMetric1-ComplexSnsAction",
AlarmActions: [{ Ref: "OnAlarmTopicF22649A2" }],
OKActions: [{ Ref: "OnOkTopic5903F4A2" }],
InsufficientDataActions: [{ Ref: "OnNoDataTopic5F9CF206" }],
})
);
const template = Template.fromStack(stack);
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
AlarmName: "Test-DummyAlarmName-AlarmForDummyMetric1-NoActionOverride",
AlarmActions: Match.absentProperty(),
OKActions: Match.absentProperty(),
InsufficientDataActions: Match.absentProperty(),
});
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
AlarmName: "Test-DummyAlarmName-AlarmForDummyMetric1-SimpleSnsAction",
AlarmActions: [{ Ref: "OnAlarmTopicF22649A2" }],
OKActions: Match.absentProperty(),
InsufficientDataActions: Match.absentProperty(),
});
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
AlarmName: "Test-DummyAlarmName-AlarmForDummyMetric1-ComplexSnsAction",
AlarmActions: [{ Ref: "OnAlarmTopicF22649A2" }],
OKActions: [{ Ref: "OnOkTopic5903F4A2" }],
InsufficientDataActions: [{ Ref: "OnNoDataTopic5F9CF206" }],
});
});
5 changes: 2 additions & 3 deletions test/dashboard/BitmapDashboard.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { haveResource } from "@monocdk-experiment/assert";
import { expect as cdkExpect } from "@monocdk-experiment/assert/lib/expect";
import { Stack } from "monocdk";
import { Template } from "monocdk/assertions";
import { Column, GraphWidget, Metric, Row } from "monocdk/aws-cloudwatch";

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

cdkExpect(stack).to(haveResource("AWS::CloudWatch::Dashboard"));
Template.fromStack(stack).resourceCountIs("AWS::CloudWatch::Dashboard", 1);
});
19 changes: 8 additions & 11 deletions test/dashboard/DashboardWithBitmapCopy.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { haveResource } from "@monocdk-experiment/assert";
import { expect as cdkExpect } from "@monocdk-experiment/assert/lib/expect";
import { Stack } from "monocdk";
import { Template } from "monocdk/assertions";

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

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

cdkExpect(stack).to(
haveResource("AWS::CloudWatch::Dashboard", {
DashboardName: "DummyDashboard",
}).and(
haveResource("AWS::CloudWatch::Dashboard", {
DashboardName: "Bitmap-DummyDashboard",
})
)
);
const template = Template.fromStack(stack);
template.hasResourceProperties("AWS::CloudWatch::Dashboard", {
DashboardName: "DummyDashboard",
});
template.hasResourceProperties("AWS::CloudWatch::Dashboard", {
DashboardName: "Bitmap-DummyDashboard",
});
});
6 changes: 3 additions & 3 deletions test/dashboard/DefaultDashboardFactory.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SynthUtils } from "@monocdk-experiment/assert";
import { Stack } from "monocdk";
import { Template } from "monocdk/assertions";
import { TextWidget } from "monocdk/aws-cloudwatch";

import {
Expand All @@ -19,7 +19,7 @@ test("default dashboards created", () => {
renderingPreference: DashboardRenderingPreference.INTERACTIVE_ONLY,
});

expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
expect(Template.fromStack(stack)).toMatchSnapshot();
});

test("no dashboards created", () => {
Expand All @@ -39,5 +39,5 @@ test("no dashboards created", () => {
),
});

expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
expect(Template.fromStack(stack)).toMatchSnapshot();
});
4 changes: 2 additions & 2 deletions test/dashboard/widget/BitmapWidget.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SynthUtils } from "@monocdk-experiment/assert";
import { Stack } from "monocdk";
import { Template } from "monocdk/assertions";
import { GraphWidget } from "monocdk/aws-cloudwatch";

import { BitmapWidgetRenderingSupport } from "../../../lib";
Expand All @@ -9,7 +9,7 @@ test("support", () => {

new BitmapWidgetRenderingSupport(stack, "Support");

expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
expect(Template.fromStack(stack)).toMatchSnapshot();
});

test("widget", () => {
Expand Down
Loading

0 comments on commit 18e595c

Please sign in to comment.