hi everyone, so I’ve been struggling with somethin...
# ktor
a
hi everyone, so I’ve been struggling with something for several hours, I can’t find a working (clean) solution. I’m using configuration in a file, with several modules loaded by default in production. I wanted to create application tests and well, I can’t find a way to pass the HTTP client (used to mock external services) when using config as file compared to this example: https://github.com/ktorio/ktor-documentation/blob/3.0.3/codeSnippets/snippets/auth-oauth-google/src/test/kotlin/ApplicationTest.kt where in the tests, they simply declare the said modules manually. Of course, this would be the simplest solution, but I’d like to write the tests based on the very same configuration used in production (with some small overrides of course but at least the same modules and plugins…etc which are defined in the module functions code). The inner issue is that I made a specific plugin, which configures ready to use API clients to call external APIs of our company. And in the tests I’d like to pass the “fake” client instead to avoid calling the said APIs. But I can’t pass it in parameter if I use configuration in a file 🙃 How would you do it ? Bonus: I’d also like to “leave the possibility” to define modules to test manually because all of this is part of some common skeleton for tests destined to be used by the feature teams I work with, and I’d like to hide all this config logic from them not because I don’t trust, but just because they don’t have to know how it is configured, they just want it to work. I like the “plug’n’play” approach (sorry, this may be my background with Spring speaking 😅)
a
The best thing you can do is to test the module function, which requires the HTTP client, separately from the entry module used in production. Unfortunately, it's impossible to pass arguments for a module listed in the configuration file.