https://kotlinlang.org logo
#koin
Title
# koin
m

Mark Malik

06/15/2022, 8:58 AM
The test as simple as this:
Copy code
"Not allow logging in with incorrect api key" {
                // given
                val payload = JsonObject(
                    mapOf(
                        "apikey" to JsonPrimitive("wrong"),
                        "username" to JsonPrimitive("jamma"),
                    )
                )
                // when
                testApplication {
                    application { Application::testModule }
                    environment {
                        config = ApplicationConfig("test-application.conf")
                    }
                    val client = createClient { install(ContentNegotiation) { json() } }

                    val response = <http://client.post|client.post>("api/login") {
                        contentType(ContentType.Application.Json)
                        setBody(payload)
                    }

                    // then
                    response shouldHaveStatus HttpStatusCode.Unauthorized
                }
            }
I’m using KoinExtensions to inject the dependencies.
Copy code
override fun extensions(): List<Extension> =
        listOf(KoinExtension(listOf(testDbModule, testHttpModule, RepositoryModule)))
a

arnaud.giuliani

06/20/2022, 12:58 PM
nothing on Koin in your stack? can you check in pure Ktor sample?
m

Mark Malik

06/20/2022, 2:19 PM
I will push something later today.
I have the Koin Ktor project with modules firing on Application setup
The tests ComplexDIRoutingTest and ComplexDIRoutingWithoutKoinTest display the issue I’m having. A different problem, that I have, that I try to resolve is the fact that I’m not able to override the default module in tests, I need to konfigure Koin separatly with the final (test) module implementations.
a

arnaud.giuliani

06/22/2022, 8:59 AM
Interesting, did you linked all your resources in the issue?
m

Mark Malik

06/22/2022, 9:03 AM
yes.
the problem i;m getting is that there is a Casting issue when trying to inject that depencency
@arnaud.giuliani do you have any ideas why my getting this issue ?
2 Views