gnu: Add python-tappy.
[jackhill/guix/guix.git] / tests / services / configuration.scm
CommitLineData
a77e3a58
MC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2021 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 services linux)
20 #:use-module (gnu services configuration)
21 #:use-module (guix gexp)
22 #:use-module (srfi srfi-34)
23 #:use-module (srfi srfi-64))
24
25;;; Tests for the (gnu services configuration) module.
26
27(test-begin "services-configuration")
28
29\f
30;;;
31;;; define-configuration macro.
32;;;
33
34(define-configuration port-configuration
35 (port (number 80) "The port number.")
36 (no-serialization))
37
38(test-equal "default value, no serialization"
39 80
40 (port-configuration-port (port-configuration)))
41
42(define-configuration port-configuration-cs
43 (port (number 80) "The port number." empty-serializer))
44
45(test-equal "default value, custom serializer"
46 80
47 (port-configuration-cs-port (port-configuration-cs)))
48
49(define serialize-number "")
50(define-configuration port-configuration-ndv
51 (port (number) "The port number."))
52
53(test-equal "no default value, provided"
54 55
55 (port-configuration-ndv-port (port-configuration-ndv
56 (port 55))))
57
58(test-assert "no default value, not provided"
59 (guard (c ((configuration-error? c)
60 #t))
61 (port-configuration-ndv-port (port-configuration-ndv))))
62
63(define (custom-number-serializer name value)
64 (format #t "~a = ~a;" name value))
65
66(define-configuration serializable-configuration
67 (port (number 80) "The port number." custom-number-serializer))
68
69(test-assert "serialize-configuration"
70 (gexp?
71 (let ((config (serializable-configuration)))
72 (serialize-configuration config serializable-configuration-fields))))
73
74(define-configuration serializable-configuration
75 (port (number 80) "The port number." custom-number-serializer)
76 (no-serialization))
77
78(test-assert "serialize-configuration with no-serialization"
79 ;; When serialization is disabled, the serializer is set to #f, so
80 ;; attempting to use it fails with a 'wrong-type-arg' error.
81 (not (false-if-exception
82 (let ((config (serializable-configuration)))
83 (serialize-configuration config serializable-configuration-fields)))))