almeydajuan
07/04/2024, 12:14 PMResponse
object, as defined by this interface: Approver.kt.
However, upon delving deeper into the code, I noticed some extension functions that aren't part of the interface but allow for direct content approval: Approver.assertApproved.
This discovery enabled me to streamline my code from:
kotlin
@ExtendWith(YamlApprovalTest::class)
interface YamlMetadataConfigTest {
val config: YamlConfig
@Test
fun `generate metadata`(approver: Approver) {
approver.assertYamlApproved(YamlBuilder.fromConfig(config))
}
}
fun Approver.assertYamlApproved(input: String) = Response(OK)
.body(input)
.contentType(APPLICATION_YAML)
.let(::assertApproved)
To a more concise version:
kotlin
import org.http4k.testing.assertApproved
@ExtendWith(YamlApprovalTest::class)
interface YamlMetadataConfigTest {
val config: YamlConfig
@Test
fun `generate metadata`(approver: Approver) {
approver.assertApproved(YamlBuilder.fromConfig(config), APPLICATION_YAML)
}
}
By simply importing the correct function import org.http4k.testing.assertApproved
.
I've checked the example repositories:
- http4k examples
- http4k by example
but found no examples demonstrating this functionality.
Given its utility, I believe this feature deserves more visibility. What are your thoughts on this? If it's welcome, I'd be happy to contribute towards enhancing its documentation or examples.Andrew O'Hara
07/04/2024, 2:21 PM