Something went wrong. Try again.
A batteries included HTTP/1.1 client in OCaml
Something went wrong. Try again.
2.9 kB · 76 lines
OCaml
at master
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677(*--------------------------------------------------------------------------- Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*)
(** Tests for Timeout module *)
module Timeout = Requests.Timeout
(** {1 none Tests} *)
let test_none () = let t = Timeout.none in Alcotest.(check (option (float 0.001))) "connect" None (Timeout.connect t); Alcotest.(check (option (float 0.001))) "read" None (Timeout.read t); Alcotest.(check (option (float 0.001))) "total" None (Timeout.total t); Alcotest.(check (option (float 0.001))) "expect_100_continue" None (Timeout.expect_100_continue t)
(** {1 default Tests} *)
let test_default () = let t = Timeout.default in Alcotest.(check (option (float 0.001))) "connect" (Some 10.0) (Timeout.connect t); Alcotest.(check (option (float 0.001))) "read" (Some 30.0) (Timeout.read t); Alcotest.(check (option (float 0.001))) "total" None (Timeout.total t); Alcotest.(check (option (float 0.001))) "expect_100_continue" (Some 1.0) (Timeout.expect_100_continue t)
(** {1 create Tests} *)
let test_create_with_values () = let t = Timeout.v ~connect:5.0 ~read:15.0 () in Alcotest.(check (option (float 0.001))) "connect" (Some 5.0) (Timeout.connect t); Alcotest.(check (option (float 0.001))) "read" (Some 15.0) (Timeout.read t); Alcotest.(check (option (float 0.001))) "total" None (Timeout.total t); Alcotest.(check (option (float 0.001))) "expect_100_continue" None (Timeout.expect_100_continue t)
let test_create_no_args () = let t = Timeout.v () in Alcotest.(check (option (float 0.001))) "connect" None (Timeout.connect t); Alcotest.(check (option (float 0.001))) "read" None (Timeout.read t); Alcotest.(check (option (float 0.001))) "total" None (Timeout.total t); Alcotest.(check (option (float 0.001))) "expect_100_continue" None (Timeout.expect_100_continue t)
let test_create_all_fields () = let t = Timeout.v ~connect:1.0 ~read:2.0 ~total:10.0 ~expect_100_continue:0.5 () in Alcotest.(check (option (float 0.001))) "connect" (Some 1.0) (Timeout.connect t); Alcotest.(check (option (float 0.001))) "read" (Some 2.0) (Timeout.read t); Alcotest.(check (option (float 0.001))) "total" (Some 10.0) (Timeout.total t); Alcotest.(check (option (float 0.001))) "expect_100_continue" (Some 0.5) (Timeout.expect_100_continue t)
(** {1 Test Suite} *)
let suite = ( "timeout", [ Alcotest.test_case "all fields None" `Quick test_none; Alcotest.test_case "has expected defaults" `Quick test_default; Alcotest.test_case "with connect and read" `Quick test_create_with_values; Alcotest.test_case "no args all None" `Quick test_create_no_args; Alcotest.test_case "all fields set" `Quick test_create_all_fields; ] )