Skip to content

Commit

Permalink
Fix IdentifierUtils unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tvp-1 committed Sep 3, 2024
1 parent b9cfe28 commit 1698874
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
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

0 comments on commit 1698874

Please sign in to comment.