diff --git a/repos/common/tests/src/commonMain/kotlin/CommonCRUDRepoTests.kt b/repos/common/tests/src/commonMain/kotlin/CommonCRUDRepoTests.kt index d8f21192b3d..b9177691ade 100644 --- a/repos/common/tests/src/commonMain/kotlin/CommonCRUDRepoTests.kt +++ b/repos/common/tests/src/commonMain/kotlin/CommonCRUDRepoTests.kt @@ -1,21 +1,27 @@ +package dev.inmo.micro_utils.repos.common.tests + import com.benasher44.uuid.uuid4 import dev.inmo.micro_utils.repos.CRUDRepo import dev.inmo.micro_utils.repos.create import dev.inmo.micro_utils.repos.deleteById import korlibs.time.seconds import kotlinx.coroutines.test.runTest +import kotlinx.serialization.Serializable import kotlin.test.* abstract class CommonCRUDRepoTests : CommonRepoTests>() { + @Serializable data class New( val data: String ) + @Serializable data class Registered( val id: String, val data: String ) - open fun creatingWorksProperly() = runTest(timeout = 120.seconds) { + @Test + fun creatingWorksProperly() = runTest(timeout = 120.seconds) { val crudRepo = repoCreator() val testData = (0 until testSequencesSize).map { ("$it-" + uuid4().toString()) @@ -53,7 +59,7 @@ abstract class CommonCRUDRepoTests : CommonRepoTests>() { - open fun creatingWorksProperly() = runTest(timeout = 120.seconds) { + @Test + fun creatingWorksProperly() = runTest(timeout = 120.seconds) { val repo = repoCreator() val testData = (0 until testSequencesSize).associate { ("$it-" + uuid4().toString()) to "$it-" + uuid4().toString() @@ -26,7 +30,8 @@ abstract class CommonKeyValueRepoTests : CommonRepoTests>() { - open fun creatingWorksProperly() = runTest(timeout = 120.seconds) { + @Test + fun creatingWorksProperly() = runTest(timeout = 120.seconds) { val repo = repoCreator() val testData = (0 until testSequencesSize).associate { ("$it-" + uuid4().toString()) to (0 until 1000).map { diff --git a/repos/common/tests/src/commonMain/kotlin/CommonRepoTests.kt b/repos/common/tests/src/commonMain/kotlin/CommonRepoTests.kt index b774bfdbd61..433b9ddf87e 100644 --- a/repos/common/tests/src/commonMain/kotlin/CommonRepoTests.kt +++ b/repos/common/tests/src/commonMain/kotlin/CommonRepoTests.kt @@ -1,4 +1,4 @@ -import dev.inmo.micro_utils.repos.CRUDRepo +package dev.inmo.micro_utils.repos.common.tests abstract class CommonRepoTests { protected open val testSequencesSize = 1000 diff --git a/repos/exposed/src/jvmTest/kotlin/ExposedCRUDRepoTests.kt b/repos/exposed/src/jvmTest/kotlin/ExposedCRUDRepoTests.kt index 7821a94e587..430bbcd0994 100644 --- a/repos/exposed/src/jvmTest/kotlin/ExposedCRUDRepoTests.kt +++ b/repos/exposed/src/jvmTest/kotlin/ExposedCRUDRepoTests.kt @@ -1,15 +1,10 @@ package full -import CommonCRUDRepoTests import com.benasher44.uuid.uuid4 import dev.inmo.micro_utils.repos.CRUDRepo -import dev.inmo.micro_utils.repos.create -import dev.inmo.micro_utils.repos.deleteById +import dev.inmo.micro_utils.repos.common.tests.CommonCRUDRepoTests import dev.inmo.micro_utils.repos.exposed.AbstractExposedCRUDRepo import dev.inmo.micro_utils.repos.exposed.initTable -import korlibs.time.seconds -import kotlinx.coroutines.test.TestResult -import kotlinx.coroutines.test.runTest import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.ISqlExpressionBuilder import org.jetbrains.exposed.sql.Op @@ -17,11 +12,11 @@ import org.jetbrains.exposed.sql.ResultRow import org.jetbrains.exposed.sql.statements.InsertStatement import org.jetbrains.exposed.sql.statements.UpdateBuilder import java.io.File -import javax.xml.crypto.Data -import kotlin.test.* +import kotlin.test.AfterTest +import kotlin.test.BeforeTest class ExposedCRUDRepoTests : CommonCRUDRepoTests() { - class Repo(override val database: Database) : AbstractExposedCRUDRepo() { + class Repo(override val database: Database) : AbstractExposedCRUDRepo() { val idColumn = text("_id") val dataColumn = text("data") @@ -29,8 +24,8 @@ class ExposedCRUDRepoTests : CommonCRUDRepoTests() { override val ResultRow.asId: String get() = get(idColumn) - override val ResultRow.asObject: CommonCRUDRepoTests.Registered - get() = CommonCRUDRepoTests.Registered( + override val ResultRow.asObject: Registered + get() = Registered( asId, get(dataColumn) ) @@ -40,13 +35,13 @@ class ExposedCRUDRepoTests : CommonCRUDRepoTests() { initTable() } - override fun update(id: String?, value: CommonCRUDRepoTests.New, it: UpdateBuilder) { + override fun update(id: String?, value: New, it: UpdateBuilder) { it[idColumn] = id ?: uuid4().toString() it[dataColumn] = value.data } - override fun InsertStatement.asObject(value: CommonCRUDRepoTests.New): CommonCRUDRepoTests.Registered { - return CommonCRUDRepoTests.Registered( + override fun InsertStatement.asObject(value: New): Registered { + return Registered( get(idColumn), get(dataColumn) ) @@ -64,14 +59,4 @@ class ExposedCRUDRepoTests : CommonCRUDRepoTests() { database = null File(filename).delete() } - - @Test - override fun creatingWorksProperly(): TestResult { - return super.creatingWorksProperly() - } - - @Test - override fun removingWorksProperly(): TestResult { - return super.removingWorksProperly() - } } diff --git a/repos/exposed/src/jvmTest/kotlin/ExposedKeyValueRepoTests.kt b/repos/exposed/src/jvmTest/kotlin/ExposedKeyValueRepoTests.kt index e142511804d..7c325d90c61 100644 --- a/repos/exposed/src/jvmTest/kotlin/ExposedKeyValueRepoTests.kt +++ b/repos/exposed/src/jvmTest/kotlin/ExposedKeyValueRepoTests.kt @@ -1,18 +1,17 @@ package full -import CommonKeyValueRepoTests -import com.benasher44.uuid.uuid4 -import dev.inmo.micro_utils.repos.* +import dev.inmo.micro_utils.repos.KeyValueRepo +import dev.inmo.micro_utils.repos.common.tests.CommonKeyValueRepoTests import dev.inmo.micro_utils.repos.exposed.initTable import dev.inmo.micro_utils.repos.exposed.keyvalue.AbstractExposedKeyValueRepo -import korlibs.time.seconds -import kotlinx.coroutines.test.TestResult -import kotlinx.coroutines.test.runTest -import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.statements.InsertStatement +import org.jetbrains.exposed.sql.Database +import org.jetbrains.exposed.sql.ISqlExpressionBuilder +import org.jetbrains.exposed.sql.Op +import org.jetbrains.exposed.sql.ResultRow import org.jetbrains.exposed.sql.statements.UpdateBuilder import java.io.File -import kotlin.test.* +import kotlin.test.AfterTest +import kotlin.test.BeforeTest class ExposedKeyValueRepoTests : CommonKeyValueRepoTests() { class Repo(override val database: Database) : AbstractExposedKeyValueRepo(database) { @@ -54,14 +53,4 @@ class ExposedKeyValueRepoTests : CommonKeyValueRepoTests() { } override val repoCreator: suspend () -> KeyValueRepo = { Repo(database!!) } - - @Test - override fun creatingWorksProperly(): TestResult { - return super.creatingWorksProperly() - } - - @Test - override fun unsettingWorksProperly(): TestResult { - return super.unsettingWorksProperly() - } } diff --git a/repos/exposed/src/jvmTest/kotlin/ExposedKeyValuesRepoTests.kt b/repos/exposed/src/jvmTest/kotlin/ExposedKeyValuesRepoTests.kt index 43ec7718941..9bafab6fa5c 100644 --- a/repos/exposed/src/jvmTest/kotlin/ExposedKeyValuesRepoTests.kt +++ b/repos/exposed/src/jvmTest/kotlin/ExposedKeyValuesRepoTests.kt @@ -1,17 +1,17 @@ package full -import CommonKeyValuesRepoTests -import dev.inmo.micro_utils.repos.* +import dev.inmo.micro_utils.repos.KeyValuesRepo +import dev.inmo.micro_utils.repos.common.tests.CommonKeyValuesRepoTests import dev.inmo.micro_utils.repos.exposed.initTable import dev.inmo.micro_utils.repos.exposed.onetomany.AbstractExposedKeyValuesRepo -import kotlinx.coroutines.test.TestResult import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.ISqlExpressionBuilder import org.jetbrains.exposed.sql.Op import org.jetbrains.exposed.sql.ResultRow import org.jetbrains.exposed.sql.statements.UpdateBuilder import java.io.File -import kotlin.test.* +import kotlin.test.AfterTest +import kotlin.test.BeforeTest class ExposedKeyValuesRepoTests : CommonKeyValuesRepoTests() { override val testSequencesSize: Int = 100 @@ -49,9 +49,4 @@ class ExposedKeyValuesRepoTests : CommonKeyValuesRepoTests() { } override val repoCreator: suspend () -> KeyValuesRepo = { Repo(database!!) } - - @Test - override fun creatingWorksProperly(): TestResult { - super.creatingWorksProperly() - } } diff --git a/repos/inmemory/src/commonTest/kotlin/InMemoryCRUDRepoTests.kt b/repos/inmemory/src/commonTest/kotlin/InMemoryCRUDRepoTests.kt index c14d499212d..132b57deebb 100644 --- a/repos/inmemory/src/commonTest/kotlin/InMemoryCRUDRepoTests.kt +++ b/repos/inmemory/src/commonTest/kotlin/InMemoryCRUDRepoTests.kt @@ -1,11 +1,9 @@ package full -import CommonCRUDRepoTests import com.benasher44.uuid.uuid4 import dev.inmo.micro_utils.repos.CRUDRepo import dev.inmo.micro_utils.repos.MapCRUDRepo -import kotlinx.coroutines.test.TestResult -import kotlin.test.* +import dev.inmo.micro_utils.repos.common.tests.CommonCRUDRepoTests class InMemoryCRUDRepoTests : CommonCRUDRepoTests() { override val repoCreator: suspend () -> CRUDRepo = { @@ -18,14 +16,4 @@ class InMemoryCRUDRepoTests : CommonCRUDRepoTests() { id to Registered(id, it.data) } } - - @Test - override fun creatingWorksProperly(): TestResult { - return super.creatingWorksProperly() - } - - @Test - override fun removingWorksProperly(): TestResult { - return super.removingWorksProperly() - } } diff --git a/repos/inmemory/src/commonTest/kotlin/InMemoryKeyValueRepoTests.kt b/repos/inmemory/src/commonTest/kotlin/InMemoryKeyValueRepoTests.kt index 3da9bf755b8..fd0a3b79f82 100644 --- a/repos/inmemory/src/commonTest/kotlin/InMemoryKeyValueRepoTests.kt +++ b/repos/inmemory/src/commonTest/kotlin/InMemoryKeyValueRepoTests.kt @@ -1,20 +1,9 @@ package full -import CommonKeyValueRepoTests -import dev.inmo.micro_utils.repos.* -import kotlinx.coroutines.test.TestResult -import kotlin.test.* +import dev.inmo.micro_utils.repos.KeyValueRepo +import dev.inmo.micro_utils.repos.MapKeyValueRepo +import dev.inmo.micro_utils.repos.common.tests.CommonKeyValueRepoTests class InMemoryKeyValueRepoTests : CommonKeyValueRepoTests() { override val repoCreator: suspend () -> KeyValueRepo = { MapKeyValueRepo() } - - @Test - override fun creatingWorksProperly(): TestResult { - return super.creatingWorksProperly() - } - - @Test - override fun unsettingWorksProperly(): TestResult { - return super.unsettingWorksProperly() - } } diff --git a/repos/inmemory/src/commonTest/kotlin/InMemoryKeyValuesRepoTests.kt b/repos/inmemory/src/commonTest/kotlin/InMemoryKeyValuesRepoTests.kt index 0d943bb713d..03bee23d43f 100644 --- a/repos/inmemory/src/commonTest/kotlin/InMemoryKeyValuesRepoTests.kt +++ b/repos/inmemory/src/commonTest/kotlin/InMemoryKeyValuesRepoTests.kt @@ -1,14 +1,9 @@ package full -import CommonKeyValuesRepoTests -import dev.inmo.micro_utils.repos.* -import kotlinx.coroutines.test.TestResult -import kotlin.test.* +import dev.inmo.micro_utils.repos.KeyValuesRepo +import dev.inmo.micro_utils.repos.MapKeyValuesRepo +import dev.inmo.micro_utils.repos.common.tests.CommonKeyValuesRepoTests class InMemoryKeyValuesRepoTests : CommonKeyValuesRepoTests() { override val repoCreator: suspend () -> KeyValuesRepo = { MapKeyValuesRepo() } - @Test - override fun creatingWorksProperly(): TestResult { - return super.creatingWorksProperly() - } } diff --git a/repos/ktor/common/build.gradle b/repos/ktor/common/build.gradle index f66aa9f0f4d..c6755dbf3d2 100644 --- a/repos/ktor/common/build.gradle +++ b/repos/ktor/common/build.gradle @@ -16,6 +16,7 @@ kotlin { jvmTest { dependencies { implementation internalProject("micro_utils.repos.common") + implementation internalProject("micro_utils.repos.common.tests") implementation internalProject("micro_utils.repos.ktor.client") implementation internalProject("micro_utils.repos.ktor.server") implementation internalProject("micro_utils.repos.inmemory") diff --git a/repos/ktor/common/src/jvmTest/kotlin/ComplexData.kt b/repos/ktor/common/src/jvmTest/kotlin/ComplexData.kt index ad202ee46b3..39f870f49c7 100644 --- a/repos/ktor/common/src/jvmTest/kotlin/ComplexData.kt +++ b/repos/ktor/common/src/jvmTest/kotlin/ComplexData.kt @@ -1,3 +1,5 @@ +package dev.inmo.micro_utils.repos.ktor + import com.benasher44.uuid.uuid4 import kotlinx.serialization.Serializable diff --git a/repos/ktor/common/src/jvmTest/kotlin/CRUDTests.kt b/repos/ktor/common/src/jvmTest/kotlin/KtorCRUDRepoTests.kt similarity index 71% rename from repos/ktor/common/src/jvmTest/kotlin/CRUDTests.kt rename to repos/ktor/common/src/jvmTest/kotlin/KtorCRUDRepoTests.kt index 922a72289da..0ed2b98eba3 100644 --- a/repos/ktor/common/src/jvmTest/kotlin/CRUDTests.kt +++ b/repos/ktor/common/src/jvmTest/kotlin/KtorCRUDRepoTests.kt @@ -1,4 +1,8 @@ +package dev.inmo.micro_utils.repos.ktor + +import com.benasher44.uuid.uuid4 import dev.inmo.micro_utils.repos.* +import dev.inmo.micro_utils.repos.common.tests.CommonCRUDRepoTests import dev.inmo.micro_utils.repos.ktor.client.crud.KtorCRUDRepoClient import dev.inmo.micro_utils.repos.ktor.server.crud.configureCRUDRepoRoutes import io.ktor.client.HttpClient @@ -8,17 +12,53 @@ import io.ktor.serialization.kotlinx.KotlinxWebsocketSerializationConverter import io.ktor.serialization.kotlinx.json.json import io.ktor.server.application.install import io.ktor.server.cio.CIO +import io.ktor.server.engine.* import io.ktor.server.plugins.contentnegotiation.ContentNegotiation import io.ktor.server.routing.routing import io.ktor.server.websocket.WebSockets -import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.TestResult import kotlinx.coroutines.test.runTest import kotlinx.serialization.json.Json +import kotlin.test.AfterTest +import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals -class CRUDTests { - @OptIn(ExperimentalCoroutinesApi::class) +class KtorCRUDRepoTests : CommonCRUDRepoTests() { + private var engine: ApplicationEngine? = null + + @BeforeTest + fun beforeTest() { + engine = KtorRepoTestsHelper.beforeTest { + configureCRUDRepoRoutes( + MapCRUDRepo( + { new, id, old -> + Registered(id, new.data) + } + ) { + val id = uuid4().toString() + id to Registered(id, it.data) + } + ) { + it + } + } + } + @AfterTest + fun afterTest() { + engine ?.let(KtorRepoTestsHelper::afterTest) + } + + override val repoCreator: suspend () -> CRUDRepo = { + KtorCRUDRepoClient( + "http://127.0.0.1:23456", + KtorRepoTestsHelper.client(), + ContentType.Application.Json + ) { + it + } + } + @Test fun testCRUDFunctions() { runTest { @@ -33,7 +73,7 @@ class CRUDTests { } val server = io.ktor.server.engine.embeddedServer( CIO, - 23456, + 34567, "127.0.0.1" ) { install(ContentNegotiation) { @@ -60,7 +100,7 @@ class CRUDTests { } } val crudClient = KtorCRUDRepoClient( - "http://127.0.0.1:23456", + "http://127.0.0.1:34567", client, ContentType.Application.Json ) { diff --git a/repos/ktor/common/src/jvmTest/kotlin/KVTests.kt b/repos/ktor/common/src/jvmTest/kotlin/KtorKeyValueRepoTests.kt similarity index 80% rename from repos/ktor/common/src/jvmTest/kotlin/KVTests.kt rename to repos/ktor/common/src/jvmTest/kotlin/KtorKeyValueRepoTests.kt index 2a0df3bff7f..80942cba6a8 100644 --- a/repos/ktor/common/src/jvmTest/kotlin/KVTests.kt +++ b/repos/ktor/common/src/jvmTest/kotlin/KtorKeyValueRepoTests.kt @@ -1,8 +1,13 @@ +package dev.inmo.micro_utils.repos.ktor + import dev.inmo.micro_utils.pagination.firstPageWithOneElementPagination import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import dev.inmo.micro_utils.repos.* +import dev.inmo.micro_utils.repos.common.tests.CommonKeyValueRepoTests import dev.inmo.micro_utils.repos.ktor.client.key.value.KtorKeyValueRepoClient +import dev.inmo.micro_utils.repos.ktor.client.key.values.KtorKeyValuesRepoClient import dev.inmo.micro_utils.repos.ktor.server.key.value.configureKeyValueRepoRoutes +import dev.inmo.micro_utils.repos.ktor.server.key.values.configureKeyValuesRepoRoutes import io.ktor.client.HttpClient import io.ktor.client.plugins.logging.Logging import io.ktor.http.ContentType @@ -10,17 +15,47 @@ import io.ktor.serialization.kotlinx.KotlinxWebsocketSerializationConverter import io.ktor.serialization.kotlinx.json.json import io.ktor.server.application.install import io.ktor.server.cio.CIO +import io.ktor.server.engine.* import io.ktor.server.plugins.contentnegotiation.ContentNegotiation import io.ktor.server.routing.routing import io.ktor.server.websocket.WebSockets import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.TestResult import kotlinx.coroutines.test.runTest import kotlinx.serialization.builtins.serializer import kotlinx.serialization.json.Json import kotlin.test.* -class KVTests { - @OptIn(ExperimentalCoroutinesApi::class) +class KtorKeyValueRepoTests : CommonKeyValueRepoTests() { + private var engine: ApplicationEngine? = null + + override val repoCreator: suspend () -> KeyValueRepo = { + KtorKeyValueRepoClient( + "http://127.0.0.1:23456", + KtorRepoTestsHelper.client(), + ContentType.Application.Json, + String.serializer(), + String.serializer(), + Json + ) + } + + @BeforeTest + fun beforeTest() { + engine = KtorRepoTestsHelper.beforeTest { + configureKeyValueRepoRoutes( + MapKeyValueRepo(), + String.serializer(), + String.serializer(), + Json + ) + } + } + @AfterTest + fun afterTest() { + engine ?.let(KtorRepoTestsHelper::afterTest) + } + @Test fun testKVFunctions() { runTest { @@ -28,7 +63,7 @@ class KVTests { val repo = MapKeyValueRepo(map) val server = io.ktor.server.engine.embeddedServer( CIO, - 23456, + 34567, "127.0.0.1" ) { install(ContentNegotiation) { @@ -56,7 +91,7 @@ class KVTests { } } val crudClient = KtorKeyValueRepoClient( - "http://127.0.0.1:23456", + "http://127.0.0.1:34567", client, ContentType.Application.Json, Int.serializer(), diff --git a/repos/ktor/common/src/jvmTest/kotlin/KVsTests.kt b/repos/ktor/common/src/jvmTest/kotlin/KtorKeyValuesRepoTests.kt similarity index 76% rename from repos/ktor/common/src/jvmTest/kotlin/KVsTests.kt rename to repos/ktor/common/src/jvmTest/kotlin/KtorKeyValuesRepoTests.kt index de3ff95484a..a5f7214fafa 100644 --- a/repos/ktor/common/src/jvmTest/kotlin/KVsTests.kt +++ b/repos/ktor/common/src/jvmTest/kotlin/KtorKeyValuesRepoTests.kt @@ -1,26 +1,59 @@ +package dev.inmo.micro_utils.repos.ktor + import dev.inmo.micro_utils.pagination.firstPageWithOneElementPagination import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import dev.inmo.micro_utils.repos.* +import dev.inmo.micro_utils.repos.common.tests.CommonKeyValuesRepoTests import dev.inmo.micro_utils.repos.ktor.client.key.values.KtorKeyValuesRepoClient import dev.inmo.micro_utils.repos.ktor.server.key.values.configureKeyValuesRepoRoutes -import io.ktor.client.HttpClient -import io.ktor.client.plugins.logging.Logging +import io.ktor.client.* +import io.ktor.client.plugins.logging.* import io.ktor.http.ContentType -import io.ktor.serialization.kotlinx.KotlinxWebsocketSerializationConverter -import io.ktor.serialization.kotlinx.json.json -import io.ktor.server.application.install -import io.ktor.server.cio.CIO -import io.ktor.server.plugins.contentnegotiation.ContentNegotiation -import io.ktor.server.routing.routing -import io.ktor.server.websocket.WebSockets -import kotlinx.coroutines.ExperimentalCoroutinesApi +import io.ktor.serialization.kotlinx.* +import io.ktor.serialization.kotlinx.json.* +import io.ktor.server.application.* +import io.ktor.server.cio.* +import io.ktor.server.engine.* +import io.ktor.server.plugins.contentnegotiation.* +import io.ktor.server.routing.* +import io.ktor.server.websocket.* import kotlinx.coroutines.test.runTest import kotlinx.serialization.builtins.serializer import kotlinx.serialization.json.Json import kotlin.test.* -class KVsTests { - @OptIn(ExperimentalCoroutinesApi::class) +class KtorKeyValuesRepoTests : CommonKeyValuesRepoTests() { + private var engine: ApplicationEngine? = null + override val testSequencesSize: Int + get() = 100 + + override val repoCreator: suspend () -> KeyValuesRepo = { + KtorKeyValuesRepoClient( + "http://127.0.0.1:23456", + KtorRepoTestsHelper.client(), + ContentType.Application.Json, + String.serializer(), + String.serializer(), + Json + ) + } + + @BeforeTest + fun beforeTest() { + engine = KtorRepoTestsHelper.beforeTest { + configureKeyValuesRepoRoutes( + MapKeyValuesRepo(), + String.serializer(), + String.serializer(), + Json + ) + } + } + @AfterTest + fun afterTest() { + engine ?.let(KtorRepoTestsHelper::afterTest) + } + @Test fun testKVsFunctions() { runTest { @@ -28,7 +61,7 @@ class KVsTests { val repo = MapKeyValuesRepo(map) val server = io.ktor.server.engine.embeddedServer( CIO, - 23456, + 34567, "127.0.0.1" ) { install(ContentNegotiation) { @@ -42,7 +75,7 @@ class KVsTests { repo, Int.serializer(), ComplexData.serializer(), - Json {} + Json ) } }.start(false) @@ -56,7 +89,7 @@ class KVsTests { } } val crudClient = KtorKeyValuesRepoClient( - "http://127.0.0.1:23456", + "http://127.0.0.1:34567", client, ContentType.Application.Json, Int.serializer(), diff --git a/repos/ktor/common/src/jvmTest/kotlin/KtorRepoTestsHelper.kt b/repos/ktor/common/src/jvmTest/kotlin/KtorRepoTestsHelper.kt new file mode 100644 index 00000000000..d50cd7fca5d --- /dev/null +++ b/repos/ktor/common/src/jvmTest/kotlin/KtorRepoTestsHelper.kt @@ -0,0 +1,44 @@ +package dev.inmo.micro_utils.repos.ktor + +import io.ktor.client.* +import io.ktor.client.plugins.logging.* +import io.ktor.serialization.kotlinx.* +import io.ktor.serialization.kotlinx.json.* +import io.ktor.server.application.* +import io.ktor.server.cio.* +import io.ktor.server.engine.* +import io.ktor.server.plugins.contentnegotiation.* +import io.ktor.server.routing.* +import io.ktor.server.websocket.* +import kotlinx.serialization.json.Json + +object KtorRepoTestsHelper { + fun beforeTest(routingConfigurator: Routing.() -> Unit): ApplicationEngine { + return embeddedServer( + CIO, + 23456, + "127.0.0.1" + ) { + install(ContentNegotiation) { + json() + } + install(WebSockets) { + contentConverter = KotlinxWebsocketSerializationConverter(Json) + } + routing(routingConfigurator) + }.start(false) + } + fun afterTest(engine: ApplicationEngine) { + engine.stop() + } + fun client(): HttpClient = HttpClient { + install(io.ktor.client.plugins.contentnegotiation.ContentNegotiation) { + json() + } + install(Logging) + install(io.ktor.client.plugins.websocket.WebSockets) { + contentConverter = KotlinxWebsocketSerializationConverter(Json) + } + } + +} diff --git a/repos/ktor/common/src/jvmTest/kotlin/SimpleData.kt b/repos/ktor/common/src/jvmTest/kotlin/SimpleData.kt index a078cfe0cf1..6ea7697f9ab 100644 --- a/repos/ktor/common/src/jvmTest/kotlin/SimpleData.kt +++ b/repos/ktor/common/src/jvmTest/kotlin/SimpleData.kt @@ -1,3 +1,5 @@ +package dev.inmo.micro_utils.repos.ktor + import com.benasher44.uuid.uuid4 import kotlinx.serialization.Serializable