From 3d0387d778dbd5a5cdc51becb0c5f4a459eaa432 Mon Sep 17 00:00:00 2001 From: Christine Cao Date: Mon, 12 Dec 2022 14:07:32 +0000 Subject: [PATCH] Add integration test --- .../@aws-cdk/aws-cloudwatch/test/alarm.test.ts | 17 +++++++++++++++++ .../aws-cloudwatch/test/dashboard.test.ts | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/packages/@aws-cdk/aws-cloudwatch/test/alarm.test.ts b/packages/@aws-cdk/aws-cloudwatch/test/alarm.test.ts index d7c6a8a1411ad..e9d1da8143721 100644 --- a/packages/@aws-cdk/aws-cloudwatch/test/alarm.test.ts +++ b/packages/@aws-cdk/aws-cloudwatch/test/alarm.test.ts @@ -284,6 +284,23 @@ describe('Alarm', () => { const template = Annotations.fromStack(stack); template.hasWarning('/MyStack/MyAlarm', Match.stringLikeRegexp("Math expression 'oops' references unknown identifiers")); }); + + test('metric warnings are not added to MetricsInsights Alarm', () => { + // GIVEN + const stack = new Stack(); + const m = new MathExpression({ expression: 'Select MAX(cpu_usage_user) FROM SCHEMA(CWAgent, cpu,host)' }); + + // WHEN + new Alarm(stack, 'MyAlarm', { + metric: m, + evaluationPeriods: 1, + threshold: 1, + }); + + // THEN + const template = Annotations.fromStack(stack); + template.hasNoWarning('/MyStack/MyAlarm', Match.stringLikeRegexp("Math expression 'Select MAX(cpu_usage_user) FROM SCHEMA(CWAgent, cpu,host)' references unknown identifiers")); + }); }); class TestAlarmAction implements IAlarmAction { diff --git a/packages/@aws-cdk/aws-cloudwatch/test/dashboard.test.ts b/packages/@aws-cdk/aws-cloudwatch/test/dashboard.test.ts index cf4c123e0171c..be3c195792166 100644 --- a/packages/@aws-cdk/aws-cloudwatch/test/dashboard.test.ts +++ b/packages/@aws-cdk/aws-cloudwatch/test/dashboard.test.ts @@ -211,6 +211,23 @@ describe('Dashboard', () => { const template = Annotations.fromStack(stack); template.hasWarning('/MyStack/MyDashboard', Match.stringLikeRegexp("Math expression 'oops' references unknown identifiers")); }); + + test('metric warnings are not added to dashboard for metricsinsights alarms', () => { + const app = new App(); + const stack = new Stack(app, 'MyStack'); + const m = new MathExpression({ expression: 'Select MAX(cpu_usage_user) FROM SCHEMA(CWAgent, cpu,host)' }); + + // WHEN + new Dashboard(stack, 'MyDashboard', { + widgets: [ + [new GraphWidget({ left: [m] }), new TextWidget({ markdown: 'asdf' })], + ], + }); + + // THEN + const template = Annotations.fromStack(stack); + template.hasNoWarning('/MyStack/MyDashboard', Match.stringLikeRegexp("Math expression 'Select MAX(cpu_usage_user) FROM SCHEMA(CWAgent, cpu,host)' references unknown identifiers")); + }); }); /**