1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (tests networking)
20 #:use-module (ice-9 regex)
21 #:use-module (gnu services networking)
22 #:use-module (srfi srfi-64))
24 ;;; Tests for the (gnu services networking) module.
26 (test-begin "networking")
33 (define ntp-server->string (@@ (gnu services networking) ntp-server->string))
35 (define %ntp-server-sample
38 (address "some.ntp.server.org")
39 (options `(iburst (version 3) (maxpoll 16) prefer))))
41 (test-equal "ntp-server->string"
42 (ntp-server->string %ntp-server-sample)
43 "server some.ntp.server.org iburst version 3 maxpoll 16 prefer")
45 (test-equal "ntp configuration servers deprecated form"
46 (ntp-configuration-servers
48 (servers (list (ntp-server
50 (address "example.pool.ntp.org")
52 (ntp-configuration-servers
54 (servers (list "example.pool.ntp.org")))))
61 (define openntpd-configuration->string (@@ (gnu services networking)
62 openntpd-configuration->string))
64 (define %openntpd-conf-sample
65 (openntpd-configuration
66 (server '("0.guix.pool.ntp.org" "1.guix.pool.ntp.org"))
67 (listen-on '("127.0.0.1" "::1"))
68 (sensor '("udcf0 correction 70000"))
69 (constraint-from '("www.gnu.org"))
70 (constraints-from '("https://www.google.com/"))
71 (allow-large-adjustment? #t)))
73 (test-assert "openntpd configuration generation sanity check"
76 (define (string-match/newline pattern text)
77 (regexp-exec (make-regexp pattern regexp/newline) text))
79 (define (match-count pattern text)
80 (fold-matches (make-regexp pattern regexp/newline) text 0
84 (let ((config (openntpd-configuration->string %openntpd-conf-sample)))
86 (and (string-match/newline "^listen on 127.0.0.1$" config)
87 (string-match/newline "^listen on ::1$" config)
88 (string-match/newline "^sensor udcf0 correction 70000$" config)
89 (string-match/newline "^constraint from www.gnu.org$" config)
90 (string-match/newline "^server 0.guix.pool.ntp.org$" config)
92 "^constraints from \"https://www.google.com/\"$"
95 ;; Check for issue #3731 (see:
96 ;; http://debbugs.gnu.org/cgi/bugreport.cgi?bug=37318).
97 (= (match-count "^listen on " config) 2)
98 (= (match-count "^sensor " config) 1)
99 (= (match-count "^constraint from " config) 1)
100 (= (match-count "^server " config) 2)
101 (= (match-count "^constraints from " config) 1)))
103 (format #t "The configuration below failed \
104 the sanity check:\n~a~%" config)
108 (test-equal "openntpd generated config string ends with a newline"
109 (let ((config (openntpd-configuration->string %openntpd-conf-sample)))
110 (string-take-right config 1))
113 (test-end "networking")