pl.allegro.tech.servicemesh.envoycontrol.config.envoy.ResponseWithBody.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of envoy-control-tests Show documentation
Show all versions of envoy-control-tests Show documentation
Production-ready Control Plane for Service Mesh based on Envoy Proxy.
package pl.allegro.tech.servicemesh.envoycontrol.config.envoy
import com.fasterxml.jackson.databind.ObjectMapper
import okhttp3.Response
import pl.allegro.tech.servicemesh.envoycontrol.config.service.EchoContainer
data class ResponseWithBody(val response: Response) {
companion object {
private val objectMapper by lazy { ObjectMapper() }
}
val body = response.body?.string() ?: ""
fun isFrom(echoContainer: EchoContainer) = body.contains(echoContainer.response)
fun isOk() = response.isSuccessful
fun bodyJsonField(field: String) = objectMapper.readTree(body).at(field)
}