Skip to content

Commit

Permalink
Update unit tests, try/catch errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Peterson committed Nov 10, 2023
1 parent 6e04059 commit a6d9357
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/aws-cdk-lib/core/lib/asset-staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,11 @@ function sanitizeHashValue(key: string, value: any): any {
url.password = '';
return url.toString();
}
} catch (e) {
if (e instanceof TypeError) {
throw new Error(`${key} must be a valid URL, got ${value}.`);
}
throw e;
} catch (e: any) {
if (e.name === 'TypeError') {
throw new Error(`${key} must be a valid URL, got ${value}.`);
}
throw e;
}
}
return value;
Expand Down
19 changes: 19 additions & 0 deletions packages/aws-cdk-lib/core/test/staging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,25 @@ describe('staging', () => {
]);
});

test('bundler throws n error when the PIP url is not a valid url', () => {
// GIVEN
const app = new App({ context: { [cxapi.NEW_STYLE_STACK_SYNTHESIS_CONTEXT]: false } });
const stack = new Stack(app, 'stack');
const directory = path.join(__dirname, 'fs', 'fixtures', 'test1');

// WHEN
expect(() => new AssetStaging(stack, 'Asset', {
sourcePath: directory,
bundling: {
image: DockerImage.fromRegistry('alpine'),
command: [DockerStubCommand.SUCCESS],
environment: {
PIP_INDEX_URL: 'NOT_A_URL',
},
},
})).toThrow('PIP_INDEX_URL must be a valid URL, got NOT_A_URL.');
});

test('bundler outputs to intermediate dir and renames to asset', () => {
// GIVEN
const app = new App({ context: { [cxapi.NEW_STYLE_STACK_SYNTHESIS_CONTEXT]: false } });
Expand Down

0 comments on commit a6d9357

Please sign in to comment.