zio.http.TestServer
See theTestServer companion object
final case class TestServer(driver: Driver, bindPort: Int) extends Server
Enables tests that make calls against "localhost" with user-specified Behavior/Responses.
Value parameters
- bindPort
-
Port for HTTP interactions
- driver
-
The web driver that accepts our Server behavior
Attributes
Members list
Value members
Concrete methods
Define 1-1 mappings between incoming Requests and outgoing Responses
Define 1-1 mappings between incoming Requests and outgoing Responses
Value parameters
- expectedRequest
-
Request that will trigger the provided Response
- response
-
Response that the Server will send
Attributes
- Example
-
TestServer.addRequestResponse(Request.get(url = URL.root.port(port = ???)), Response(Status.Ok))
Adds a new route to the Server
Adds a new route to the Server
Value parameters
- route
-
New route
Attributes
- Example
-
TestServer.addRoute { Method.ANY / trailing -> handler { (_: Path, _: Request) => for { curState <- state.getAndUpdate(_ + 1) } yield { if (curState > 0) Response(Status.InternalServerError) else Response(Status.Ok) } } }
Add new routes to the Server
Add new routes to the Server
Attributes
- Example
-
TestServer.addRoutes { Routes( Method.ANY / trailing -> handler { (_: Path, _: Request) => Response.text("Fallback handler") }, Method.GET / "hello" / "world" -> handler { (_: Path, _: Request) => Response.text("Hello world!") }, ) }
Installs the given HTTP application into the server.
Inherited methods
Attributes
- Inherited from:
- Product
Attributes
- Inherited from:
- Product
In this article