(*--------------------------------------------------------------------------- Copyright (c) 2025 Anil Madhavapeddy . All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*) (** Tests for Expect_continue module *) module Expect_continue = Requests.Expect_continue (** {1 Default Configuration Tests} *) let test_default_threshold () = let t = Expect_continue.default in Alcotest.(check int64) "default threshold is 1MB" 1_048_576L (Expect_continue.threshold t) let test_default_enabled () = let t = Expect_continue.default in Alcotest.(check bool) "default is enabled" true (Expect_continue.enabled t) let test_default_timeout () = let t = Expect_continue.default in Alcotest.(check (float 0.01)) "default timeout" 1.0 (Expect_continue.timeout t) (** {1 Disabled Configuration Tests} *) let test_disabled_not_enabled () = let t = Expect_continue.disabled in Alcotest.(check bool) "disabled is not enabled" false (Expect_continue.enabled t) (** {1 of_config Tests} *) let test_of_config_disabled () = let t = Expect_continue.of_config `Disabled in Alcotest.(check bool) "Disabled config" false (Expect_continue.enabled t) let test_of_config_always () = let t = Expect_continue.of_config `Always in Alcotest.(check bool) "Always enabled" true (Expect_continue.enabled t); Alcotest.(check int64) "Always threshold is 0" 0L (Expect_continue.threshold t) let test_of_config_threshold () = let t = Expect_continue.of_config (`Threshold 5000L) in Alcotest.(check bool) "Threshold enabled" true (Expect_continue.enabled t); Alcotest.(check int64) "Threshold value" 5000L (Expect_continue.threshold t) let test_of_config_custom_timeout () = let t = Expect_continue.of_config ~timeout:2.5 (`Threshold 1000L) in Alcotest.(check (float 0.01)) "custom timeout" 2.5 (Expect_continue.timeout t) (** {1 should_use Tests} *) let test_should_use_above_threshold () = let t = Expect_continue.of_config (`Threshold 1000L) in Alcotest.(check bool) "body above threshold" true (Expect_continue.should_use t 2000L) let test_should_use_at_threshold () = let t = Expect_continue.of_config (`Threshold 1000L) in Alcotest.(check bool) "body at threshold" true (Expect_continue.should_use t 1000L) let test_should_use_below_threshold () = let t = Expect_continue.of_config (`Threshold 1000L) in Alcotest.(check bool) "body below threshold" false (Expect_continue.should_use t 999L) let test_should_use_disabled () = let t = Expect_continue.disabled in Alcotest.(check bool) "disabled always false" false (Expect_continue.should_use t 999_999_999L) let test_should_use_always () = let t = Expect_continue.of_config `Always in Alcotest.(check bool) "always with any body" true (Expect_continue.should_use t 1L) let test_should_use_always_zero () = let t = Expect_continue.of_config `Always in Alcotest.(check bool) "always with zero body" true (Expect_continue.should_use t 0L) (** {1 default_threshold Tests} *) let test_default_threshold_value () = Alcotest.(check int64) "default_threshold is 1MB" 1_048_576L Expect_continue.default_threshold (** {1 make Tests} *) let test_make_defaults () = let t = Expect_continue.v () in Alcotest.(check bool) "make defaults enabled" true (Expect_continue.enabled t); Alcotest.(check int64) "make defaults threshold" 1_048_576L (Expect_continue.threshold t) let test_make_custom () = let t = Expect_continue.v ~enabled:false ~threshold:500L ~timeout:3.0 () in Alcotest.(check bool) "custom not enabled" false (Expect_continue.enabled t); Alcotest.(check int64) "custom threshold" 500L (Expect_continue.threshold t); Alcotest.(check (float 0.01)) "custom timeout" 3.0 (Expect_continue.timeout t) (** {1 to_string Tests} *) let test_to_string () = let t = Expect_continue.default in let s = Expect_continue.to_string t in Alcotest.(check bool) "to_string non-empty" true (String.length s > 0) (** {1 Test Suite} *) let suite = ( "expect_continue", [ Alcotest.test_case "threshold is 1MB" `Quick test_default_threshold; Alcotest.test_case "enabled" `Quick test_default_enabled; Alcotest.test_case "timeout" `Quick test_default_timeout; Alcotest.test_case "not enabled" `Quick test_disabled_not_enabled; Alcotest.test_case "Disabled" `Quick test_of_config_disabled; Alcotest.test_case "Always" `Quick test_of_config_always; Alcotest.test_case "Threshold" `Quick test_of_config_threshold; Alcotest.test_case "custom timeout" `Quick test_of_config_custom_timeout; Alcotest.test_case "above threshold" `Quick test_should_use_above_threshold; Alcotest.test_case "at threshold" `Quick test_should_use_at_threshold; Alcotest.test_case "below threshold" `Quick test_should_use_below_threshold; Alcotest.test_case "disabled always false" `Quick test_should_use_disabled; Alcotest.test_case "always with any body" `Quick test_should_use_always; Alcotest.test_case "always with zero body" `Quick test_should_use_always_zero; Alcotest.test_case "value" `Quick test_default_threshold_value; Alcotest.test_case "defaults" `Quick test_make_defaults; Alcotest.test_case "custom" `Quick test_make_custom; Alcotest.test_case "non-empty" `Quick test_to_string; ] )