2

versions:

  • http4s: 0.18.1
  • specs2: 4.0.0

I'm using http4s and writing unit test for routers, but there are little documents about headers assertion.

When code below is executed, it can be compiled, but fails.

code:

import cats.effect.IO
import org.http4s._
import org.http4s.dsl.io._
import org.http4s.headers._
import org.http4s.testing.Http4sMatchers
import org.specs2.mutable.Specification

class RedirectSpec extends Specification with Http4sMatchers {
  "testing" >> {
    val response: IO[Response[IO]] = Found(Location(Uri.unsafeFromString("")))
    response must returnStatus(Found)
    response must returnValue(
      haveHeaders(
        Headers(
          `Content-Length`.zero,
          Location(Uri.unsafeFromString(""))
        )
      )
    )
  }
}

output:

$  sbt "testOnly RedirectSpec"
...
[info] RedirectSpec
[error] x testing
[error]  the headers 'Headers(Content-Length: 0, Location: )' is not the same as Headers(Content-Length: 0, Location: ) (RedirectSpec.scala:13)
[info] Total for specification RedirectSpec
[info] Finished in 655 ms
[info] 1 example, 1 failure, 0 error
[error] Failed: Total 1, Failed 1, Errors 0, Passed 0
[error] Failed tests:
[error]         RedirectSpec
[error] (test:testOnly) sbt.TestsFailedException: Tests unsuccessful

What is difference between actual and expected value? If it's wrong, please tell me how to make assertion about headers.

4

1 回答 1

1

这几乎可以肯定是一个错误,因为Http4s 自己的一个测试做了类似的事情,当我运行它并Http4sMatchers出现类似错误时失败。我报告了一个错误

于 2018-09-20T06:36:57.450 回答