jdiazcano / cfg4k

Flexible and easy to use config library written in kotlin
Apache License 2.0
80 stars 6 forks source link

Remake tests #59

Closed jdiazcano closed 5 years ago

jdiazcano commented 5 years ago

Basically using Spek1 has been pretty hard since the start so finally let's get rid of it once and for all.

The substitutor would be Kotlintest as it seems to be pretty good.

With the rewrite of all the tests, no code should change, and everything would be a port but also rethinking how they are organized as right now they are definitely not sorted. Also right now there is the code coverage that didn't really seem useful and with that it'll be possible to migrate to .kts and also to a beter kts version of the buildSrc with a git submodule (it should be possible)

jdiazcano commented 5 years ago

As an example, one of the tests that I did yesterday for the environment config loader:

class EnvironmentConfigLoaderTest: StringSpec() {

    override fun beforeSpec(spec: Spec) {
        mockkStatic(System::class)
        every { System.getenv() } returns mapOf(
                "PROPERTIES_GROUPONE_KEYONE" to "1",
                "PROPERTIES_GROUPONE_KEYTWO" to "2"
        )
    }

    override fun afterSpec(spec: Spec) {
        unmockkAll()
    }

    init {
        val loader = EnvironmentConfigLoader()
        val provider = ProxyConfigProvider(loader)

        "it should be good in the loader" {
            loader.get("properties.groupone.keyone").should.be.equal("1".toConfig())
        }

        "should be also good with the provider" {
            provider.get<String>("properties.groupone.keyone").should.be.equal("1")
        }

        "works with binding" {
            val properties = provider.bind<Props>("properties")
            properties.groupone.keyone.should.be.equal("1")
            properties.groupone.keytwo.should.be.equal("2")
        }
    }
}
jdiazcano commented 5 years ago

Done!