Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mazyu36 committed Jun 2, 2024
1 parent 0cac270 commit e5067dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ export class AutoScalingConfiguration extends cdk.Resource implements IAutoScali
});

if (
props.autoScalingConfigurationName !== undefined &&
props.autoScalingConfigurationName !== undefined &&
!cdk.Token.isUnresolved(props.autoScalingConfigurationName) &&
!/^[A-Za-z0-9][A-Za-z0-9\-_]{3,31}$/.test(props.autoScalingConfigurationName)
) {
throw new Error(`autoScalingConfigurationName must match the ^[A-Za-z0-9][A-Za-z0-9\-_]{3,31}$ pattern, got ${props.autoScalingConfigurationName}`);
}

const isMinSizeDefined = props.minSize !== undefined && !cdk.Token.isUnresolved(props.minSize)
const isMaxSizeDefined = props.maxSize !== undefined && !cdk.Token.isUnresolved(props.maxSize)
const isMinSizeDefined = props.minSize !== undefined && !cdk.Token.isUnresolved(props.minSize);
const isMaxSizeDefined = props.maxSize !== undefined && !cdk.Token.isUnresolved(props.maxSize);
if (isMinSizeDefined && (props.minSize < 1 || props.minSize > 25)) {
throw new Error(`minSize must be between 1 and 25, got ${props.minSize}`);
}
Expand All @@ -177,7 +177,7 @@ export class AutoScalingConfiguration extends cdk.Resource implements IAutoScali
throw new Error('maxSize must be greater than minSize');
}
if (
props.maxConcurrency !== undefined &&
props.maxConcurrency !== undefined &&
!cdk.Token.isUnresolved(props.maxConcurrency) &&
(props.maxConcurrency < 1 || props.maxConcurrency > 200)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,13 @@ test.each([0, 201])('invalid maxConcurrency', (maxConcurrency: number) => {
test.each([
['tes'],
['test-autoscaling-configuration-name-over-limitation'],
])('autoScalingConfigurationName over length limitation (name: %s)', (autoScalingConfigurationName: string) => {
expect(() => {
new AutoScalingConfiguration(stack, 'AutoScalingConfiguration', {
autoScalingConfigurationName,
});
}).toThrow(`autoScalingConfigurationName must be between 4 and 32 characters long, but it has ${autoScalingConfigurationName.length} characters.`);
});

test.each([
['-test'],
['test-?'],
])('invalid autoScalingConfigurationName (name: %s)', (autoScalingConfigurationName: string) => {
expect(() => {
new AutoScalingConfiguration(stack, 'AutoScalingConfiguration', {
autoScalingConfigurationName,
});
}).toThrow(`autoScalingConfigurationName ${autoScalingConfigurationName} must start with a letter or number, and can contain only letters, numbers, hyphens, and underscores.`);
}).toThrow(`autoScalingConfigurationName must match the ^[A-Za-z0-9][A-Za-z0-9\-_]{3,31}$ pattern, got ${autoScalingConfigurationName}`);
});

0 comments on commit e5067dd

Please sign in to comment.