Skip to content

Commit 2be5c76

Browse files
committed
Migrated to Multi-dollar string interpolation
Signed-off-by: Gopal S Akshintala <[email protected]>
1 parent a4ebc00 commit 2be5c76

File tree

5 files changed

+50
-48
lines changed

5 files changed

+50
-48
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

buildSrc/src/main/kotlin/revoman.kt-conventions.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ kapt {
2121
kotlin {
2222
jvmToolchain(libs.jdk.toString().toInt())
2323
compilerOptions {
24-
freeCompilerArgs.addAll("-Xjvm-default=all", "-Xcontext-receivers", "-Xconsistent-data-class-copy-visibility")
24+
freeCompilerArgs.addAll("-Xjvm-default=all", "-Xcontext-receivers", "-Xconsistent-data-class-copy-visibility", "-Xmulti-dollar-interpolation")
2525
}
2626
}

src/main/kotlin/com/salesforce/revoman/internal/postman/DynamicVariableGenerator.kt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,38 @@ private val faker = faker {}
3131
private val dynamicVariableGenerators: Map<String, () -> String> =
3232
mapOf(
3333
// Common
34-
"\$guid" to { UUID.randomUUID().toString() },
35-
"\$timestamp" to { Clock.System.now().epochSeconds.toString() },
36-
"\$isoTimestamp" to { Clock.System.now().toString() },
37-
"\$randomUUID" to { UUID.randomUUID().toString() },
34+
$$"$guid" to { UUID.randomUUID().toString() },
35+
$$"$timestamp" to { Clock.System.now().epochSeconds.toString() },
36+
$$"$isoTimestamp" to { Clock.System.now().toString() },
37+
$$"$randomUUID" to { UUID.randomUUID().toString() },
3838
// Text, numbers, and colors
39-
"\$randomAlphaNumeric" to { randomAlphanumeric(1) },
40-
"\$randomBoolean" to { nextBoolean().toString() },
41-
"\$randomInt" to { nextInt(0, Int.MAX_VALUE).toString() },
42-
"\$randomColor" to faker.color::name,
43-
"\$randomHexColor" to { "#${getRandomHex()}${getRandomHex()}${getRandomHex()}" },
39+
$$"$randomAlphaNumeric" to { randomAlphanumeric(1) },
40+
$$"$randomBoolean" to { nextBoolean().toString() },
41+
$$"$randomInt" to { nextInt(0, Int.MAX_VALUE).toString() },
42+
$$"$randomColor" to faker.color::name,
43+
$$"$randomHexColor" to { "#${getRandomHex()}${getRandomHex()}${getRandomHex()}" },
4444
// Internet and IP addresses
45-
"\$randomIP" to faker.internet::iPv4Address,
46-
"\$randomIPV6" to faker.internet::iPv6Address,
47-
"\$randomMACAddress" to { faker.internet.macAddress() },
48-
"\$randomPassword" to { randomAlphanumeric(15) },
45+
$$"$randomIP" to faker.internet::iPv4Address,
46+
$$"$randomIPV6" to faker.internet::iPv6Address,
47+
$$"$randomMACAddress" to { faker.internet.macAddress() },
48+
$$"$randomPassword" to { randomAlphanumeric(15) },
4949
// Names
50-
"\$randomFirstName" to faker.name::firstName,
51-
"\$randomLastName" to faker.name::lastName,
52-
"\$randomUserName" to { faker.name.firstName() + faker.name.lastName() },
50+
$$"$randomFirstName" to faker.name::firstName,
51+
$$"$randomLastName" to faker.name::lastName,
52+
$$"$randomUserName" to { faker.name.firstName() + faker.name.lastName() },
5353
// Phone, address, and location
54-
"\$randomCity" to faker.address::city,
54+
$$"$randomCity" to faker.address::city,
5555
// Grammar
56-
"\$randomAdjective" to faker.adjective::positive,
57-
"\$randomWord" to faker.lorem::words,
56+
$$"$randomAdjective" to faker.adjective::positive,
57+
$$"$randomWord" to faker.lorem::words,
5858
// Business
59-
"\$randomCompanyName" to faker.company::name,
60-
"\$randomProduct" to faker.industrySegments::sector,
59+
$$"$randomCompanyName" to faker.company::name,
60+
$$"$randomProduct" to faker.industrySegments::sector,
6161
// Domains, emails, and usernames
62-
"\$randomEmail" to { faker.internet.email() },
62+
$$"$randomEmail" to { faker.internet.email() },
6363
// Date time
64-
"\$currentDate" to { LocalDate.now().toString() },
65-
"\$randomFutureDate" to
64+
$$"$currentDate" to { LocalDate.now().toString() },
65+
$$"$randomFutureDate" to
6666
{
6767
LocalDate.now().let { it.plusDays(nextLong(1, it.lengthOfYear().toLong())).toString() }
6868
},
@@ -76,7 +76,7 @@ fun randomAlphanumeric(length: Int) =
7676
(1..length).map { charPool[nextInt(0, charPool.size)] }.joinToString("")
7777

7878
private val dynamicVariableGeneratorsWithPM: Map<String, (PostmanSDK) -> String> =
79-
mapOf("\$currentRequestName" to { it.info.requestName })
79+
mapOf($$"$currentRequestName" to { it.info.requestName })
8080

8181
internal fun dynamicVariableGenerator(key: String, pm: PostmanSDK): String? =
8282
dynamicVariableGenerators[key]?.invoke() ?: dynamicVariableGeneratorsWithPM[key]?.invoke(pm)

src/test/kotlin/com/salesforce/revoman/input/EvalJsTest.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class EvalJsTest {
5959
pm.rundown = mockk()
6060
pm
6161
.evaluateJS(
62-
"""
63-
pm.variables.replaceIn("Today is {{${"$"}currentDate}}")
62+
$$"""
63+
pm.variables.replaceIn("Today is {{$currentDate}}")
6464
"""
6565
.trimIndent()
6666
)
@@ -70,24 +70,24 @@ class EvalJsTest {
7070
@Test
7171
fun `eval JS with moment`() {
7272
pm.evaluateJS(
73-
"""
73+
$$"""
7474
var moment = require('moment')
75-
pm.environment.set("${"$"}currentDate", moment().format(("YYYY-MM-DD")))
75+
pm.environment.set("$currentDate", moment().format(("YYYY-MM-DD")))
7676
"""
7777
.trimIndent()
7878
)
79-
pm.environment shouldContain Pair("\$currentDate", LocalDate.now().toString())
79+
pm.environment shouldContain Pair($$"$currentDate", LocalDate.now().toString())
8080
}
8181

8282
@Test
8383
fun `eval JS with lodash`() {
8484
pm.evaluateJS(
85-
"""
86-
pm.environment.set("${"$"}randomNum", _.random(10))
85+
$$"""
86+
pm.environment.set("$randomNum", _.random(10))
8787
"""
8888
.trimIndent()
8989
)
90-
pm.environment.getInt("\$randomNum")!! shouldBeInRange 0..10
90+
pm.environment.getInt($$"$randomNum")!! shouldBeInRange 0..10
9191
}
9292

9393
@Test

src/test/kotlin/com/salesforce/revoman/internal/postman/RegexReplacerTest.kt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class RegexReplacerTest {
2121
fun `unmarshall Env File with Regex and Dynamic variable`() {
2222
val epoch = System.currentTimeMillis().toString()
2323
val dummyDynamicVariableGenerator = { r: String, _: PostmanSDK ->
24-
if (r == "\$epoch") epoch else null
24+
if (r == $$"$epoch") epoch else null
2525
}
2626
val regexReplacer = RegexReplacer(emptyMap(), dummyDynamicVariableGenerator)
2727
val pm = PostmanSDK(mockk(), null, regexReplacer)
@@ -37,15 +37,15 @@ class RegexReplacerTest {
3737
fun `dynamic variables - Body + dynamic env`() {
3838
val epoch = System.currentTimeMillis().toString()
3939
val dummyDynamicVariableGenerator = { key: String, _: PostmanSDK ->
40-
if (key == "\$epoch") epoch else null
40+
if (key == $$"$epoch") epoch else null
4141
}
4242
val regexReplacer = RegexReplacer(dynamicVariableGenerator = dummyDynamicVariableGenerator)
4343
val pm = PostmanSDK(mockk(), null, regexReplacer)
44-
pm.environment["key"] = "value-{{\$epoch}}"
44+
pm.environment["key"] = $$"value-{{$epoch}}"
4545
val jsonStr =
46-
"""
46+
$$"""
4747
{
48-
"epoch": "{{${"$"}epoch}}",
48+
"epoch": "{{$epoch}}",
4949
"key": "{{key}}"
5050
}
5151
"""
@@ -63,17 +63,19 @@ class RegexReplacerTest {
6363
val noopDynamicVariableGenerator = { _: String, _: PostmanSDK -> null }
6464
val regexReplacer =
6565
RegexReplacer(
66-
mapOf("\$customEpoch" to customDynamicVariableGenerator),
66+
mapOf($$"$customEpoch" to customDynamicVariableGenerator),
6767
noopDynamicVariableGenerator,
6868
)
6969
val pm = PostmanSDK(mockk(), null, regexReplacer)
70-
pm.environment["key"] = "value-{{\$customEpoch}}"
70+
pm.environment["key"] = $$"value-{{$customEpoch}}"
71+
// This should get shadowed by custom dynamic variable
72+
pm.environment[$$"$customEpoch"] = $$"value-{{$customEpoch}}"
7173
pm.currentStepReport = mockk()
7274
pm.rundown = mockk()
7375
val jsonStr =
74-
"""
76+
$$"""
7577
{
76-
"epoch": "{{${"$"}customEpoch}}",
78+
"epoch": "{{$customEpoch}}",
7779
"key": "{{key}}"
7880
}
7981
"""
@@ -85,14 +87,14 @@ class RegexReplacerTest {
8587

8688
@OptIn(ExperimentalStdlibApi::class)
8789
@Test
88-
fun `duplicate dynamic variables should have different values`() {
90+
fun `duplicate dynamic variables for random value generation should have different values`() {
8991
val regexReplacer = RegexReplacer()
9092
val pm = PostmanSDK(mockk(), regexReplacer = regexReplacer)
9193
val jsonStr =
92-
"""
94+
$$"""
9395
{
94-
"key1": "{{${"$"}randomUUID}}",
95-
"key2": "{{${"$"}randomUUID}}"
96+
"key1": "{{$randomUUID}}",
97+
"key2": "{{$randomUUID}}"
9698
}
9799
"""
98100
.trimIndent()

0 commit comments

Comments
 (0)