zio / zio-http

A next-generation Scala framework for building scalable, correct, and efficient HTTP clients and servers
https://zio.dev/zio-http
Apache License 2.0
768 stars 390 forks source link

App request test break after 0.0.4 update #1983

Closed carlosedp closed 1 year ago

carlosedp commented 1 year ago

Describe the bug Tests for requests break after the 0.0.4 update. Same app and test work on 0.0.3.

A simple app and test like:

object GreetingApp {
  def apply(): Http[Any, Nothing, Request, Response] =
    Http.collectZIO[Request] {
      // GET /greet
      case Method.GET -> !! / "greet" =>
        // httpHitsMetric("GET", "/greet").increment.
        ZIO.succeed(Response.text("Hello World!")) @@ MetricsApp.httpHitsMetric("GET", "/greet")
    }
}
// Test
object GreetingAppSpec extends ZIOSpecDefault {
  val greetApp = GreetingApp()
  def spec =
    suite("Greet application")(
      test("should greet world") {
        for {
          response <- greetApp(Request.get(URL(!! / "greet")))
          body     <- response.body.asString
        } yield assertTrue(
          response.status == Status.Ok,
          body == "Hello World!",
        )
      }
    )
}

After 0.0.4 presents the error:

❯ ./mill backend.test
[64/74] backend.test.compile
[info] compiling 2 Scala sources to /Users/cdepaula/repos/scala-playground/zio-scalajs-stack/out/backend/test/compile.dest/classes ...
[error] -- [E050] Type Error: /Users/cdepaula/repos/scala-playground/zio-scalajs-stack/backend/test/src/GreetingAppSpec.scala:15:22
[error] 15 |          response <- greetApp(Request.get(URL(!! / "greet")))
[error]    |                      ^^^^^^^^
[error]    |       value greetApp in object GreetingAppSpec does not take parameters
[error]    |----------------------------------------------------------------------------
[error]    | Explanation (enabled by `-explain`)
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    | You have specified more parameter lists than defined in the method definition(s).
[error]     ----------------------------------------------------------------------------
[error] Explanation
[error] ===========
[error] You have specified more parameter lists than defined in the method definition(s).

Expected behaviour Test to pass as in 0.0.3.

vigoo commented 1 year ago

This is an intentional API change. Instead of using apply you now have to call runZIO

greetApp.runZIO(Request.get(URL(!! / "greet")))