senia-psm / zio-test-akka-http

Akka-HTTP Route TestKit for zio-test
7 stars 3 forks source link

1.0.15: `EagerCompleted` is missing headers / `Content-Type` header #159

Closed domdorn closed 2 years ago

domdorn commented 2 years ago

When migrating my tests from version 1.0.3 to 1.0.15 I've experienced the following behavior: The following code fails cause no headers or at least not the Content-Type header get populated in the Completed / EagerCompleted:

 def getNextCalcIdWithAssertions(r: RouteTestResult): ZIO[Any, Serializable, (Some[(JobId, CalcId)], Assert)] = for {
    v <- ZIO.fromOption(r.handled)
    statusCheck = assertTrue(v.status == StatusCodes.OK)
    _ <- ZIO.debug(v.headers)
    contentTypeCheck = assertTrue(v.header("Content-Type").get.value() == "application/json") // <- this fails
    completed = v.asInstanceOf[EagerCompleted]
    response <- ZIO.fromEither(completed.responseAs[GetNextCalcController.Response])
    ...

I haven't tested if other headers are also missing, but at least the Content-Type header is missing.

grafik

I found a workaround: directly use the contentType property on EagerCompleted. However, this breaks some existing user tests (at least in my codebase) and is unexpected behavior.

senia-psm commented 2 years ago

@domdorn this is consistent with akka-http-testkit:

Get() ~> smallRoute ~> check {
  contentType shouldEqual ContentTypes.`text/plain(UTF-8)`
  headers shouldEqual Seq()
}

With this behaviour you can check that content type is not specified manually by directives, but instead inferred from entity. headers is only for headers provided by directives.

I'd prefer to keep behaviour aligned to akka-http-testkit.

domdorn commented 2 years ago

thanks for clarifying. will update my tests accordingly (we've used the contentType matcher before)