summary refs log tree commit diff
path: root/tests/system.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-08-30 22:40:24 +0200
committerLudovic Courtès <ludo@gnu.org>2016-08-31 15:44:20 +0200
commitb8692e4696d0d2b36466827da1e0d25d69a298af (patch)
treec073388b0b4761f0fa719bc3ba66f3964de3dfd9 /tests/system.scm
parent183605c8533ad321ff8bba209b64071a9e84714a (diff)
downloadguix-b8692e4696d0d2b36466827da1e0d25d69a298af.tar.gz
guix system: Extract and test the service upgrade procedure.
* guix/scripts/system.scm (service-upgrade): New procedure, with code
from...
(call-with-service-upgrade-info): ... here.  Use it.
* tests/system.scm (live-service, service-upgrade): New variables.
("service-upgrade: nothing to do", "service-upgrade: one unchanged, one
upgraded, one new"): New tests.
Diffstat (limited to 'tests/system.scm')
-rw-r--r--tests/system.scm34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/system.scm b/tests/system.scm
index b5bb9af016..dee6feda2c 100644
--- a/tests/system.scm
+++ b/tests/system.scm
@@ -19,6 +19,8 @@
 (define-module (test-system)
   #:use-module (gnu)
   #:use-module (guix store)
+  #:use-module (gnu services herd)
+  #:use-module (gnu services shepherd)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-64))
 
@@ -59,6 +61,11 @@
                         %base-file-systems))
     (users %base-user-accounts)))
 
+(define live-service
+  (@@ (gnu services herd) live-service))
+
+(define service-upgrade
+  (@@ (guix scripts system) service-upgrade))
 
 (test-begin "system")
 
@@ -114,4 +121,31 @@
                            (type "ext4"))
                          %base-file-systems)))))
 
+(test-equal "service-upgrade: nothing to do"
+  '(() ())
+  (call-with-values
+      (lambda ()
+        (service-upgrade '() '()))
+    list))
+
+(test-equal "service-upgrade: one unchanged, one upgraded, one new"
+  '((bar)                                         ;unload
+    ((bar) (baz)))                                ;load
+  (call-with-values
+      (lambda ()
+        ;; Here 'foo' is not upgraded because it is still running, whereas
+        ;; 'bar' is upgraded because it is not currently running.  'baz' is
+        ;; loaded because it's a new service.
+        (service-upgrade (list (live-service '(foo) '() #t)
+                               (live-service '(bar) '() #f)
+                               (live-service '(root) '() #t)) ;essential!
+                         (list (shepherd-service (provision '(foo))
+                                                 (start #t))
+                               (shepherd-service (provision '(bar))
+                                                 (start #t))
+                               (shepherd-service (provision '(baz))
+                                                 (start #t)))))
+    (lambda (unload load)
+      (list unload (map shepherd-service-provision load)))))
+
 (test-end)