From 4651ba613917eaa005206acc39b3c49edb3791f1 Mon Sep 17 00:00:00 2001 From: Ash Davies <1892070+ashdavies@users.noreply.github.com> Date: Mon, 29 Apr 2024 00:53:24 +0200 Subject: [PATCH] fix/integration test dependency (#957) * Specify fasterxml jackson core version for Google cloud bom libraries * Include rationale * Adjust comment format --- cloud-run/build.gradle.kts | 8 +++++ .../kotlin/io/ashdavies/cloud/JsonProperty.kt | 7 ----- .../kotlin/io/ashdavies/cloud/Main.kt | 2 +- .../kotlin/io/ashdavies/cloud/Validator.kt | 30 +++++++++++++++++++ gradle/libs.versions.toml | 1 + 5 files changed, 40 insertions(+), 8 deletions(-) delete mode 100644 cloud-run/src/commonMain/kotlin/io/ashdavies/cloud/JsonProperty.kt create mode 100644 cloud-run/src/commonMain/kotlin/io/ashdavies/cloud/Validator.kt diff --git a/cloud-run/build.gradle.kts b/cloud-run/build.gradle.kts index 1937cf626..0dc17cf22 100644 --- a/cloud-run/build.gradle.kts +++ b/cloud-run/build.gradle.kts @@ -90,6 +90,14 @@ kotlin { implementation(libs.ktor.server.test.host) } + jvmMain.dependencies { + compileOnly(libs.fasterxml.jackson.core)?.because( + "runtimeClasspath configuration transitively depends upon jackson-databind" + + " 2.17.0, but 2.14.2 is required by compileClasspath dependencies, this " + + "causes exceptions due to missing method errors at runtime.", + ) + } + val jvmIntegrationTest by getting { dependencies { implementation(kotlin("test-junit")) diff --git a/cloud-run/src/commonMain/kotlin/io/ashdavies/cloud/JsonProperty.kt b/cloud-run/src/commonMain/kotlin/io/ashdavies/cloud/JsonProperty.kt deleted file mode 100644 index c5f74fe79..000000000 --- a/cloud-run/src/commonMain/kotlin/io/ashdavies/cloud/JsonProperty.kt +++ /dev/null @@ -1,7 +0,0 @@ -@file:Suppress("PackageDirectoryMismatch") - -package com.fasterxml.jackson.annotation - -import kotlinx.serialization.SerialName - -internal typealias JsonProperty = SerialName diff --git a/cloud-run/src/commonMain/kotlin/io/ashdavies/cloud/Main.kt b/cloud-run/src/commonMain/kotlin/io/ashdavies/cloud/Main.kt index 812462c67..ce043cd49 100644 --- a/cloud-run/src/commonMain/kotlin/io/ashdavies/cloud/Main.kt +++ b/cloud-run/src/commonMain/kotlin/io/ashdavies/cloud/Main.kt @@ -28,7 +28,7 @@ public fun main() { server.start(wait = true) } -internal fun Application.main(client: HttpClient = defaultHttpClient()) { +internal fun Application.main(client: HttpClient = defaultHttpClient { installCallValidator() }) { install(DefaultHeaders, DefaultHeadersConfig::headers) install(Compression, CompressionConfig::default) install(ContentNegotiation, Configuration::json) diff --git a/cloud-run/src/commonMain/kotlin/io/ashdavies/cloud/Validator.kt b/cloud-run/src/commonMain/kotlin/io/ashdavies/cloud/Validator.kt new file mode 100644 index 000000000..bb485fd84 --- /dev/null +++ b/cloud-run/src/commonMain/kotlin/io/ashdavies/cloud/Validator.kt @@ -0,0 +1,30 @@ +package io.ashdavies.cloud + +import io.ktor.client.HttpClientConfig +import io.ktor.client.call.body +import io.ktor.client.plugins.ClientRequestException +import io.ktor.client.plugins.HttpCallValidator +import kotlinx.serialization.Serializable + +internal fun HttpClientConfig<*>.installCallValidator() { + install(HttpCallValidator) { + handleResponseExceptionWithRequest { exception, _ -> + if (exception is ClientRequestException) { + throw exception.response.body() + } + } + } + + expectSuccess = true +} + +@Serializable +internal data class GoogleApisException(val error: Error) : Exception(error.message) { + + @Serializable + data class Error( + val code: Int, + val message: String, + val status: String, + ) +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 209e25ede..35bf66e45 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,6 +43,7 @@ coil-network = { module = "io.coil-kt.coil3:coil-network-ktor", version.ref = "c compose-compiler = { module = "org.jetbrains.compose.compiler:compiler", version.ref = "compose-compiler" } compose-runtime = { module = "org.jetbrains.compose.runtime:runtime", version.ref = "jetbrains-compose" } +fasterxml-jackson-core = "com.fasterxml.jackson.core:jackson-core:2.17.0" fusesource-jansi = "org.fusesource.jansi:jansi:2.4.1" gitlive-firebase-app = { module = "dev.gitlive:firebase-app", version.ref = "gitlive-firebase" }