AtlatestRepositorysigil-tls

sigil-tls / tree / testtest-tls.sgl

1(import (sigil test)
2 (sigil tls)
3 (sigil socket))
4
5;; ============================================================
6;; Type predicates
7;; ============================================================
8
9(test-group "type predicates"
10 (test "tls-connection? returns #f for string"
11 (assert-false (tls-connection? "hello")))
13 (test "tls-connection? returns #f for number"
14 (assert-false (tls-connection? 42)))
16 (test "tls-connection? returns #f for list"
17 (assert-false (tls-connection? '(1 2 3))))
19 (test "tls-connection? returns #f for boolean"
20 (assert-false (tls-connection? #f)))
22 (test "tls-connection? returns #f for plain TCP socket"
23 (let ((sock (tcp-listen 0)))
24 (assert-false (tls-connection? sock))
25 (socket-close sock))))
27;; ============================================================
28;; Connection failure handling
29;; ============================================================
31(test-group "connection failure handling"
32 (test "tls-connect to closed port returns #f"
33 (assert-false (tls-connect "127.0.0.1" 1)))
35 (test "tls-connect to invalid host returns #f"
36 (assert-false (tls-connect "invalid-host-that-does-not-exist.test" 443))))
38;; ============================================================
39;; Error paths (wrong argument types)
40;; ============================================================
42(test-group "error paths"
43 (test "tls-connect with non-string hostname raises error"
44 (assert-error (tls-connect 42 443)))
46 (test "tls-connect with non-integer port raises error"
47 (assert-error (tls-connect "localhost" "443")))
49 (test "tls-read with non-connection raises error"
50 (assert-error (tls-read "not-a-connection")))
52 (test "tls-write with non-connection raises error"
53 (assert-error (tls-write "not-a-connection" "data")))
55 (test "tls-close with non-connection raises error"
56 (assert-error (tls-close "not-a-connection"))))
58(run-tests)