gpt4 book ai didi

scala - 喷雾测试 gzip 解码

转载 作者:行者123 更新时间:2023-12-05 01:01:44 28 4
gpt4 key购买 nike

我尝试为喷雾写测试

class FullTestKitExampleSpec extends Specification with Specs2RouteTest with UserController with HttpService {
def actorRefFactory = system

"The service" should {

"return a greeting for GET requests to the root path" in {
Get("/user") ~> `Accept-Encoding`(gzip) ~> userRoute ~> check {
val responsex = response
responseAs[String] must contain("Test1")
}
}
}
}

我有关注路由器
trait UserController extends HttpService with Json4sSupport with CORSSupport{
override implicit def json4sFormats: Formats = DefaultFormats

val userRoute = {
cors {
compressResponse(Gzip) {
path("user") {
get {
complete {
"Test1"
}
} ~
post {
entity(as[UserRegister]) { person =>
complete {
println(person.name)
person.name
}
}
}
}
}
}
}
}

我使用 GZIP 压缩进行响应,但是

Could not unmarshal response to type 'java.lang.String' for responseAs assertion: MalformedContent(unknown token Near: ,Some(org.json4s.ParserUtil$ParseException: unknown token Near: ))



如何将自动解码 GZIP HttpResponse 设置为字符串?

最佳答案

包括 decode(Gzip)在您的管道中:

import spray.httpx.encoding.Gzip
import spray.httpx.ResponseTransformation

class MySprayRouteSpec extends FlatSpec
with ShouldMatchers
with ResponseTransformation
with ScalatestRouteTest
{
Get("/") ~> mapHttpResponse(decode(Gzip))(userRoute) ~> check{
response.status should equal(OK)
}
}

关于scala - 喷雾测试 gzip 解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27794570/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com