org.http4k.testing.ApprovalTransformer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http4k-testing-approval Show documentation
Show all versions of http4k-testing-approval Show documentation
Http4k support for Approval Testing
package org.http4k.testing
import java.io.InputStream
/**
* Convert the output into a Comparable form.
*/
fun interface ApprovalTransformer : (InputStream) -> T {
companion object {
/**
* Use this for HTTP bodies which are strings with normalised line endings.
*/
fun StringWithNormalisedLineEndings(): ApprovalTransformer {
val matchAllLineEndings = "\\r\\n?".toRegex()
fun String.normalizeLineEndings() = replace(matchAllLineEndings, "\n")
return ApprovalTransformer {
it.reader().use { it.readText().normalizeLineEndings().trimEnd() }
}
}
}
}