From 29b5c39d9b5f2a78d8c6c94c77c1d1cfcb642dc0 Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Wed, 8 Jan 2025 15:43:29 +0100 Subject: [PATCH] Disable testGzipWithContentLengthWithoutPlugin for non-JVM clients (#4583) * Use EnginePattern for both for except and only --- .../ktor/client/tests/utils/ClientLoader.kt | 30 +++++++++---------- .../tests/ContentEncodingIntegrationTest.kt | 11 ++++--- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/ktor-client/ktor-client-tests/common/src/io/ktor/client/tests/utils/ClientLoader.kt b/ktor-client/ktor-client-tests/common/src/io/ktor/client/tests/utils/ClientLoader.kt index 6b65b51eaa..7a099f6fb5 100644 --- a/ktor-client/ktor-client-tests/common/src/io/ktor/client/tests/utils/ClientLoader.kt +++ b/ktor-client/ktor-client-tests/common/src/io/ktor/client/tests/utils/ClientLoader.kt @@ -1,5 +1,5 @@ /* - * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ package io.ktor.client.tests.utils @@ -79,8 +79,8 @@ abstract class ClientLoader(private val timeout: Duration = 1.minutes) { /** Defines that test should be executed only with the specified [engine]. */ fun only(engine: String): EngineSelectionRule { - val lowercaseEngineName = engine.lowercase() - return EngineSelectionRule { it.lowercase() == lowercaseEngineName } + val pattern = EnginePattern.parse(engine) + return EngineSelectionRule { pattern.matches(it) } } /** Excludes the specified [engines] from test execution. */ @@ -88,7 +88,7 @@ abstract class ClientLoader(private val timeout: Duration = 1.minutes) { /** Excludes the specified [engines] from test execution. */ fun except(engines: List): EngineSelectionRule { - val skipPatterns = engines.map(SkipEnginePattern::parse) + val skipPatterns = engines.map(EnginePattern::parse) return EngineSelectionRule { engineName -> skipPatterns.none { it.matches(engineName) } } } @@ -176,23 +176,23 @@ fun interface EngineSelectionRule { fun shouldRun(engineName: String): Boolean } -private data class SkipEnginePattern( - val skippedPlatform: String?, // null means * or empty - val skippedEngine: String?, // null means * or empty +private data class EnginePattern( + val matchingPlatform: String?, // null means * or empty + val matchingEngine: String?, // null means * or empty ) { fun matches(engineName: String): Boolean { var result = true - if (skippedEngine != null) { - result = result && engineName.lowercase() == skippedEngine + if (matchingEngine != null) { + result = result && engineName.lowercase() == matchingEngine } - if (result && skippedPlatform != null) { - result = result && platformName.startsWith(skippedPlatform) + if (result && matchingPlatform != null) { + result = result && platformName.startsWith(matchingPlatform) } return result } companion object { - fun parse(pattern: String): SkipEnginePattern { + fun parse(pattern: String): EnginePattern { val parts = pattern.lowercase().split(":").map { it.takeIf { it != "*" } } val platform: String? val engine: String? @@ -207,13 +207,13 @@ private data class SkipEnginePattern( engine = parts[1] } - else -> error("Skip engine pattern should consist of two parts: PLATFORM:ENGINE or ENGINE") + else -> error("Engine pattern should consist of two parts: PLATFORM:ENGINE or ENGINE") } if (platform == null && engine == null) { - error("Skip engine pattern should consist of two parts: PLATFORM:ENGINE or ENGINE") + error("Engine pattern should consist of two parts: PLATFORM:ENGINE or ENGINE") } - return SkipEnginePattern(platform, engine) + return EnginePattern(platform, engine) } } } diff --git a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentEncodingIntegrationTest.kt b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentEncodingIntegrationTest.kt index 74d4508735..0c3cc9372d 100644 --- a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentEncodingIntegrationTest.kt +++ b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentEncodingIntegrationTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ package io.ktor.client.tests @@ -18,16 +18,15 @@ private const val TEST_URL = "$TEST_SERVER/compression" class ContentEncodingIntegrationTest : ClientLoader() { + // GZipEncoder is implemented only on JVM. @Test - fun testGzipWithContentLengthWithoutPlugin() = clientTests { + fun testGzipWithContentLengthWithoutPlugin() = clientTests(only("jvm:*")) { test { client -> val response = client.get("$TEST_URL/gzip-with-content-length") - val byteContent = response.bodyAsBytes() - val content = if (response.headers[HttpHeaders.ContentEncoding] == "gzip") { - GZipEncoder.decode(ByteReadChannel(byteContent)).readRemaining().readString() + GZipEncoder.decode(response.bodyAsChannel()).readRemaining().readString() } else { - byteContent.decodeToString() + response.bodyAsText() } assertEquals("Hello, world", content)