Skip to content

Commit 4104043

Browse files
authored
chore(location): add validation for description property in PlaceIndex class (#30974)
### Issue # (if applicable) N/A ### Reason for this change Add validation for PlaceIndex description, similar to #30648, #30682, and #30711 . ### Description of changes Add validation and unit tests for description. ### Description of how you validated changes Add unit tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c185194 commit 4104043

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

packages/@aws-cdk/aws-location-alpha/lib/place-index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export interface PlaceIndexProps {
2929
/**
3030
* A name for the place index
3131
*
32+
* Must be between 1 and 100 characters and contain only alphanumeric characters,
33+
* hyphens, periods and underscores.
34+
*
3235
* @default - A name is automatically generated
3336
*/
3437
readonly placeIndexName?: string;
@@ -175,6 +178,10 @@ export class PlaceIndex extends PlaceIndexBase {
175178
public readonly placeIndexUpdateTime: string;
176179

177180
constructor(scope: Construct, id: string, props: PlaceIndexProps = {}) {
181+
if (props.description && !Token.isUnresolved(props.description) && props.description.length > 1000) {
182+
throw new Error(`\`description\` must be between 0 and 1000 characters. Received: ${props.description.length} characters`);
183+
}
184+
178185
if (props.placeIndexName && !Token.isUnresolved(props.placeIndexName) && !/^[-.\w]{1,100}$/.test(props.placeIndexName)) {
179186
throw new Error(`Invalid place index name. The place index name must be between 1 and 100 characters and contain only alphanumeric characters, hyphens, periods and underscores. Received: ${props.placeIndexName}`);
180187
}

packages/@aws-cdk/aws-location-alpha/test/place-index.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,34 @@ test('create a place index', () => {
1717
});
1818
});
1919

20+
test('create a place index with description', () => {
21+
new PlaceIndex(stack, 'PlaceIndex', {
22+
description: 'my-description',
23+
});
24+
25+
Template.fromStack(stack).hasResourceProperties('AWS::Location::PlaceIndex', {
26+
DataSource: 'Esri',
27+
IndexName: 'PlaceIndex',
28+
Description: 'my-description',
29+
});
30+
});
31+
32+
test('creates a place index with empty description', () => {
33+
new PlaceIndex(stack, 'PlaceIndex', {
34+
description: '',
35+
});
36+
37+
Template.fromStack(stack).hasResourceProperties('AWS::Location::PlaceIndex', {
38+
Description: '',
39+
});
40+
});
41+
42+
test('throws with invalid description', () => {
43+
expect(() => new PlaceIndex(stack, 'PlaceIndex', {
44+
description: 'a'.repeat(1001),
45+
})).toThrow('`description` must be between 0 and 1000 characters. Received: 1001 characters');
46+
});
47+
2048
test('throws with invalid name', () => {
2149
expect(() => new PlaceIndex(stack, 'PlaceIndex', {
2250
placeIndexName: 'inv@lid',

0 commit comments

Comments
 (0)