diff --git a/docs/guides/testing-http-apps.md b/docs/guides/testing-http-apps.md index 578d958ee2..5d462bcf36 100644 --- a/docs/guides/testing-http-apps.md +++ b/docs/guides/testing-http-apps.md @@ -117,12 +117,10 @@ object TestServerExampleSpec extends ZIOSpecDefault { fallbackResponse <- client.batched(Request.get(testRequest.url / "any")) fallbackBody <- fallbackResponse.body.asString } yield assertTrue(helloBody == "Hey there!", fallbackBody == "fallback") - }.provideSome[Client with Driver](TestServer.layer) + } }.provide( - ZLayer.succeed(Server.Config.default.onAnyOpenPort), + TestServer.default, Client.default, - NettyDriver.customized, - ZLayer.succeed(NettyConfig.defaultWithFastShutdown), ) } ``` diff --git a/zio-http-testkit/src/main/scala/zio/http/TestServer.scala b/zio-http-testkit/src/main/scala/zio/http/TestServer.scala index 0bdd25dad9..d551f693dd 100644 --- a/zio-http-testkit/src/main/scala/zio/http/TestServer.scala +++ b/zio-http-testkit/src/main/scala/zio/http/TestServer.scala @@ -2,6 +2,9 @@ package zio.http import zio._ +import zio.http.netty.NettyConfig +import zio.http.netty.server.NettyDriver + /** * Enables tests that make calls against "localhost" with user-specified * Behavior/Responses. @@ -136,4 +139,11 @@ object TestServer { } yield TestServer(driver, result.port) } + val default: ZLayer[Any, Nothing, Server with TestServer] = ZLayer.make[Server with TestServer][Nothing]( + TestServer.layer.orDie, + ZLayer.succeed(Server.Config.default.onAnyOpenPort), + NettyDriver.customized.orDie, + ZLayer.succeed(NettyConfig.defaultWithFastShutdown), + ) + } diff --git a/zio-http-testkit/src/test/scala/zio/http/TestServerSpec.scala b/zio-http-testkit/src/test/scala/zio/http/TestServerSpec.scala index d5d7b462ab..3562ab50e1 100644 --- a/zio-http-testkit/src/test/scala/zio/http/TestServerSpec.scala +++ b/zio-http-testkit/src/test/scala/zio/http/TestServerSpec.scala @@ -37,8 +37,8 @@ object TestServerSpec extends ZIOHttpSpec { ) } yield assertTrue(status(response1) == Status.Ok) && assertTrue(status(response2) == Status.InternalServerError) - }.provideSome[Client with Driver]( - TestServer.layer, + }.provideSome[Client]( + TestServer.default, Scope.default, ), suite("Exact Request=>Response version")( @@ -83,8 +83,8 @@ object TestServerSpec extends ZIOHttpSpec { } yield assertTrue(status(finalResponse) == Status.NotFound) }, ) - .provideSome[Client with Driver]( - TestServer.layer, + .provideSome[Client]( + TestServer.default, Scope.default, ), test("add routes to the server") { @@ -102,15 +102,12 @@ object TestServerSpec extends ZIOHttpSpec { fallbackResponse <- client(Request.get(testRequest.url / "any")) fallbackBody <- fallbackResponse.body.asString } yield assertTrue(helloBody == "Hey there!", fallbackBody == "fallback") - }.provideSome[Client with Driver]( - TestServer.layer, + }.provideSome[Client]( + TestServer.default, Scope.default, ), ).provide( - ZLayer.succeed(Server.Config.default.onAnyOpenPort), Client.default, - NettyDriver.customized, - ZLayer.succeed(NettyConfig.defaultWithFastShutdown), ) private def requestToCorrectPort =