aboutsummaryrefslogtreecommitdiff
path: root/tests/web-server.scm
blob: 490926071f5079d81646cc379153b19e87773315 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(((calp server routes) make-make-routes)
 ((web server) run-server)
 ((ice-9 threads) call-with-new-thread cancel-thread)
 ((web client) http-get)
 ((util) let*)
 ((web response) response-code response-location)
 ((web uri) build-uri uri-path)
 ((guile) AF_INET))

;; TODO find some free address.
(define port 8090)
(define host "127.8.9.5")

(define server-thread
  (call-with-new-thread
   (lambda ()
     (run-server (make-make-routes)
                 'http
                 `(family: ,AF_INET
                           host: ,host
                           port: ,port
                           ))
     ;; This test should always fail, but should never be run
     (test-assert "Server returned unexpectedly" #f)
     )))

(let* ((response body (http-get (build-uri 'http host: host port: port))))
  (test-eqv "Basic connect" 200 (response-code response)))

(let* ((response body (http-get (build-uri 'http host: host port: port
                                           path: "/today"
                                           query: "view=week&date=2020-01-04"))))
  (test-eqv "Redirect"
    302 (response-code response))
  (test-equal "Fully specified redirect position"
    "/week/2020-01-04.html" (uri-path (response-location response))))

(cancel-thread server-thread)