Skip to content
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

Fix IdentifierUtils unit tests #442

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

public class IdentifierUtils {

public static final int GUID_LENGTH = 12;
private static final int GENERATED_PHYSICALID_MAXLEN = 40;
private static final int GUID_LENGTH = 12;
private static final int MIN_PHYSICAL_RESOURCE_ID_LENGTH = 15;
private static final int MIN_PREFERRED_LENGTH = 17;
private static final Splitter STACKID_SPLITTER = Splitter.on('/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.junit.jupiter.api.Test;

public class IdentifierUtilsTest {
private static final String guidPattern = "[a-zA-Z0-9]{" + IdentifierUtils.GUID_LENGTH + "}$";

@Test
public void generateResourceIdentifier_withDefaultLength() {
String result = IdentifierUtils.generateResourceIdentifier("my-resource", "123456");
Expand Down Expand Up @@ -88,7 +90,7 @@ public void generateResourceIdentifier_withStackNameBothFitMaxLen() {
"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");
assertThat(result).matches("^my-stack-name-my-resource-" + IdentifierUtilsTest.guidPattern);
}

@Test
Expand All @@ -97,15 +99,15 @@ public void generateResourceIdentifier_withLongStackNameAndShotLogicalId() {
"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");
assertThat(result).matches("^my-very-very-very-v-abc-" + IdentifierUtilsTest.guidPattern);
}

@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");
assertThat(result).matches("^abc-my-very-very-very-v-" + IdentifierUtilsTest.guidPattern);
}

@Test
Expand All @@ -114,7 +116,7 @@ public void generateResourceIdentifier_withLongStackNameAndLongLogicalId() {
"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");
assertThat(result).matches("^my-very-ver-my-very-ver-" + IdentifierUtilsTest.guidPattern);
}

@Test
Expand Down
Loading