Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
caoxy98 committed Dec 12, 2022
1 parent 6aec44a commit 3d0387d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/@aws-cdk/aws-cloudwatch/test/alarm.test.ts
Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions packages/@aws-cdk/aws-cloudwatch/test/dashboard.test.ts
Expand Up @@ -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"));
});
});

/**
Expand Down

0 comments on commit 3d0387d

Please sign in to comment.