Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 48
added stack-id in resource name generation#317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ammokhov
merged 4 commits into
aws-cloudformation:master
from
ammokhov:resource-name-generationOct 15, 2020
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
99 changes: 98 additions & 1 deletion
99 src/main/java/software/amazon/cloudformation/resource/IdentifierUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88 src/test/java/software/amazon/cloudformation/resource/IdentifierUtilsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -48,4 +48,92 @@ public void generateResourceIdentifier_withShortLength_prefixTruncated() { | ||
| // string that is left to fix the max length. | ||
| assertThat(result).startsWith("my-re-"); | ||
| } | ||
| @Test | ||
| public void generateResourceIdentifier_withStackNameStackId() { | ||
| String result = IdentifierUtils.generateResourceIdentifier("my-stack-name", "my-resource", "123456", 18); | ||
| assertThat(result.length()).isLessThanOrEqualTo(18); | ||
| // to ensure randomness in the identity, the result will always be a random | ||
| // string PREFIXED by the size of | ||
| // string that is left to fix the max length. | ||
| assertThat(result).startsWith("my-my-"); | ||
| } | ||
| @Test | ||
| public void generateResourceIdentifier_withStackName() { | ||
| String result = IdentifierUtils.generateResourceIdentifier("my-stack-name", "my-resource", "123456", 50); | ||
| assertThat(result.length()).isLessThanOrEqualTo(49); | ||
| // to ensure randomness in the identity, the result will always be a random | ||
| // string PREFIXED by the size of | ||
| // string that is left to fix the max length. | ||
| assertThat(result).startsWith("my-stack-name-my-resource-"); | ||
| } | ||
| @Test | ||
| public void generateResourceIdentifier_withStackNameLessThanPreferredLen() { | ||
| String result = IdentifierUtils.generateResourceIdentifier("my-stack-name", "my-resource", "123456", 16); | ||
| assertThat(result.length()).isLessThanOrEqualTo(16); | ||
| // to ensure randomness in the identity, the result will always be a random | ||
| // string PREFIXED by the size of | ||
| // string that is left to fix the max length. | ||
| assertThat(result).startsWith("mym-"); | ||
| } | ||
| @Test | ||
| public void generateResourceIdentifier_withStackNameBothFitMaxLen() { | ||
| String result = IdentifierUtils.generateResourceIdentifier( | ||
| "arn:aws:cloudformation:us-east-1:123456789012:stack/my-stack-name/084c0bd1-082b-11eb-afdc-0a2fadfa68a5", | ||
| "my-resource", "123456", 255); | ||
| assertThat(result.length()).isLessThanOrEqualTo(44); | ||
| assertThat(result).isEqualTo("my-stack-name-my-resource-hDoP0dahAFjd"); | ||
| } | ||
| @Test | ||
| public void generateResourceIdentifier_withLongStackNameAndShotLogicalId() { | ||
ammokhov marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| String result = IdentifierUtils.generateResourceIdentifier( | ||
| "arn:aws:cloudformation:us-east-1:123456789012:stack/my-very-very-very-very-very-very-long-custom-stack-name/084c0bd1-082b-11eb-afdc-0a2fadfa68a5", | ||
| "abc", "123456", 36); | ||
| assertThat(result.length()).isLessThanOrEqualTo(36); | ||
| assertThat(result).isEqualTo("my-very-very-very-v-abc-hDoP0dahAFjd"); | ||
| } | ||
| @Test | ||
| public void generateResourceIdentifier_withShortStackNameAndLongLogicalId() { | ||
| String result = IdentifierUtils.generateResourceIdentifier("abc", | ||
| "my-very-very-very-very-very-very-long-custom-logical-id", "123456", 36); | ||
| assertThat(result.length()).isLessThanOrEqualTo(36); | ||
| assertThat(result).isEqualTo("abc-my-very-very-very-v-hDoP0dahAFjd"); | ||
| } | ||
| @Test | ||
| public void generateResourceIdentifier_withLongStackNameAndLongLogicalId() { | ||
| String result = IdentifierUtils.generateResourceIdentifier( | ||
| "arn:aws:cloudformation:us-east-1:123456789012:stack/my-very-very-very-very-very-very-long-custom-stack-name/084c0bd1-082b-11eb-afdc-0a2fadfa68a5", | ||
| "my-very-very-very-very-very-very-long-custom-logical-id", "123456", 36); | ||
| assertThat(result.length()).isEqualTo(36); | ||
| assertThat(result).isEqualTo("my-very-ver-my-very-ver-hDoP0dahAFjd"); | ||
| } | ||
| @Test | ||
| public void generateResourceIdentifier_withStackInValidInput() { | ||
| try { | ||
| IdentifierUtils.generateResourceIdentifier("stack/my-stack-name", "my-resource", "123456", 255); | ||
| } catch (IllegalArgumentException e) { | ||
| assertThat(e.getMessage()).isEqualTo("stack/my-stack-name is not a valid Stack name"); | ||
| } | ||
| } | ||
| @Test | ||
| public void generateResourceIdentifier_withStackValidStackId() { | ||
| try { | ||
| IdentifierUtils.generateResourceIdentifier( | ||
| "arn:aws:cloudformation:us-east-1:123456789012:stack/my-stack-name/084c0bd1-082b-11eb-afdc-0a2fadfa68a5", | ||
| "my-resource", "123456", 14); | ||
| } catch (IllegalArgumentException e) { | ||
| assertThat(e.getMessage()).isEqualTo("Cannot generate resource IDs shorter than 15 characters."); | ||
| } | ||
| } | ||
ammokhov marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.