| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 |
|
| 19 | (define-module (tests networking)
|
| 20 | #:use-module (ice-9 regex)
|
| 21 | #:use-module (gnu services networking)
|
| 22 | #:use-module (srfi srfi-64))
|
| 23 |
|
| 24 | |
| 25 |
|
| 26 | (test-begin "networking")
|
| 27 |
|
| 28 |
|
| 29 | |
| 30 | |
| 31 | |
| 32 |
|
| 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")
|
| 39 | |
| 40 | (options `("iburst" (version 3) (maxpoll 16) prefer))))
|
| 41 |
|
| 42 | (test-equal "ntp-server->string"
|
| 43 | "server some.ntp.server.org iburst version 3 maxpoll 16 prefer"
|
| 44 | (ntp-server->string %ntp-server-sample))
|
| 45 |
|
| 46 |
|
| 47 | |
| 48 | |
| 49 | |
| 50 |
|
| 51 | (define openntpd-configuration->string (@@ (gnu services networking)
|
| 52 | openntpd-configuration->string))
|
| 53 |
|
| 54 | (define %openntpd-conf-sample
|
| 55 | (openntpd-configuration
|
| 56 | (server '("0.guix.pool.ntp.org" "1.guix.pool.ntp.org"))
|
| 57 | (listen-on '("127.0.0.1" "::1"))
|
| 58 | (sensor '("udcf0 correction 70000"))
|
| 59 | (constraint-from '("www.gnu.org"))
|
| 60 | (constraints-from '("https://www.google.com/"))))
|
| 61 |
|
| 62 | (test-assert "openntpd configuration generation sanity check"
|
| 63 |
|
| 64 | (begin
|
| 65 | (define (string-match/newline pattern text)
|
| 66 | (regexp-exec (make-regexp pattern regexp/newline) text))
|
| 67 |
|
| 68 | (define (match-count pattern text)
|
| 69 | (fold-matches (make-regexp pattern regexp/newline) text 0
|
| 70 | (lambda (match count)
|
| 71 | (1+ count))))
|
| 72 |
|
| 73 | (let ((config (openntpd-configuration->string %openntpd-conf-sample)))
|
| 74 | (if (not
|
| 75 | (and (string-match/newline "^listen on 127.0.0.1$" config)
|
| 76 | (string-match/newline "^listen on ::1$" config)
|
| 77 | (string-match/newline "^sensor udcf0 correction 70000$" config)
|
| 78 | (string-match/newline "^constraint from www.gnu.org$" config)
|
| 79 | (string-match/newline "^server 0.guix.pool.ntp.org$" config)
|
| 80 | (string-match/newline
|
| 81 | "^constraints from \"https://www.google.com/\"$"
|
| 82 | config)
|
| 83 |
|
| 84 | |
| 85 | |
| 86 | (= (match-count "^listen on " config) 2)
|
| 87 | (= (match-count "^sensor " config) 1)
|
| 88 | (= (match-count "^constraint from " config) 1)
|
| 89 | (= (match-count "^server " config) 2)
|
| 90 | (= (match-count "^constraints from " config) 1)))
|
| 91 | (begin
|
| 92 | (format #t "The configuration below failed \
|
| 93 | the sanity check:\n~a~%" config)
|
| 94 | #f)
|
| 95 | #t))))
|
| 96 |
|
| 97 | (test-equal "openntpd generated config string ends with a newline"
|
| 98 | "\n"
|
| 99 | (let ((config (openntpd-configuration->string %openntpd-conf-sample)))
|
| 100 | (string-take-right config 1)))
|
| 101 |
|
| 102 | (test-end "networking")
|