From 2d0a33a090bb28da287475bc448222c1ecd26a4e Mon Sep 17 00:00:00 2001 From: Siddharth Salot Date: Thu, 27 Jan 2022 14:22:51 -0500 Subject: [PATCH] Revision 4: Modify error messages and unit test cases --- .../aws-fsx/lib/lustre-file-system.ts | 6 +-- .../aws-fsx/test/lustre-file-system.test.ts | 40 +++++++++---------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/packages/@aws-cdk/aws-fsx/lib/lustre-file-system.ts b/packages/@aws-cdk/aws-fsx/lib/lustre-file-system.ts index 8ccda74196dd8..7b145252941cb 100644 --- a/packages/@aws-cdk/aws-fsx/lib/lustre-file-system.ts +++ b/packages/@aws-cdk/aws-fsx/lib/lustre-file-system.ts @@ -282,18 +282,18 @@ export class LustreFileSystem extends FileSystemBase { if (perUnitStorageThroughput === undefined) { return; } if (deploymentType !== LustreDeploymentType.PERSISTENT_1 && deploymentType !== LustreDeploymentType.PERSISTENT_2) { - throw new Error('perUnitStorageThroughput can only be set for the PERSISTENT_1/PERSISTENT_2 deployment types'); + throw new Error('perUnitStorageThroughput can only be set for the PERSISTENT_1/PERSISTENT_2 deployment types, received: ' + deploymentType); } if (deploymentType === LustreDeploymentType.PERSISTENT_1) { if (![50, 100, 200].includes(perUnitStorageThroughput)) { - throw new Error('perUnitStorageThroughput must be 50, 100, or 200 MB/s/TiB'); + throw new Error('perUnitStorageThroughput must be 50, 100, or 200 MB/s/TiB for PERSISTENT_1 deployment type, got: ' + perUnitStorageThroughput); } } if (deploymentType === LustreDeploymentType.PERSISTENT_2) { if (![125, 250, 500, 1000].includes(perUnitStorageThroughput)) { - throw new Error('perUnitStorageThroughput must be 125, 250, 500 or 1000 MB/s/TiB'); + throw new Error('perUnitStorageThroughput must be 125, 250, 500 or 1000 MB/s/TiB for PERSISTENT_2 deployment type, got: ' + perUnitStorageThroughput); } } } diff --git a/packages/@aws-cdk/aws-fsx/test/lustre-file-system.test.ts b/packages/@aws-cdk/aws-fsx/test/lustre-file-system.test.ts index ba2bb3d8d3f97..cff4f97f1149f 100644 --- a/packages/@aws-cdk/aws-fsx/test/lustre-file-system.test.ts +++ b/packages/@aws-cdk/aws-fsx/test/lustre-file-system.test.ts @@ -436,10 +436,16 @@ describe('FSx for Lustre File System', () => { }); }); - test('invalid perUnitStorageThroughput', () => { + test.each([ + 1, + 125, + 250, + 500, + 1000, + ])('invalid perUnitStorageThroughput', (invalidValue: number) => { lustreConfiguration = { deploymentType: LustreDeploymentType.PERSISTENT_1, - perUnitStorageThroughput: 1, + perUnitStorageThroughput: invalidValue, }; expect(() => { @@ -449,7 +455,7 @@ describe('FSx for Lustre File System', () => { vpc, vpcSubnet, }); - }).toThrowError('perUnitStorageThroughput must be 50, 100, or 200 MB/s/TiB'); + }).toThrowError('perUnitStorageThroughput must be 50, 100, or 200 MB/s/TiB for PERSISTENT_1 deployment type, got: ' + invalidValue); }); test('setting perUnitStorageThroughput on wrong deploymentType', () => { @@ -496,26 +502,16 @@ describe('FSx for Lustre File System', () => { }); }); - test('invalid perUnitStorageThroughput', () => { + test.each([ + 1, + 50, + 100, + 200, + 550, + ])('invalid perUnitStorageThroughput', (invalidValue: number) => { lustreConfiguration = { deploymentType: LustreDeploymentType.PERSISTENT_2, - perUnitStorageThroughput: 1, - }; - - expect(() => { - new LustreFileSystem(stack, 'FsxFileSystem', { - lustreConfiguration, - storageCapacityGiB: storageCapacity, - vpc, - vpcSubnet, - }); - }).toThrowError('perUnitStorageThroughput must be 125, 250, 500 or 1000 MB/s/TiB'); - }); - - test('setting perUnitStorageThroughput on wrong deploymentType', () => { - lustreConfiguration = { - deploymentType: LustreDeploymentType.SCRATCH_2, - perUnitStorageThroughput: 125, + perUnitStorageThroughput: invalidValue, }; expect(() => { @@ -525,7 +521,7 @@ describe('FSx for Lustre File System', () => { vpc, vpcSubnet, }); - }).toThrowError('perUnitStorageThroughput can only be set for the PERSISTENT_1/PERSISTENT_2 deployment types'); + }).toThrowError('perUnitStorageThroughput must be 125, 250, 500 or 1000 MB/s/TiB for PERSISTENT_2 deployment type, got: ' + invalidValue); }); });