Skip to content

Commit

Permalink
add description validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mazyu36 committed Jul 29, 2024
1 parent f23e19b commit 3841404
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/@aws-cdk/aws-location-alpha/lib/route-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ export class RouteCalculator extends RouteCalculatorBase {
public readonly routeCalculatorUpdateTime: string;

constructor(scope: Construct, id: string, props: RouteCalculatorProps = {}) {

if (props.description !== undefined && !Token.isUnresolved(props.description) && props.description.length > 1000) {
throw new Error(`\`description\` must be between 0 and 1000 characters. Received: ${props.description.length} characters`);
}

if (props.routeCalculatorName && !Token.isUnresolved(props.routeCalculatorName) && !/^[-.\w]{1,100}$/.test(props.routeCalculatorName)) {
throw new Error(`Invalid route calculator name. The route calculator name must be between 1 and 100 characters and contain only alphanumeric characters, hyphens, periods and underscores. Received: ${props.routeCalculatorName}`);
}
Expand Down
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-location-alpha/test/route-calculator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ test('create a route calculator', () => {
});
});

test('creates geofence collection with empty description', () => {
new RouteCalculator(stack, 'RouteCalculator', { description: '' });

Template.fromStack(stack).hasResourceProperties('AWS::Location::RouteCalculator', {
Description: '',
});
});

test('throws with invalid description', () => {
expect(() => new RouteCalculator(stack, 'RouteCalculator', {
description: 'a'.repeat(1001),
})).toThrow('`description` must be between 0 and 1000 characters. Received: 1001 characters');
});

test('throws with invalid name', () => {
expect(() => new RouteCalculator(stack, 'RouteCalculator', {
routeCalculatorName: 'inv@lid',
Expand Down

0 comments on commit 3841404

Please sign in to comment.