66
77package io.ktor.tests.hosts
88
9- import com.typesafe.config.*
9+ import com.typesafe.config.ConfigFactory
1010import io.ktor.client.request.*
1111import io.ktor.events.*
1212import io.ktor.server.application.*
@@ -15,11 +15,16 @@ import io.ktor.server.engine.*
1515import io.ktor.server.response.*
1616import io.ktor.server.routing.*
1717import io.ktor.server.testing.*
18+ import io.ktor.tests.hosts.EmbeddedServerReloadingTests.Companion.addLoadedModule
1819import io.ktor.util.*
19- import kotlinx.coroutines.*
20- import org.slf4j.helpers.*
21- import kotlin.reflect.*
22- import kotlin.reflect.jvm.*
20+ import kotlinx.coroutines.Job
21+ import kotlinx.coroutines.runBlocking
22+ import org.slf4j.helpers.NOPLogger
23+ import kotlin.reflect.KClass
24+ import kotlin.reflect.KFunction
25+ import kotlin.reflect.KFunction0
26+ import kotlin.reflect.jvm.javaMethod
27+ import kotlin.reflect.jvm.jvmName
2328import kotlin.test.*
2429
2530class EmbeddedServerReloadingTests {
@@ -391,7 +396,8 @@ class EmbeddedServerReloadingTests {
391396 mapOf (
392397 " ktor.deployment.environment" to " test" ,
393398 " ktor.application.modules" to listOf (
394- EmbeddedServerReloadingTests ::class .jvmName + " Kt.topLevelWithDefaultArg"
399+ Application ::defaultArgBoolean.fqName,
400+ Application ::defaultArgContainingApplicationWord.fqName,
395401 )
396402 )
397403 )
@@ -405,7 +411,13 @@ class EmbeddedServerReloadingTests {
405411 server.start()
406412 val application = server.application
407413 assertNotNull(application)
408- assertEquals(" topLevelWithDefaultArg" , application.attributes[TestKey ])
414+ assertEquals(
415+ setOf (
416+ " defaultArgBoolean" ,
417+ " defaultArgContainingApplicationWord" ,
418+ ),
419+ application.loadedModules,
420+ )
409421 server.stop()
410422 }
411423
@@ -512,6 +524,14 @@ class EmbeddedServerReloadingTests {
512524 companion object {
513525 val TestKey = AttributeKey <String >(" test-key" )
514526 val TestKey2 = AttributeKey <String >(" test-key2" )
527+ private val LoadedModulesKey = AttributeKey <MutableSet <String >>(" loaded-modules" )
528+
529+ val Application .loadedModules: Set <String >
530+ get() = attributes.getOrNull(LoadedModulesKey ).orEmpty()
531+
532+ fun Application.addLoadedModule (name : String ) {
533+ attributes.computeIfAbsent(LoadedModulesKey ) { mutableSetOf () }.add(name)
534+ }
515535
516536 private val KFunction <* >.fqName: String
517537 get() = javaMethod!! .declaringClass.name + " ." + name
@@ -652,8 +672,12 @@ fun topLevelFunction() {
652672 error(" Shouldn't be invoked" )
653673}
654674
655- fun Application.topLevelWithDefaultArg (testing : Boolean = false) {
656- attributes.put(EmbeddedServerReloadingTests .TestKey , " topLevelWithDefaultArg" )
675+ fun Application.defaultArgBoolean (testing : Boolean = false) {
676+ addLoadedModule(" defaultArgBoolean" )
677+ }
678+
679+ fun Application.defaultArgContainingApplicationWord (configure : Application .() -> Unit = {}) {
680+ addLoadedModule(" defaultArgContainingApplicationWord" )
657681}
658682
659683@JvmOverloads
0 commit comments