How to mock response for cohttp?

I wanna to write some unit tests for the process of http response, for example, for this function

let get_em_positions_resp ~code ~year ~month =
  let%bind _, body =
    Cohttp_async.Client.get
      ~headers:(Cohttp.Header.of_list [ (hdr_ua, ua) ])
      (generate_em_positions_uri ~code ~year ~month)
  in
  Cohttp_async.Body.to_string body

When I wrote Java, there’s some cool thing to help. Is there kind of mock tools in OCaml?

1 Like

You might want to implement Cohttp_lwt.S.Client like I did in there: https://github.com/ghuysmans/api-cohttp-lwt/tree/master/mock.

1 Like