TestClient

zio.http.TestClient
See theTestClient companion object
final case class TestClient(behavior: Ref[Routes[Any, Response]], serverSocketBehavior: Ref[WebSocketApp[Any]]) extends Driver[Any, Throwable]

Enables tests that use a client without needing a live Server

Value parameters

behavior

Contains the user-specified behavior that takes the place of the usual Server

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait Driver[Any, Throwable]
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def addRequestResponse(expectedRequest: Request, response: Response): ZIO[Any, Nothing, Unit]

Adds an exact 1-1 behavior

Adds an exact 1-1 behavior

Value parameters

expectedRequest

The request that will trigger the response

response

The response to be returned when a user submits the response

Attributes

Example
  TestClient.addRequestResponse(Request.get(URL.root), Response.ok)
def addRoute[R](route: Route[R, Response]): ZIO[R, Nothing, Unit]

Adds a route definition to handle requests that are submitted by test cases

Adds a route definition to handle requests that are submitted by test cases

Type parameters

R

Environment of the new route

Value parameters

route

New route to be added to the TestClient

Attributes

Example
  TestClient.addRoute { Method.ANY / trailing -> handler(Response.ok) }
def addRoutes[R](routes: Routes[R, Response]): ZIO[R, Nothing, Unit]

Adds routes to handle requests that are submitted by test cases

Adds routes to handle requests that are submitted by test cases

Type parameters

R

Environment of the new route

Value parameters

routes

New routes to be added to the TestClient

Attributes

Example
 TestClient.addRoutes {
   Routes(
     Method.GET / trailing          -> handler { Response.text("fallback") },
     Method.GET / "hello" / "world" -> handler { Response.text("Hey there!") },
   )
 }
def installSocketApp[Env1](app: WebSocketApp[Any]): ZIO[Env1, Nothing, Unit]
def method: Method
override def request(version: Version, method: Method, url: URL, headers: Headers, body: Body, sslConfig: Option[ClientSSLConfig], proxy: Option[Proxy])(implicit trace: Trace): ZIO[Any, Throwable, Response]

Attributes

Definition Classes
def socket[Env1](version: Version, url: URL, headers: Headers, app: WebSocketApp[Env1])(implicit trace: Trace): ZIO[Env1 & Scope, Throwable, Response]
def sslConfig: Option[ClientSSLConfig]
def url: URL

Inherited methods

final def apply(request: Request)(implicit trace: Trace): ZIO[Env & Scope, Err, Response]

Attributes

Inherited from:
Driver
final def disableStreaming(implicit ev: Throwable <:< Throwable): Driver[Env, Throwable]

Attributes

Inherited from:
Driver
final def mapError[Err2](f: Throwable => Err2): Driver[Env, Err2]

Attributes

Inherited from:
Driver
def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product
final def refineOrDie[Err2](pf: PartialFunction[Throwable, Err2])(implicit ev1: IsSubtypeOfError[Throwable, Throwable], ev2: CanFail[Throwable], trace: Trace): Driver[Env, Err2]

Attributes

Inherited from:
Driver
final def request(req: Request)(implicit trace: Trace): ZIO[Env & Scope, Err, Response]

Attributes

Inherited from:
Driver
final def retry[Env1, Err1 >: Throwable](policy: Schedule[Env1, Err1, Any]): Driver[Env1, Err1]

Attributes

Inherited from:
Driver
def widenError[E1](implicit ev: Throwable <:< E1): Driver[Env, E1]

Attributes

Inherited from:
Driver