Skip to content

Commit

Permalink
Disable testGzipWithContentLengthWithoutPlugin for non-JVM clients (#…
Browse files Browse the repository at this point in the history
…4583)

* Use EnginePattern for both for except and only
  • Loading branch information
osipxd authored Jan 8, 2025
1 parent 7a3736b commit 29b5c39
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -79,16 +79,16 @@ 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. */
fun except(vararg engines: String): EngineSelectionRule = except(engines.asList())

/** Excludes the specified [engines] from test execution. */
fun except(engines: List<String>): EngineSelectionRule {
val skipPatterns = engines.map(SkipEnginePattern::parse)
val skipPatterns = engines.map(EnginePattern::parse)
return EngineSelectionRule { engineName -> skipPatterns.none { it.matches(engineName) } }
}

Expand Down Expand Up @@ -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?
Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 29b5c39

Please sign in to comment.