My agentic slop goes here. Not intended for anyone else!
1let test_auth_from_toml_string () =
2 let toml_content = {|
3[api]
4email = "test@example.com"
5key = "test-api-key"
6site = "https://test.zulipchat.com"
7|} in
8
9 (* Create a temporary file *)
10 let temp_file = Filename.temp_file "zuliprc" ".toml" in
11 let oc = open_out temp_file in
12 output_string oc toml_content;
13 close_out oc;
14
15 (* Test parsing *)
16 (match Zulip.Auth.from_zuliprc ~path:temp_file () with
17 | Ok auth ->
18 Alcotest.(check string) "email" "test@example.com" (Zulip.Auth.email auth);
19 Alcotest.(check string) "server_url" "https://test.zulipchat.com" (Zulip.Auth.server_url auth);
20 (* Clean up *)
21 Sys.remove temp_file
22 | Error err ->
23 Sys.remove temp_file;
24 Alcotest.fail ("Failed to parse TOML: " ^ Zulip.Error.message err))
25
26let test_auth_from_toml_root_level () =
27 let toml_content = {|
28email = "root@example.com"
29key = "root-api-key"
30site = "https://root.zulipchat.com"
31|} in
32
33 let temp_file = Filename.temp_file "zuliprc" ".toml" in
34 let oc = open_out temp_file in
35 output_string oc toml_content;
36 close_out oc;
37
38 (match Zulip.Auth.from_zuliprc ~path:temp_file () with
39 | Ok auth ->
40 Alcotest.(check string) "email" "root@example.com" (Zulip.Auth.email auth);
41 Alcotest.(check string) "server_url" "https://root.zulipchat.com" (Zulip.Auth.server_url auth);
42 Sys.remove temp_file
43 | Error err ->
44 Sys.remove temp_file;
45 Alcotest.fail ("Failed to parse root level TOML: " ^ Zulip.Error.message err))
46
47let test_auth_missing_fields () =
48 let toml_content = {|
49[api]
50email = "incomplete@example.com"
51# Missing key and site
52|} in
53
54 let temp_file = Filename.temp_file "zuliprc" ".toml" in
55 let oc = open_out temp_file in
56 output_string oc toml_content;
57 close_out oc;
58
59 (match Zulip.Auth.from_zuliprc ~path:temp_file () with
60 | Ok _ ->
61 Sys.remove temp_file;
62 Alcotest.fail "Should have failed with missing fields"
63 | Error err ->
64 Sys.remove temp_file;
65 Alcotest.(check bool) "has config_missing error" true
66 (String.contains (Zulip.Error.message err) 'M'))
67
68let () =
69 let open Alcotest in
70 run "TOML Support Tests" [
71 "auth_toml", [
72 test_case "Parse TOML with [api] section" `Quick test_auth_from_toml_string;
73 test_case "Parse TOML with root level config" `Quick test_auth_from_toml_root_level;
74 test_case "Handle missing required fields" `Quick test_auth_missing_fields;
75 ];
76 ]