[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
05/06: services: configuration: Add tests.
From: |
guix-commits |
Subject: |
05/06: services: configuration: Add tests. |
Date: |
Sat, 8 May 2021 01:06:18 -0400 (EDT) |
apteryx pushed a commit to branch master
in repository guix.
commit a77e3a5846d8b4b4b8d0fe4887d1ee17340971e0
Author: Maxim Cournoyer <maxim.cournoyer@gmail.com>
AuthorDate: Sat May 8 00:05:27 2021 -0400
services: configuration: Add tests.
* tests/services/configuration.scm: New file.
* Makefile.am (SCM_TESTS): Register it.
---
Makefile.am | 1 +
tests/services/configuration.scm | 83 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+)
diff --git a/Makefile.am b/Makefile.am
index e6a7b54..a310de8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -484,6 +484,7 @@ SCM_TESTS = \
tests/search-paths.scm \
tests/services.scm \
tests/services/file-sharing.scm \
+ tests/services/configuration.scm \
tests/services/linux.scm \
tests/sets.scm \
tests/size.scm \
diff --git a/tests/services/configuration.scm b/tests/services/configuration.scm
new file mode 100644
index 0000000..21ad188
--- /dev/null
+++ b/tests/services/configuration.scm
@@ -0,0 +1,83 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (tests services linux)
+ #:use-module (gnu services configuration)
+ #:use-module (guix gexp)
+ #:use-module (srfi srfi-34)
+ #:use-module (srfi srfi-64))
+
+;;; Tests for the (gnu services configuration) module.
+
+(test-begin "services-configuration")
+
+
+;;;
+;;; define-configuration macro.
+;;;
+
+(define-configuration port-configuration
+ (port (number 80) "The port number.")
+ (no-serialization))
+
+(test-equal "default value, no serialization"
+ 80
+ (port-configuration-port (port-configuration)))
+
+(define-configuration port-configuration-cs
+ (port (number 80) "The port number." empty-serializer))
+
+(test-equal "default value, custom serializer"
+ 80
+ (port-configuration-cs-port (port-configuration-cs)))
+
+(define serialize-number "")
+(define-configuration port-configuration-ndv
+ (port (number) "The port number."))
+
+(test-equal "no default value, provided"
+ 55
+ (port-configuration-ndv-port (port-configuration-ndv
+ (port 55))))
+
+(test-assert "no default value, not provided"
+ (guard (c ((configuration-error? c)
+ #t))
+ (port-configuration-ndv-port (port-configuration-ndv))))
+
+(define (custom-number-serializer name value)
+ (format #t "~a = ~a;" name value))
+
+(define-configuration serializable-configuration
+ (port (number 80) "The port number." custom-number-serializer))
+
+(test-assert "serialize-configuration"
+ (gexp?
+ (let ((config (serializable-configuration)))
+ (serialize-configuration config serializable-configuration-fields))))
+
+(define-configuration serializable-configuration
+ (port (number 80) "The port number." custom-number-serializer)
+ (no-serialization))
+
+(test-assert "serialize-configuration with no-serialization"
+ ;; When serialization is disabled, the serializer is set to #f, so
+ ;; attempting to use it fails with a 'wrong-type-arg' error.
+ (not (false-if-exception
+ (let ((config (serializable-configuration)))
+ (serialize-configuration config
serializable-configuration-fields)))))
- branch master updated (b4ab965 -> a9a67da), guix-commits, 2021/05/08
- 03/06: services: configuration: Allow specifying a custom serializer., guix-commits, 2021/05/08
- 01/06: services: configuration: Avoid a compilation warning., guix-commits, 2021/05/08
- 02/06: services: configuration: Allow disabling serialization., guix-commits, 2021/05/08
- 04/06: services: configuration: Fix %location accessor name., guix-commits, 2021/05/08
- 05/06: services: configuration: Add tests.,
guix-commits <=
- 06/06: services: docker: Disable configuration serialization., guix-commits, 2021/05/08