From 3841404a7fcef1cd2ee7e19118440a7916037e4d Mon Sep 17 00:00:00 2001 From: maz Date: Mon, 29 Jul 2024 22:48:07 +0900 Subject: [PATCH] add description validation --- .../aws-location-alpha/lib/route-calculator.ts | 5 +++++ .../test/route-calculator.test.ts | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/packages/@aws-cdk/aws-location-alpha/lib/route-calculator.ts b/packages/@aws-cdk/aws-location-alpha/lib/route-calculator.ts index 4f97f11624098..d7135cc709546 100644 --- a/packages/@aws-cdk/aws-location-alpha/lib/route-calculator.ts +++ b/packages/@aws-cdk/aws-location-alpha/lib/route-calculator.ts @@ -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}`); } diff --git a/packages/@aws-cdk/aws-location-alpha/test/route-calculator.test.ts b/packages/@aws-cdk/aws-location-alpha/test/route-calculator.test.ts index d8c5ff9d32742..d3ebfb0a2e317 100644 --- a/packages/@aws-cdk/aws-location-alpha/test/route-calculator.test.ts +++ b/packages/@aws-cdk/aws-location-alpha/test/route-calculator.test.ts @@ -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',