TestServer

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

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait Server
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def addHandler[R](pf: PartialFunction[Request, ZIO[R, Response, Response]]): ZIO[R, Nothing, Unit]

Add new behavior to Server

Add new behavior to Server

Value parameters

pf

New behavior

Attributes

Example
for {
  state <- Ref.make(0)
  testRequest <- requestToCorrectPort
  _           <- TestServer.addHandler{ case (_: Request) =>
    for {
      curState <- state.getAndUpdate(_ + 1)
    } yield {
      if (curState > 0)
        Response(Status.InternalServerError)
      else
        Response(Status.Ok)
    }
  }
def addRequestResponse(expectedRequest: Request, response: Response): ZIO[Any, Nothing, Unit]

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))
override def install[R](httpApp: HttpApp[R])(implicit trace: Trace): URIO[R, Unit]

Installs the given HTTP application into the server.

Installs the given HTTP application into the server.

Attributes

Definition Classes
override def port: Int

The port on which the server is listening.

The port on which the server is listening.

Attributes

Definition Classes

Inherited methods

Attributes

Inherited from:
Product

Attributes

Inherited from:
Product