AtlatestRepositorysigil-youtube

sigil-youtube / tree / testlive-test.sgl

1;;; Tests for (youtube live) — livestreaming module
2;;;
3;;; Tests record construction and JSON parsing with fixture data.
4
5(import (sigil core)
6 (sigil dict)
7 (sigil string)
8 (sigil struct)
9 (sigil json)
10 (sigil test)
11 (youtube)
12 (youtube live))
14;; ---------------------------------------------------------------
15;; Test fixtures
16;; ---------------------------------------------------------------
18(define broadcast-resource-json
19 (json-decode
20 (string-append
21 "{\"id\": \"bcast-001\","
22 " \"snippet\": {"
23 " \"title\": \"Weekly Livestream\","
24 " \"scheduledStartTime\": \"2026-03-28T18:00:00Z\""
25 " },"
26 " \"status\": {"
27 " \"lifeCycleStatus\": \"ready\""
28 " },"
29 " \"contentDetails\": {"
30 " \"boundStreamId\": \"stream-001\""
31 " }}")))
33(define broadcast-minimal-json
34 (json-decode
35 (string-append
36 "{\"id\": \"bcast-002\","
37 " \"snippet\": {},"
38 " \"status\": {},"
39 " \"contentDetails\": {}}")))
41(define stream-resource-json
42 (json-decode
43 (string-append
44 "{\"id\": \"stream-001\","
45 " \"snippet\": {"
46 " \"title\": \"Main Stream Feed\""
47 " },"
48 " \"cdn\": {"
49 " \"ingestionType\": \"rtmp\","
50 " \"ingestionInfo\": {"
51 " \"ingestionAddress\": \"rtmp://a.rtmp.youtube.com/live2\","
52 " \"streamName\": \"xxxx-xxxx-xxxx-xxxx-xxxx\""
53 " }"
54 " }}")))
56(define stream-minimal-json
57 (json-decode
58 (string-append
59 "{\"id\": \"stream-002\","
60 " \"snippet\": {},"
61 " \"cdn\": {}}")))
63;; ---------------------------------------------------------------
64;; Broadcast record tests
65;; ---------------------------------------------------------------
67(test-group "broadcast records"
69 (test "broadcast construction"
70 (let ((b (youtube-broadcast id: "bc1" title: "Live!"
71 scheduled-start: "2026-04-01T20:00:00Z"
72 lifecycle-status: "live"
73 stream-id: "st1")))
74 (assert-true (youtube-broadcast? b))
75 (assert-equal "bc1" (youtube-broadcast-id b))
76 (assert-equal "Live!" (youtube-broadcast-title b))
77 (assert-equal "2026-04-01T20:00:00Z"
78 (youtube-broadcast-scheduled-start b))
79 (assert-equal "live" (youtube-broadcast-lifecycle-status b))
80 (assert-equal "st1" (youtube-broadcast-stream-id b))))
82 (test "broadcast defaults"
83 (let ((b (youtube-broadcast id: "bc2")))
84 (assert-equal "" (youtube-broadcast-title b))
85 (assert-equal #f (youtube-broadcast-scheduled-start b))
86 (assert-equal "created" (youtube-broadcast-lifecycle-status b))
87 (assert-equal #f (youtube-broadcast-stream-id b)))))
89;; ---------------------------------------------------------------
90;; Stream record tests
91;; ---------------------------------------------------------------
93(test-group "stream records"
95 (test "stream construction"
96 (let ((s (youtube-stream id: "st1" title: "Feed"
97 rtmp-url: "rtmp://example.com/live"
98 stream-key: "key-123")))
99 (assert-true (youtube-stream? s))
100 (assert-equal "st1" (youtube-stream-id s))
101 (assert-equal "Feed" (youtube-stream-title s))
102 (assert-equal "rtmp://example.com/live" (youtube-stream-rtmp-url s))
103 (assert-equal "key-123" (youtube-stream-stream-key s))))
105 (test "stream defaults"
106 (let ((s (youtube-stream id: "st2")))
107 (assert-equal "" (youtube-stream-title s))
108 (assert-equal #f (youtube-stream-rtmp-url s))
109 (assert-equal #f (youtube-stream-stream-key s)))))
111;; ---------------------------------------------------------------
112;; Broadcast parsing tests
113;; ---------------------------------------------------------------
115(test-group "broadcast parsing"
117 (test "parse full broadcast"
118 (let ((b (parse-broadcast broadcast-resource-json)))
119 (assert-true (youtube-broadcast? b))
120 (assert-equal "bcast-001" (youtube-broadcast-id b))
121 (assert-equal "Weekly Livestream" (youtube-broadcast-title b))
122 (assert-equal "2026-03-28T18:00:00Z"
123 (youtube-broadcast-scheduled-start b))
124 (assert-equal "ready" (youtube-broadcast-lifecycle-status b))
125 (assert-equal "stream-001" (youtube-broadcast-stream-id b))))
127 (test "parse minimal broadcast"
128 (let ((b (parse-broadcast broadcast-minimal-json)))
129 (assert-equal "bcast-002" (youtube-broadcast-id b))
130 (assert-equal "" (youtube-broadcast-title b))
131 (assert-equal #f (youtube-broadcast-scheduled-start b))
132 (assert-equal "created" (youtube-broadcast-lifecycle-status b))
133 (assert-equal #f (youtube-broadcast-stream-id b)))))
135;; ---------------------------------------------------------------
136;; Stream parsing tests
137;; ---------------------------------------------------------------
139(test-group "stream parsing"
141 (test "parse full stream"
142 (let ((s (parse-stream stream-resource-json)))
143 (assert-true (youtube-stream? s))
144 (assert-equal "stream-001" (youtube-stream-id s))
145 (assert-equal "Main Stream Feed" (youtube-stream-title s))
146 (assert-equal "rtmp://a.rtmp.youtube.com/live2"
147 (youtube-stream-rtmp-url s))
148 (assert-equal "xxxx-xxxx-xxxx-xxxx-xxxx"
149 (youtube-stream-stream-key s))))
151 (test "parse minimal stream"
152 (let ((s (parse-stream stream-minimal-json)))
153 (assert-equal "stream-002" (youtube-stream-id s))
154 (assert-equal "" (youtube-stream-title s))
155 (assert-equal #f (youtube-stream-rtmp-url s))
156 (assert-equal #f (youtube-stream-stream-key s)))))
158(run-tests)