Skip to content

Commit

Permalink
chore(test): make metadata resource test immune to encoding (#13538)
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.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
RomainMuller committed Mar 11, 2021
1 parent 4c63f09 commit e9cd1e8
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 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' }
}

0 comments on commit e9cd1e8

Please sign in to comment.