Module Grpc_test_helpers

A library to help writing tests for gRPC Eio applications.

This is built with expect-tests in mind. See the keyval application in this repo for a complete example of use.

Testing environment

To use the rest of this API, you need to introduce a new test environment to the scope. This is done via the run function. This function will run the given function f with a fresh environment of type t, and clean up the environment at the end.

type t
val run : env: < fs : _ Eio.Path.t ; net : [> [ `Generic | `Unix ] Eio.Net.ty ] Eio.Resource.t ; process_mgr : _ Eio.Process.mgr ; stderr : _ Eio.Flow.sink ; clock : _ Eio.Time.clock.. > -> f:(t -> Base.unit) -> Base.unit

Socket kinds

The tests support both kind of sockaddr, unix sockets and tcp connections, in both cases to connect to a server running on the localhost where the expect tests are running.

module Sockaddr_kind : sig ... end

Choosing the kind of sockaddr to use.

Config

module Config : sig ... end

A configuration is required by the library to know how to run your server and client commands.

Server

The rest of the API is used to run one or several server(s) and connect to it, either by running your app's cli, or in OCaml directly via Server.with_connection.

module Server : sig ... end
module With_server : sig ... end
val with_server : ?sockaddr_kind:Sockaddr_kind.t -> t -> config:Config.t -> f:(With_server.t -> Base.unit) -> Base.unit

Takes care of starting a server, running f and stopping the server at the end. sockaddr_kind defaults to Unix_socket.

val run_client : Server.t -> ?offline:Base.bool -> Base.string Base.list Base.list -> Base.unit

run_client server ?offline args runs a client process that will connect to the given server. offline:true should be used for commands that do not connect to the server, and defaults to false. The args are flatten before the actual invocation, the grouping is only useful to make the code more readable (e.g. you can group together a flag with it's required argument, etc.).