From 1698874bd0ceb815e04c94268dede6944381971c Mon Sep 17 00:00:00 2001 From: Tatiana Viana Date: Tue, 3 Sep 2024 11:57:53 -0700 Subject: [PATCH] Fix IdentifierUtils unit tests --- .../cloudformation/resource/IdentifierUtils.java | 2 +- .../cloudformation/resource/IdentifierUtilsTest.java | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/software/amazon/cloudformation/resource/IdentifierUtils.java b/src/main/java/software/amazon/cloudformation/resource/IdentifierUtils.java index 1bc8d213..6d64d9bc 100644 --- a/src/main/java/software/amazon/cloudformation/resource/IdentifierUtils.java +++ b/src/main/java/software/amazon/cloudformation/resource/IdentifierUtils.java @@ -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('/'); diff --git a/src/test/java/software/amazon/cloudformation/resource/IdentifierUtilsTest.java b/src/test/java/software/amazon/cloudformation/resource/IdentifierUtilsTest.java index a7b109aa..264c75e7 100644 --- a/src/test/java/software/amazon/cloudformation/resource/IdentifierUtilsTest.java +++ b/src/test/java/software/amazon/cloudformation/resource/IdentifierUtilsTest.java @@ -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"); @@ -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 @@ -97,7 +99,7 @@ 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 @@ -105,7 +107,7 @@ 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 @@ -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