gnu: r-wgcna: Move to (gnu packages bioconductor).
[jackhill/guix/guix.git] / tests / networking.scm
CommitLineData
5658ae8a
MC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (tests networking)
2625abc6 20 #:use-module (ice-9 regex)
5658ae8a
MC
21 #:use-module (gnu services networking)
22 #:use-module (srfi srfi-64))
23
24;;; Tests for the (gnu services networking) module.
25
2625abc6
MC
26(test-begin "networking")
27
28\f
29;;;
30;;; NTP.
31;;;
32
5658ae8a
MC
33(define ntp-server->string (@@ (gnu services networking) ntp-server->string))
34
35(define %ntp-server-sample
36 (ntp-server
37 (type 'server)
38 (address "some.ntp.server.org")
97bc3cbe
MC
39 ;; Using either strings or symbols for option names is accepted.
40 (options `("iburst" (version 3) (maxpoll 16) prefer))))
5658ae8a 41
5658ae8a 42(test-equal "ntp-server->string"
97bc3cbe
MC
43 "server some.ntp.server.org iburst version 3 maxpoll 16 prefer"
44 (ntp-server->string %ntp-server-sample))
5658ae8a
MC
45
46(test-equal "ntp configuration servers deprecated form"
97bc3cbe
MC
47 (ntp-configuration-servers
48 (ntp-configuration
49 (servers (list "example.pool.ntp.org"))))
5658ae8a
MC
50 (ntp-configuration-servers
51 (ntp-configuration
52 (servers (list (ntp-server
53 (type 'server)
54 (address "example.pool.ntp.org")
97bc3cbe 55 (options '())))))))
5658ae8a 56
2625abc6
MC
57\f
58;;;
59;;; OpenNTPD
60;;;
61
62(define openntpd-configuration->string (@@ (gnu services networking)
63 openntpd-configuration->string))
64
65(define %openntpd-conf-sample
66 (openntpd-configuration
67 (server '("0.guix.pool.ntp.org" "1.guix.pool.ntp.org"))
68 (listen-on '("127.0.0.1" "::1"))
69 (sensor '("udcf0 correction 70000"))
70 (constraint-from '("www.gnu.org"))
71 (constraints-from '("https://www.google.com/"))
72 (allow-large-adjustment? #t)))
73
74(test-assert "openntpd configuration generation sanity check"
75
76 (begin
77 (define (string-match/newline pattern text)
78 (regexp-exec (make-regexp pattern regexp/newline) text))
79
80 (define (match-count pattern text)
81 (fold-matches (make-regexp pattern regexp/newline) text 0
82 (lambda (match count)
83 (1+ count))))
84
85 (let ((config (openntpd-configuration->string %openntpd-conf-sample)))
86 (if (not
87 (and (string-match/newline "^listen on 127.0.0.1$" config)
88 (string-match/newline "^listen on ::1$" config)
89 (string-match/newline "^sensor udcf0 correction 70000$" config)
90 (string-match/newline "^constraint from www.gnu.org$" config)
91 (string-match/newline "^server 0.guix.pool.ntp.org$" config)
92 (string-match/newline
93 "^constraints from \"https://www.google.com/\"$"
94 config)
95
96 ;; Check for issue #3731 (see:
97 ;; http://debbugs.gnu.org/cgi/bugreport.cgi?bug=37318).
98 (= (match-count "^listen on " config) 2)
99 (= (match-count "^sensor " config) 1)
100 (= (match-count "^constraint from " config) 1)
101 (= (match-count "^server " config) 2)
102 (= (match-count "^constraints from " config) 1)))
103 (begin
104 (format #t "The configuration below failed \
105the sanity check:\n~a~%" config)
106 #f)
107 #t))))
108
109(test-equal "openntpd generated config string ends with a newline"
97bc3cbe 110 "\n"
2625abc6 111 (let ((config (openntpd-configuration->string %openntpd-conf-sample)))
97bc3cbe 112 (string-take-right config 1)))
2625abc6 113
5658ae8a 114(test-end "networking")