Grpc_test
A library to help writting 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.
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.
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
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.
module Config : sig ... end
A configuration is required by the library to know how to run your server and client commands.
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
.
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.).