···
("unknown_type.bin", Unknown_type, 0);
28
-
let test_binary_file filename expected_type expected_request_id =
28
+
let test_binary_file ~fs filename expected_type expected_request_id =
Printf.printf "Testing %s... " filename;
32
-
let ic = open_in_bin ("test_cases/" ^ filename) in
33
-
let len = in_channel_length ic in
34
-
let content = really_input_string ic len in
32
+
Eio.Path.with_open_in (fs, "test_cases/" ^ filename) @@ fun flow ->
33
+
let buf_read = Eio.Buf_read.of_flow flow ~max_size:1000000 in
34
+
Record.read buf_read
39
-
let buf_read = Eio.Buf_read.of_string content in
40
-
let parsed = Record.read buf_read in
assert (parsed.version = 1);
assert (parsed.record_type = expected_type);
assert (parsed.request_id = expected_request_id);
48
-
let test_params_decoding () =
43
+
let test_params_decoding ~fs =
Printf.printf "Testing params record content decoding... ";
52
-
let ic = open_in_bin "test_cases/params_get.bin" in
53
-
let len = in_channel_length ic in
54
-
let content = really_input_string ic len in
47
+
Eio.Path.with_open_in (fs, "test_cases/params_get.bin") @@ fun flow ->
48
+
let buf_read = Eio.Buf_read.of_flow flow ~max_size:1000000 in
49
+
Record.read buf_read
59
-
let buf_read = Eio.Buf_read.of_string content in
60
-
let parsed = Record.read buf_read in
(* Decode the params content *)
let params = Record.KV.decode parsed.content in
···
72
-
let test_large_record () =
62
+
let test_large_record ~fs =
Printf.printf "Testing large record... ";
76
-
let ic = open_in_bin "test_cases/large_record.bin" in
77
-
let len = in_channel_length ic in
78
-
let content = really_input_string ic len in
66
+
Eio.Path.with_open_in (fs, "test_cases/large_record.bin") @@ fun flow ->
67
+
let buf_read = Eio.Buf_read.of_flow flow ~max_size:1000000 in
68
+
Record.read buf_read
83
-
let buf_read = Eio.Buf_read.of_string content in
84
-
let parsed = Record.read buf_read in
assert (parsed.version = 1);
assert (parsed.record_type = Stdout);
assert (parsed.request_id = 1);
···
93
-
let test_padded_record () =
78
+
let test_padded_record ~fs =
Printf.printf "Testing padded record... ";
97
-
let ic = open_in_bin "test_cases/padded_record.bin" in
98
-
let len = in_channel_length ic in
99
-
let content = really_input_string ic len in
82
+
Eio.Path.with_open_in (fs, "test_cases/padded_record.bin") @@ fun flow ->
83
+
let buf_read = Eio.Buf_read.of_flow flow ~max_size:1000000 in
84
+
Record.read buf_read
104
-
let buf_read = Eio.Buf_read.of_string content in
105
-
let parsed = Record.read buf_read in
assert (parsed.version = 1);
assert (parsed.record_type = Stdout);
···
114
-
let test_multiplexed_records () =
94
+
let test_multiplexed_records ~fs =
Printf.printf "Testing multiplexed records... ";
118
-
let ic = open_in_bin "test_cases/multiplexed_requests.bin" in
119
-
let len = in_channel_length ic in
120
-
let content = really_input_string ic len in
98
+
Eio.Path.with_open_in (fs, "test_cases/multiplexed_requests.bin") @@ fun flow ->
99
+
let buf_read = Eio.Buf_read.of_flow flow ~max_size:1000000 in
100
+
let records = ref [] in
102
+
(* Read all records from the multiplexed stream *)
105
+
let record = Record.read buf_read in
106
+
records := record :: !records
108
+
with End_of_file -> ());
125
-
let buf_read = Eio.Buf_read.of_string content in
126
-
let records = ref [] in
128
-
(* Read all records from the multiplexed stream *)
131
-
let record = Record.read buf_read in
132
-
records := record :: !records
134
-
with End_of_file -> ());
136
-
let records = List.rev !records in
112
+
let records = List.rev records in
(* Should have multiple records with different request IDs *)
assert (List.length records > 5);
···
148
-
let run_all_tests () =
124
+
let run_all_tests ~fs =
Printf.printf "Validating all FastCGI test case files...\n\n%!";
(* Test individual files *)
List.iter (fun (filename, expected_type, expected_request_id) ->
153
-
test_binary_file filename expected_type expected_request_id
129
+
test_binary_file ~fs filename expected_type expected_request_id
Printf.printf "\nTesting specific content decoding...\n%!";
157
-
test_params_decoding ();
158
-
test_large_record ();
159
-
test_padded_record ();
160
-
test_multiplexed_records ();
133
+
test_params_decoding ~fs;
134
+
test_large_record ~fs;
135
+
test_padded_record ~fs;
136
+
test_multiplexed_records ~fs;
Printf.printf "\nā
All %d test case files validated successfully!\n%!" (List.length test_cases);
Printf.printf "ā
FastCGI Record implementation is working correctly!\n%!"
165
-
let () = run_all_tests ()
141
+
let () = Eio_main.run @@ fun env ->
142
+
let fs = Eio.Stdenv.cwd env in
143
+
run_all_tests ~fs:(fst fs)