Skip to content

Commit

Permalink
fix(test): make metadata resource test immune to encoding
Browse files Browse the repository at this point in the history
The prefix-encoded trie could occasionally encode the tested resource
name in a way that prevents the test to match. Using a "fake" version
number ensures a unique prefix is always present, and hence the tested
entry will never be encoded in unexpected ways.
  • Loading branch information
RomainMuller committed Mar 11, 2021
1 parent 4c63f09 commit a6a8025
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/@aws-cdk/core/test/metadata-resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('MetadataResource', () => {
test('includes constructs added to the stack', () => {
new TestConstruct(stack, 'Test');

expect(stackAnalytics()).toContain('1.2.3!@amzn/core.TestConstruct');
expect(stackAnalytics()).toContain('FakeVersion.2.3!@amzn/core.TestConstruct');
});

test('only includes constructs in the allow list', () => {
Expand Down Expand Up @@ -141,11 +141,10 @@ const JSII_RUNTIME_SYMBOL = Symbol.for('jsii.rtti');

class TestConstruct extends Construct {
// @ts-ignore
private static readonly [JSII_RUNTIME_SYMBOL] = { fqn: '@amzn/core.TestConstruct', version: '1.2.3' }
private static readonly [JSII_RUNTIME_SYMBOL] = { fqn: '@amzn/core.TestConstruct', version: 'FakeVersion.2.3' }
}

class TestThirdPartyConstruct extends Construct {
// @ts-ignore
private static readonly [JSII_RUNTIME_SYMBOL] = { fqn: 'mycoolthing.TestConstruct', version: '1.2.3' }
private static readonly [JSII_RUNTIME_SYMBOL] = { fqn: 'mycoolthing.TestConstruct', version: '999.2.3' }
}

0 comments on commit a6a8025

Please sign in to comment.