-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[Junie]: feat: make client property in ApplicationTestBuilder mutable #4879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b4df5c8
15a8556
7dc6f4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,49 @@ | ||||||||||||||||
/* | ||||||||||||||||
* 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.tests.server.testing | ||||||||||||||||
|
||||||||||||||||
import io.ktor.client.* | ||||||||||||||||
import io.ktor.client.request.* | ||||||||||||||||
import io.ktor.client.statement.* | ||||||||||||||||
import io.ktor.http.* | ||||||||||||||||
import io.ktor.server.application.* | ||||||||||||||||
import io.ktor.server.response.* | ||||||||||||||||
import io.ktor.server.routing.* | ||||||||||||||||
import io.ktor.server.testing.* | ||||||||||||||||
import kotlin.test.Test | ||||||||||||||||
import kotlin.test.assertEquals | ||||||||||||||||
import kotlin.test.assertNotSame | ||||||||||||||||
|
||||||||||||||||
class ClientConfigurationTest { | ||||||||||||||||
|
||||||||||||||||
@Test | ||||||||||||||||
fun testClientConfiguration() = testApplication { | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jetbrains-junie fix it |
||||||||||||||||
// Set up a simple route | ||||||||||||||||
application { | ||||||||||||||||
routing { | ||||||||||||||||
get("/hello") { | ||||||||||||||||
call.respondText("Hello, World!") | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// Store the original client | ||||||||||||||||
val originalClient = client | ||||||||||||||||
|
||||||||||||||||
// Create a new client | ||||||||||||||||
val configuredClient = createClient { } | ||||||||||||||||
|
||||||||||||||||
// Set the new client as the default | ||||||||||||||||
client = configuredClient | ||||||||||||||||
Comment on lines
+35
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's simplify this
Suggested change
|
||||||||||||||||
|
||||||||||||||||
// Verify that the client has been changed | ||||||||||||||||
assertNotSame(originalClient, client) | ||||||||||||||||
|
||||||||||||||||
// Test the configured client | ||||||||||||||||
val response = client.get("/hello") | ||||||||||||||||
assertEquals(HttpStatusCode.OK, response.status) | ||||||||||||||||
assertEquals("Hello, World!", response.bodyAsText()) | ||||||||||||||||
} | ||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep
val
here, but make itvar
inTestApplicationBuilder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jetbrains-junie fix it