Skip to content
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 @@ -19,7 +19,12 @@ package com.google.firebase.dataconnect.testutil
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.firebase.dataconnect.ConnectorConfig
import com.google.firebase.util.nextAlphanumericString
import io.kotest.property.Arb
import io.kotest.property.RandomSource
import io.kotest.property.arbitrary.Codepoint
import io.kotest.property.arbitrary.alphanumeric
import io.kotest.property.arbitrary.arbitrary
import io.kotest.property.arbitrary.string
import kotlin.random.Random
import org.junit.Rule
import org.junit.rules.TestName
Expand All @@ -40,6 +45,31 @@ abstract class DataConnectIntegrationTestBase {

val rs: RandomSource by randomSeedTestRule.rs

/**
* Generates and returns a string containing random alphanumeric characters, including the name of
* the currently-running test as returned from [testName].
*
* @param string The [Arb] to use to generate the random string; if not specified, then an [Arb]
* that generates strings of 20 alphanumeric characters is used.
* @param prefix A prefix to include in the returned string; if null (the default) then no prefix
* will be included.
* @return a string containing random characters and incorporating the other information
* identified above.
*/
fun Arb.Companion.alphanumericString(
string: Arb<String> = Arb.string(20, Codepoint.alphanumeric()),
prefix: String? = null,
): Arb<String> = arbitrary {
buildString {
if (prefix != null) {
append(prefix)
}
append(testName)
append("_")
append(string.bind())
}
}

companion object {
val testConnectorConfig: ConnectorConfig
get() =
Expand Down
Loading
Loading