pl.allegro.tech.servicemesh.envoycontrol.assertions.ResponseAssertions.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.assertions
import okhttp3.Response
import org.assertj.core.api.ObjectAssert
import pl.allegro.tech.servicemesh.envoycontrol.config.service.EchoServiceExtension
fun ObjectAssert.isOk(): ObjectAssert {
matches { it.isSuccessful }
return this
}
fun ObjectAssert.isForbidden(): ObjectAssert {
matches({
it.body?.close()
it.code == 403
}, "is forbidden")
return this
}
fun ObjectAssert.isUnreachable(): ObjectAssert {
matches({
it.body?.close()
it.code == 503 || it.code == 504
}, "is unreachable")
return this
}
fun ObjectAssert.isFrom(echoServiceExtension: EchoServiceExtension): ObjectAssert {
matches {
it.body?.use { it.string().contains(echoServiceExtension.container().response) } ?: false
}
return this
}
fun ObjectAssert.isEitherFrom(vararg echoContainers: EchoServiceExtension): ObjectAssert {
matches {
val serviceResponse = it.body?.string() ?: ""
echoContainers.any { containerExtension -> serviceResponse.contains(containerExtension.container().response) }
}
return this
}