Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Julia Plewa <jplewa@virtuslab.com>
  • Loading branch information
jplewa committed Jul 21, 2023
1 parent b894fac commit 529773a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ data class PulumiName(
}

fun toResourceFunctionName(namingFlags: NamingFlags): String {
require(namingFlags.language == Kotlin)
val resourceName = toResourceName(namingFlags)
val numberOfCaps = resourceName.takeWhile { it.isUpperCase() || it.isDigit() }.count()
return if (numberOfCaps == resourceName.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,13 +564,28 @@ internal class PulumiNameTest {

// when
val pulumiName = PulumiName.from(token, namingConfiguration)
val namingFlags = NamingFlags(Root, Resource, Input, Java)
val namingFlags = NamingFlags(Root, Resource, Input, Kotlin)
val resourceFunctionName = pulumiName.toResourceFunctionName(namingFlags)

// then
assertEquals("organizationPolicy", resourceFunctionName)
}

@Test
fun `a resource function name starting with a two-letter acronym is decapitalized correctly`() {
// given
val token = "provider:module:VMwareCluster"
val namingConfiguration = PulumiNamingConfiguration.create(providerName = "provider")

// when
val pulumiName = PulumiName.from(token, namingConfiguration)
val namingFlags = NamingFlags(Root, Resource, Input, Kotlin)
val resourceFunctionName = pulumiName.toResourceFunctionName(namingFlags)

// then
assertEquals("vMwareCluster", resourceFunctionName)
}

@Test
fun `a resource function name starting with a three-letter acronym is decapitalized correctly`() {
// given
Expand All @@ -579,7 +594,7 @@ internal class PulumiNameTest {

// when
val pulumiName = PulumiName.from(token, namingConfiguration)
val namingFlags = NamingFlags(Root, Resource, Input, Java)
val namingFlags = NamingFlags(Root, Resource, Input, Kotlin)
val resourceFunctionName = pulumiName.toResourceFunctionName(namingFlags)

// then
Expand All @@ -594,7 +609,7 @@ internal class PulumiNameTest {

// when
val pulumiName = PulumiName.from(token, namingConfiguration)
val namingFlags = NamingFlags(Root, Resource, Input, Java)
val namingFlags = NamingFlags(Root, Resource, Input, Kotlin)
val resourceFunctionName = pulumiName.toResourceFunctionName(namingFlags)

// then
Expand All @@ -609,7 +624,7 @@ internal class PulumiNameTest {

// when
val pulumiName = PulumiName.from(token, namingConfiguration)
val namingFlags = NamingFlags(Root, Resource, Input, Java)
val namingFlags = NamingFlags(Root, Resource, Input, Kotlin)
val resourceFunctionName = pulumiName.toResourceFunctionName(namingFlags)

// then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,23 @@ internal class StringUtilsKtTest {
}

@Test
fun `should turn the expected number of character lowercase`() {
assertEquals("sslCertificate", "SSLCertificate".lowercaseBefore(3))
fun `should do nothing when trying to turn all characters before index=0 lowercase`() {
assertEquals("ABCD", "ABCD".lowercaseBefore(index = 0))
}

@Test
fun `should turn all characters before index=1 lowercase`() {
assertEquals("aBCD", "ABCD".lowercaseBefore(index = 1))
}

@Test
fun `should turn all characters before index=3 lowercase`() {
assertEquals("abcD", "ABCD".lowercaseBefore(index = 3))
}

@Test
fun `should turn all characters before index=4 to lower case in a string with 4 characters`() {
assertEquals("abcd", "ABCD".lowercaseBefore(index = 4))
}

@Suppress("unused")
Expand Down

0 comments on commit 529773a

Please sign in to comment.