Skip to content

Commit

Permalink
Verify string can be sent with json feature
Browse files Browse the repository at this point in the history
	Close #1265
  • Loading branch information
e5l committed Jun 29, 2020
1 parent 4e7d395 commit 587da84
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Copyright 2014-2019 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("NO_EXPLICIT_RETURN_TYPE_IN_API_MODE_WARNING")

package io.ktor.client.tests.utils

import io.ktor.client.*
Expand All @@ -12,16 +14,24 @@ import io.ktor.utils.io.core.*
import kotlinx.coroutines.*

/**
* Local test server url.
* Web url for tests.
*/
public const val TEST_SERVER: String = "http://127.0.0.1:8080"

/**
* Websocket server url for tests.
*/
public const val TEST_WEBSOCKET_SERVER: String = "ws://127.0.0.1:8080"

/**
* Proxy server url for tests.
*/
const val TEST_SERVER: String = "http://127.0.0.1:8080"
const val TEST_WEBSOCKET_SERVER: String = "ws://127.0.0.1:8080"
const val HTTP_PROXY_SERVER: String = "http://127.0.0.1:8082"
public const val HTTP_PROXY_SERVER: String = "http://127.0.0.1:8082"

/**
* Perform test with selected client [engine].
*/
fun testWithEngine(
public fun testWithEngine(
engine: HttpClientEngine,
block: suspend TestClientBuilder<*>.() -> Unit
) = testWithClient(HttpClient(engine), block)
Expand All @@ -47,7 +57,7 @@ private fun testWithClient(
/**
* Perform test with selected client engine [factory].
*/
fun <T : HttpClientEngineConfig> testWithEngine(
public fun <T : HttpClientEngineConfig> testWithEngine(
factory: HttpClientEngineFactory<T>,
loader: ClientLoader? = null,
block: suspend TestClientBuilder<T>.() -> Unit
Expand Down Expand Up @@ -81,21 +91,21 @@ fun <T : HttpClientEngineConfig> testWithEngine(

@InternalAPI
@Suppress("KDocMissingDocumentation")
class TestClientBuilder<T : HttpClientEngineConfig>(
var config: HttpClientConfig<T>.() -> Unit = {},
var test: suspend (client: HttpClient) -> Unit = {},
var repeatCount: Int = 1,
public class TestClientBuilder<T : HttpClientEngineConfig>(
public var config: HttpClientConfig<T>.() -> Unit = {},
public var test: suspend (client: HttpClient) -> Unit = {},
public var repeatCount: Int = 1,
var dumpAfterDelay: Long = -1
)

@InternalAPI
@Suppress("KDocMissingDocumentation")
fun <T : HttpClientEngineConfig> TestClientBuilder<T>.config(block: HttpClientConfig<T>.() -> Unit): Unit {
public fun <T : HttpClientEngineConfig> TestClientBuilder<T>.config(block: HttpClientConfig<T>.() -> Unit) {
config = block
}

@InternalAPI
@Suppress("KDocMissingDocumentation")
fun TestClientBuilder<*>.test(block: suspend (client: HttpClient) -> Unit): Unit {
public fun TestClientBuilder<*>.test(block: suspend (client: HttpClient) -> Unit) {
test = block
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,21 @@ class SerializationTest : ClientLoader() {
}
}
}

@Test
fun testSendStringWithSerialization() = clientTests {
config {
install(JsonFeature)
}

test { client ->
assertFailsWith<ClientRequestException> {
client.post {
url("https://google.com")
header(HttpHeaders.ContentType, ContentType.Application.Json)
body = "Hello, world"
}
}
}
}
}

0 comments on commit 587da84

Please sign in to comment.