mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2026-01-25 22:58:05 +00:00
add tests for cruds
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import com.benasher44.uuid.uuid4
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
import korlibs.time.seconds
|
||||
import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlin.test.*
|
||||
|
||||
abstract class CommonKeyValuesRepoTests : CommonRepoTests<KeyValuesRepo<String, String>>() {
|
||||
open fun creatingWorksProperly() = runTest(timeout = 120.seconds) {
|
||||
val repo = repoCreator()
|
||||
val testData = (0 until testSequencesSize).associate {
|
||||
("$it-" + uuid4().toString()) to (0 until 1000).map {
|
||||
"$it-" + uuid4().toString()
|
||||
}.sorted()
|
||||
}
|
||||
val updatedTestData = testData.keys.associateWith {
|
||||
(0 until 1000).map {
|
||||
"$it-" + uuid4().toString()
|
||||
}.sorted()
|
||||
}
|
||||
val addedData = testData.keys.associateWith {
|
||||
"$it-" + uuid4().toString()
|
||||
}
|
||||
|
||||
updatedTestData.map {
|
||||
launch {
|
||||
repo.set(it.key, it.value)
|
||||
assertContentEquals(it.value.sorted(), repo.getAll(it.key).sorted())
|
||||
}
|
||||
}.joinAll()
|
||||
|
||||
updatedTestData.map {
|
||||
launch {
|
||||
repo.set(it.key, it.value)
|
||||
val all = repo.getAll(it.key)
|
||||
assertContentEquals(it.value.sorted(), all.sorted())
|
||||
}
|
||||
}.joinAll()
|
||||
|
||||
addedData.forEach {
|
||||
repo.add(it.key, it.value)
|
||||
assertTrue(repo.contains(it.key, it.value))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user