Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cloudwatch): validate Dashboards with an end time must also have a start time #27124

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/aws-cdk-lib/aws-cloudwatch/lib/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ export class Dashboard extends Resource {
}

if (props.start !== undefined && props.defaultInterval !== undefined) {
throw ('both properties defaultInterval and start cannot be set at once');
throw new Error('both properties defaultInterval and start cannot be set at once');
}

if (props.end !== undefined && props.start === undefined) {
throw new Error('You must also specify a start if you specify an end');
mrgrain marked this conversation as resolved.
Show resolved Hide resolved
}

const dashboard = new CfnDashboard(this, 'Resource', {
Expand Down
29 changes: 29 additions & 0 deletions packages/aws-cdk-lib/aws-cloudwatch/test/dashboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,35 @@ describe('Dashboard', () => {

});

test('throws if both defaultInterval and start are specified', () => {
// GIVEN
const stack = new Stack();
// WHEN
const toThrow = () => {
new Dashboard(stack, 'Dash', {
start: '-P7D',
defaultInterval: Duration.days(7),
});
};

// THEN
expect(() => toThrow()).toThrow(/both properties defaultInterval and start cannot be set at once/);
});

test('throws if end is specified but start is not', () => {
// GIVEN
const stack = new Stack();
// WHEN
const toThrow = () => {
new Dashboard(stack, 'Dash', {
end: '2018-12-17T06:00:00.000Z',
});
};

// THEN
expect(() => toThrow()).toThrow(/You must also specify a start if you specify an end/);
});

test('DashboardName is set when provided', () => {
// GIVEN
const app = new App();
Expand Down