Antonio Acuña Prieto
03/12/2024, 8:43 PMTestApplication {
environment {
config = ApplicationConfig("application.conf")
}
}
Modules defined in application.conf
load fine, but when I try to override any parameter of the configuration using:
TestApplication {
environment {
config = ApplicationConfig("application.conf").mergeWith(
MapApplicationConfig(
"database.host" to "whatever",
)
)
}
}
Then the modules are loaded two times. Version 3.0.0-beta-1Aleksei Tirman [JB]
03/13/2024, 8:11 AM@Test
fun test() = testApplication {
environment {
config = ApplicationConfig("application.conf").mergeWith(
MapApplicationConfig(
"database.host" to "whatever",
)
)
}
client.get("/")
}
application.conf:
ktor {
deployment {
port = 9090
}
application {
modules = [ EngineMainKt.main ]
}
}
database {
host = localhost
}
EngineMain.kt:
fun Application.main() {
println(environment.config.property("database.host").getString())
}
Antonio Acuña Prieto
03/13/2024, 9:53 AMAntonio Acuña Prieto
03/13/2024, 8:21 PMobject Ktor3App {
suspend fun beforeSpec() {
httpClient.get("/")
}
fun afterSpec() {}
fun beforeTest() {}
fun afterTest() {}
val inMemorySpanExporter: InMemorySpanExporter
val app: TestApplication
val httpClient: HttpClient
init {
inMemorySpanExporter = InMemorySpanExporter.create()
app = TestApplication {
environment {
config = ApplicationConfig("src/test/resources/application-test.conf")
}
}
httpClient = app.createClient { }
}
}
Now I know that the testApplication server will start when the first request is made, but I need to start the server after that happens so my solution is doing a get request after the tests run.
If I replace this request in beforeSpec()
with app.start()
it will load the modules there and then it will load then on the first client http request.
Is this correct? I think it should check if the app is running, server started and modules loaded to not load them again on the first request but no strong opinion, hopefully there is a cleaner way to do it.Aleksei Tirman [JB]
03/14/2024, 7:32 AMTestApplication
then you don't need to use the testApplication
function.Antonio Acuña Prieto
03/14/2024, 2:33 PM