From c2ffbdcd0c9eba2655a32bf71dd28eed2ed47f35 Mon Sep 17 00:00:00 2001 From: Johann Pardanaud Date: Sat, 2 Nov 2024 18:28:43 +0100 Subject: [PATCH] wip: ktor 3 --- .../nesk/akkurate/ktor/server/AkkurateTest.kt | 1 + .../ktor/server/AkkurateConfigTest.jvm.kt | 3 +- .../ktor/server/RegisterValidatorKtTest.kt | 29 ++++++++++--------- settings.gradle.kts | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/akkurate-ktor-server/src/commonTest/kotlin/dev/nesk/akkurate/ktor/server/AkkurateTest.kt b/akkurate-ktor-server/src/commonTest/kotlin/dev/nesk/akkurate/ktor/server/AkkurateTest.kt index 3a94be9..29c7188 100644 --- a/akkurate-ktor-server/src/commonTest/kotlin/dev/nesk/akkurate/ktor/server/AkkurateTest.kt +++ b/akkurate-ktor-server/src/commonTest/kotlin/dev/nesk/akkurate/ktor/server/AkkurateTest.kt @@ -25,6 +25,7 @@ import io.ktor.client.request.* import io.ktor.client.statement.* import io.ktor.http.* import io.ktor.serialization.kotlinx.json.* +import io.ktor.server.application.* import io.ktor.server.plugins.contentnegotiation.* import io.ktor.server.plugins.requestvalidation.* import io.ktor.server.request.* diff --git a/akkurate-ktor-server/src/jvmTest/kotlin/dev/nesk/akkurate/ktor/server/AkkurateConfigTest.jvm.kt b/akkurate-ktor-server/src/jvmTest/kotlin/dev/nesk/akkurate/ktor/server/AkkurateConfigTest.jvm.kt index ae4eef0..4aa629f 100644 --- a/akkurate-ktor-server/src/jvmTest/kotlin/dev/nesk/akkurate/ktor/server/AkkurateConfigTest.jvm.kt +++ b/akkurate-ktor-server/src/jvmTest/kotlin/dev/nesk/akkurate/ktor/server/AkkurateConfigTest.jvm.kt @@ -20,6 +20,7 @@ package dev.nesk.akkurate.ktor.server import dev.nesk.akkurate.constraints.ConstraintViolationSet import io.ktor.server.application.* import io.ktor.server.response.* +import io.ktor.util.reflect.* import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot @@ -33,7 +34,7 @@ class AkkurateConfigTestJvm { // Arrange val messageSlot = slot() val call = mockk(relaxed = true) - coEvery { call.respond(capture(messageSlot)) } returns Unit + coEvery { call.respond(capture(messageSlot), any(TypeInfo::class)) } returns Unit // Act val config = AkkurateConfig() diff --git a/akkurate-ktor-server/src/jvmTest/kotlin/dev/nesk/akkurate/ktor/server/RegisterValidatorKtTest.kt b/akkurate-ktor-server/src/jvmTest/kotlin/dev/nesk/akkurate/ktor/server/RegisterValidatorKtTest.kt index cf0d553..3f7d49d 100644 --- a/akkurate-ktor-server/src/jvmTest/kotlin/dev/nesk/akkurate/ktor/server/RegisterValidatorKtTest.kt +++ b/akkurate-ktor-server/src/jvmTest/kotlin/dev/nesk/akkurate/ktor/server/RegisterValidatorKtTest.kt @@ -28,16 +28,17 @@ import kotlin.test.Test import kotlin.test.assertFails import kotlin.test.assertIs import kotlin.test.assertSame +import io.ktor.server.plugins.requestvalidation.Validator as KtorValidator class RegisterValidatorKtTest { companion object { val context = object {} val value = object {} - val lambdaSlot = slot ValidationResult.Valid>() + val validatorSlot = slot() val config = mockk() init { - every { config.validate(capture(lambdaSlot)) } returns Unit + every { config.validate(capture(validatorSlot)) } returns Unit } } @@ -46,7 +47,7 @@ class RegisterValidatorKtTest { fun registered_contextual_validator_uses_the_provided_context_and_value() = runBlocking { val validate = Validator { ctx -> constrain { ctx === context && it === value } } config.registerValidator(validate) { context } - val result = lambdaSlot.captured(value) + val result = validatorSlot.captured.validate(value) assertSame(ValidationResult.Valid, result) } @@ -54,7 +55,7 @@ class RegisterValidatorKtTest { fun registered_contextual_validator_returns__ValidationResult_Valid__when_value_is_valid() = runBlocking { val validate = Validator { constrain { true } } config.registerValidator(validate) { context } - val result = lambdaSlot.captured(value) + val result = validatorSlot.captured.validate(value) assertSame(ValidationResult.Valid, result) } @@ -62,7 +63,7 @@ class RegisterValidatorKtTest { fun registered_contextual_validator_throws__ValidationResult_Exception__when_value_is_invalid(): Unit = runBlocking { val validate = Validator { constrain { false } } config.registerValidator(validate) { context } - val exception = assertFails { lambdaSlot.captured(value) } + val exception = assertFails { validatorSlot.captured.validate(value) } assertIs(exception) } //endregion @@ -72,7 +73,7 @@ class RegisterValidatorKtTest { fun registered_validator_uses_the_provided_value() = runBlocking { val validate = Validator { constrain { it === value } } config.registerValidator(validate) - val result = lambdaSlot.captured(value) + val result = validatorSlot.captured.validate(value) assertSame(ValidationResult.Valid, result) } @@ -80,7 +81,7 @@ class RegisterValidatorKtTest { fun registered_validator_returns__ValidationResult_Valid__when_value_is_valid() = runBlocking { val validate = Validator { constrain { true } } config.registerValidator(validate) - val result = lambdaSlot.captured(value) + val result = validatorSlot.captured.validate(value) assertSame(ValidationResult.Valid, result) } @@ -88,7 +89,7 @@ class RegisterValidatorKtTest { fun registered_validator_throws__ValidationResult_Exception__when_value_is_invalid(): Unit = runBlocking { val validate = Validator { constrain { false } } config.registerValidator(validate) - val exception = assertFails { lambdaSlot.captured(value) } + val exception = assertFails { validatorSlot.captured.validate(value) } assertIs(exception) } //endregion @@ -98,7 +99,7 @@ class RegisterValidatorKtTest { fun registered_async_contextual_validator_uses_the_provided_context_and_value() = runBlocking { val validate = Validator.suspendable { ctx -> constrain { ctx === context && it === value } } config.registerValidator(validate) { context } - val result = lambdaSlot.captured(value) + val result = validatorSlot.captured.validate(value) assertSame(ValidationResult.Valid, result) } @@ -106,7 +107,7 @@ class RegisterValidatorKtTest { fun registered_async_contextual_validator_returns__ValidationResult_Valid__when_value_is_valid() = runBlocking { val validate = Validator.suspendable { constrain { true } } config.registerValidator(validate) { context } - val result = lambdaSlot.captured(value) + val result = validatorSlot.captured.validate(value) assertSame(ValidationResult.Valid, result) } @@ -114,7 +115,7 @@ class RegisterValidatorKtTest { fun registered_async_contextual_validator_throws__ValidationResult_Exception__when_value_is_invalid(): Unit = runBlocking { val validate = Validator.suspendable { constrain { false } } config.registerValidator(validate) { context } - val exception = assertFails { lambdaSlot.captured(value) } + val exception = assertFails { validatorSlot.captured.validate(value) } assertIs(exception) } //endregion @@ -124,7 +125,7 @@ class RegisterValidatorKtTest { fun registered_async_validator_uses_the_provided_value() = runBlocking { val validate = Validator.suspendable { constrain { it === value } } config.registerValidator(validate) - val result = lambdaSlot.captured(value) + val result = validatorSlot.captured.validate(value) assertSame(ValidationResult.Valid, result) } @@ -132,7 +133,7 @@ class RegisterValidatorKtTest { fun registered_async_validator_returns__ValidationResult_Valid__when_value_is_valid() = runBlocking { val validate = Validator.suspendable { constrain { true } } config.registerValidator(validate) - val result = lambdaSlot.captured(value) + val result = validatorSlot.captured.validate(value) assertSame(ValidationResult.Valid, result) } @@ -140,7 +141,7 @@ class RegisterValidatorKtTest { fun registered_async_validator_throws__ValidationResult_Exception__when_value_is_invalid(): Unit = runBlocking { val validate = Validator.suspendable { constrain { false } } config.registerValidator(validate) - val exception = assertFails { lambdaSlot.captured(value) } + val exception = assertFails { validatorSlot.captured.validate(value) } assertIs(exception) } //endregion diff --git a/settings.gradle.kts b/settings.gradle.kts index 59b10d7..e4de270 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -20,7 +20,7 @@ include( dependencyResolutionManagement { versionCatalogs { create("libs") { - version("ktor", "2.3.12") + version("ktor", "3.0.0") version("kotlinx-serialization", "1.7.3") plugin("kotlinx-serialization", "org.jetbrains.kotlin.plugin.serialization").version("2.0.20")