projects/guix·blob master · refs

130 lines · 4.0 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 Peter Mikkelsen <[email protected]>
3;;; Copyright © 2022 Bruno Victal <[email protected]>
4;;; Copyright © 2026 Cayetano Santos <[email protected]>
5;;;
6;;; This file is part of GNU Guix.
7;;;
8;;; GNU Guix is free software; you can redistribute it and/or modify it
9;;; under the terms of the GNU General Public License as published by
10;;; the Free Software Foundation; either version 3 of the License, or (at
11;;; your option) any later version.
12;;;
13;;; GNU Guix is distributed in the hope that it will be useful, but
14;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16;;; GNU General Public License for more details.
17;;;
18;;; You should have received a copy of the GNU General Public License
19;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21(define-module (gnu tests audio)
22 #:use-module (gnu tests)
23 #:use-module (gnu system)
24 #:use-module (gnu system vm)
25 #:use-module (gnu services)
26 #:use-module (gnu services audio)
27 #:use-module (gnu services networking)
28 #:use-module (gnu packages mpd)
29 #:use-module (guix gexp)
30 #:export (%test-mpd
31 %test-mympd))
32
33(define %mpd-os
34 (simple-operating-system
35 (service mpd-service-type)))
36
37(define (run-mpd-test)
38 "Run tests in %mpd-os, which has mpd running."
39 (define os
40 (marionette-operating-system
41 %mpd-os
42 #:imported-modules '((gnu services herd))))
43
44 (define vm
45 (virtual-machine os))
46
47 (define test
48 (with-imported-modules '((gnu build marionette))
49 #~(begin
50 (use-modules (srfi srfi-64)
51 (gnu build marionette))
52 (define marionette
53 (make-marionette (list #$vm)))
54
55 (test-runner-current (system-test-runner #$output))
56 (test-begin "mpd")
57
58 (test-assert "service is running"
59 (marionette-eval
60 '(begin
61 (use-modules (gnu services herd))
62 (start-service 'mpd))
63 marionette))
64
65 (test-assert "mpd listening"
66 ;; Wait until mpd is actually listening before spawning 'mpc'.
67 (wait-for-tcp-port 6600 marionette))
68
69 (test-equal "mpc connect"
70 0
71 (marionette-eval
72 '(system* #$(file-append mpd-mpc "/bin/mpc"))
73 marionette))
74
75 (test-end))))
76 (gexp->derivation "mpd-test" test))
77
78(define %test-mpd
79 (system-test
80 (name "mpd")
81 (description "Test that the mpd can run and be connected to.")
82 (value (run-mpd-test))))
83
84(define (run-mympd-test)
85 (define os (marionette-operating-system
86 (simple-operating-system (service dhcpcd-service-type)
87 (service mympd-service-type))
88 #:imported-modules '((gnu services herd))))
89
90 (define vm
91 (virtual-machine
92 (operating-system os)
93 (port-forwardings '((8080 . 80)))))
94
95 (define test
96 (with-imported-modules '((gnu build marionette))
97 #~(begin
98 (use-modules (srfi srfi-64)
99 (srfi srfi-8)
100 (web client)
101 (web response)
102 (gnu build marionette))
103
104 (define marionette
105 (make-marionette (list #$vm)))
106
107 (test-runner-current (system-test-runner #$output))
108 (test-begin "mympd")
109 (test-assert "service is running"
110 (marionette-eval '(begin
111 (use-modules (gnu services herd))
112
113 (start-service 'mympd))
114 marionette))
115
116 (test-assert "HTTP port ready"
117 (wait-for-tcp-port 80 marionette))
118
119 (test-equal "http-head"
120 200
121 (receive (x _) (http-head "http://localhost:8080") (response-code x)))
122
123 (test-end))))
124 (gexp->derivation "mympd-test" test))
125
126(define %test-mympd
127 (system-test
128 (name "mympd")
129 (description "Connect to a running myMPD service.")
130 (value (run-mympd-test))))