projects/guix·blob master · refs

125 lines · 4.2 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017, 2021 Ludovic Courtès <[email protected]>
3;;; Copyright © 2017, 2018, 2019, 2020, 2021 Christopher Baines <[email protected]>
4;;; Copyright © 2017, 2018 Clément Lassieur <[email protected]>
5;;; Copyright © 2018 Pierre-Antoine Rouby <[email protected]>
6;;; Copyright © 2018 Marius Bakke <[email protected]>
7;;;
8;;; This file is part of GNU Guix.
9;;;
10;;; GNU Guix is free software; you can redistribute it and/or modify it
11;;; under the terms of the GNU General Public License as published by
12;;; the Free Software Foundation; either version 3 of the License, or (at
13;;; your option) any later version.
14;;;
15;;; GNU Guix is distributed in the hope that it will be useful, but
16;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;;; GNU General Public License for more details.
19;;;
20;;; You should have received a copy of the GNU General Public License
21;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22
23(define-module (gnu tests ci)
24 #:use-module (gnu tests)
25 #:use-module (gnu system)
26 #:use-module (gnu system file-systems)
27 #:use-module (gnu system shadow)
28 #:use-module (gnu system vm)
29 #:use-module (gnu services)
30 #:use-module (gnu services ci)
31 #:use-module (gnu services web)
32 #:use-module (gnu services networking)
33 #:use-module (guix gexp)
34 #:use-module (guix store)
35 #:export (%test-laminar))
36
37
38(define %laminar-os
39 ;; Operating system under test.
40 (simple-operating-system
41 (service dhcpcd-service-type)
42 (service laminar-service-type)))
43
44(define* (run-laminar-test #:optional (http-port 8080))
45 "Run tests in %LAMINAR-OS, which has laminar running and listening on
46HTTP-PORT."
47 (define os
48 (marionette-operating-system
49 %laminar-os
50 #:imported-modules '((gnu services herd)
51 (guix combinators))))
52
53 (define vm
54 (virtual-machine
55 (operating-system os)
56 (port-forwardings `((,http-port . 8080)))))
57
58 (define test
59 (with-imported-modules '((gnu build marionette))
60 #~(begin
61 (use-modules (srfi srfi-11) (srfi srfi-64)
62 (ice-9 match)
63 (gnu build marionette)
64 (web uri)
65 (web client)
66 (web response))
67
68 (define marionette
69 ;; Forward the guest's HTTP-PORT, where laminar is listening, to
70 ;; port 8080 in the host.
71 (make-marionette (list #$vm)))
72
73 (test-runner-current (system-test-runner #$output))
74 (test-begin "laminar")
75
76 (test-assert "service running"
77 (marionette-eval
78 '(begin
79 (use-modules (gnu services herd))
80 (start-service 'laminar))
81 marionette))
82
83 (define* (retry-on-error f #:key times delay)
84 (let loop ((attempt 1))
85 (match (catch
86 #t
87 (lambda ()
88 (cons #t
89 (f)))
90 (lambda args
91 (cons #f
92 args)))
93 ((#t . return-value)
94 return-value)
95 ((#f . error-args)
96 (if (>= attempt times)
97 error-args
98 (begin
99 (sleep delay)
100 (loop (+ 1 attempt))))))))
101
102 (test-equal "http-get"
103 200
104 (retry-on-error
105 (lambda ()
106 (let-values (((response text)
107 (http-get #$(format
108 #f
109 "http://localhost:~A/"
110 http-port)
111 ;; TODO: Why does decoding fail?
112 #:decode-body? #f)))
113 (response-code response)))
114 #:times 10
115 #:delay 5))
116
117 (test-end))))
118
119 (gexp->derivation "laminar-test" test))
120
121(define %test-laminar
122 (system-test
123 (name "laminar")
124 (description "Connect to a running Laminar server.")
125 (value (run-laminar-test))))