services: ntp: Ensure no double quotes are output to config file.

* gnu/services/networking.scm (ntp-server->string): Use the textual
representation of the values as printed by 'display' rather than 'write', to
avoid inserting double quotes in the generated config.
* tests/networking.scm (%ntp-server-sample): Add a comment and make one of the
options a string, to exercise the fix.
("ntp-server->string"): Move the expected value to the first argument.
("ntp configuration servers deprecated form"): Likewise.
("openntpd generated config string ends with a newline"): Likewise.
This commit is contained in:
Maxim Cournoyer 2019-10-30 17:46:17 -04:00
parent d29d04c9e6
commit 97bc3cbea5
No known key found for this signature in database
GPG Key ID: 1260E46482E63562
2 changed files with 11 additions and 10 deletions

View File

@ -345,7 +345,7 @@ Protocol (DHCP) client, on all the non-loopback network interfaces."
(res '())) (res '()))
(if (list? x) (if (list? x)
(fold loop res x) (fold loop res x)
(cons (format #f "~s" x) res))))) (cons (format #f "~a" x) res)))))
(match ntp-server (match ntp-server
(($ <ntp-server> type address options) (($ <ntp-server> type address options)

View File

@ -36,22 +36,23 @@
(ntp-server (ntp-server
(type 'server) (type 'server)
(address "some.ntp.server.org") (address "some.ntp.server.org")
(options `(iburst (version 3) (maxpoll 16) prefer)))) ;; Using either strings or symbols for option names is accepted.
(options `("iburst" (version 3) (maxpoll 16) prefer))))
(test-equal "ntp-server->string" (test-equal "ntp-server->string"
(ntp-server->string %ntp-server-sample) "server some.ntp.server.org iburst version 3 maxpoll 16 prefer"
"server some.ntp.server.org iburst version 3 maxpoll 16 prefer") (ntp-server->string %ntp-server-sample))
(test-equal "ntp configuration servers deprecated form" (test-equal "ntp configuration servers deprecated form"
(ntp-configuration-servers
(ntp-configuration
(servers (list "example.pool.ntp.org"))))
(ntp-configuration-servers (ntp-configuration-servers
(ntp-configuration (ntp-configuration
(servers (list (ntp-server (servers (list (ntp-server
(type 'server) (type 'server)
(address "example.pool.ntp.org") (address "example.pool.ntp.org")
(options '())))))) (options '())))))))
(ntp-configuration-servers
(ntp-configuration
(servers (list "example.pool.ntp.org")))))
;;; ;;;
@ -106,8 +107,8 @@ the sanity check:\n~a~%" config)
#t)))) #t))))
(test-equal "openntpd generated config string ends with a newline" (test-equal "openntpd generated config string ends with a newline"
"\n"
(let ((config (openntpd-configuration->string %openntpd-conf-sample))) (let ((config (openntpd-configuration->string %openntpd-conf-sample)))
(string-take-right config 1)) (string-take-right config 1)))
"\n")
(test-end "networking") (test-end "networking")