all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Robert Vollmert <rob@vllmrt.net>
To: 38429@debbugs.gnu.org
Cc: Robert Vollmert <rob@vllmrt.net>
Subject: [bug#38429] [PATCH 4/5] scron: add system test
Date: Tue,  3 Dec 2019 13:46:32 +0100	[thread overview]
Message-ID: <20191203124632.1987-4-rob@vllmrt.net> (raw)
In-Reply-To: <20191203124632.1987-1-rob@vllmrt.net>

---
 gnu/tests/base.scm | 86 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)

diff --git a/gnu/tests/base.scm b/gnu/tests/base.scm
index a891711844..b80e77be66 100644
--- a/gnu/tests/base.scm
+++ b/gnu/tests/base.scm
@@ -28,6 +28,7 @@
   #:use-module (gnu services dbus)
   #:use-module (gnu services avahi)
   #:use-module (gnu services mcron)
+  #:use-module (gnu services scron)
   #:use-module (gnu services shepherd)
   #:use-module (gnu services networking)
   #:use-module (gnu packages base)
@@ -48,6 +49,7 @@
             %test-halt
             %test-cleanup
             %test-mcron
+            %test-scron
             %test-nss-mdns))
 
 (define %simple-os
@@ -720,6 +722,90 @@ non-ASCII names from /tmp.")
    (description "Make sure the mcron service works as advertised.")
    (value (run-mcron-test name))))
 
+\f
+;;;
+;;; Scron.
+;;;
+
+(define %scron-os
+  ;; System with an scron service, with one scron job for "root" and one scron
+  ;; job for an unprivileged user.
+  (let ((job1
+         (scron-job
+          (schedule "* * * * *")
+          (command  "(id -u; id -g) > witness")))
+        (job2
+         (scron-job
+          (schedule "* * * * *")
+          (command  "su -c '(id -u; id -g) > ~/witness' alice")))
+        (job3
+         (scron-job
+          (schedule "* * * * *")
+          (command  "touch witness-touch"))))
+    (simple-operating-system
+     (service scron-service-type
+              (scron-configuration (jobs (list job1 job2 job3)))))))
+
+(define (run-scron-test name)
+  (define os
+    (marionette-operating-system
+     %scron-os
+     #:imported-modules '((gnu services herd)
+                          (guix combinators))))
+
+  (define test
+    (with-imported-modules '((gnu build marionette))
+      #~(begin
+          (use-modules (gnu build marionette)
+                       (srfi srfi-64)
+                       (ice-9 match))
+
+          (define marionette
+            (make-marionette (list #$(virtual-machine os))))
+
+          (mkdir #$output)
+          (chdir #$output)
+
+          (test-begin "scron")
+
+          (test-assert "service running"
+            (marionette-eval
+             '(begin
+                (use-modules (gnu services herd))
+                (start-service 'scron))
+             marionette))
+
+          ;; Make sure root's scron job runs, has its cwd set to "/", and
+          ;; runs with the right UID/GID.
+          (test-equal "root's job"
+            '(0 0)
+            (wait-for-file "/witness" marionette))
+
+          ;; Likewise for Alice's job.  We cannot know what its GID is since
+          ;; it's chosen by 'groupadd', but it's strictly positive.
+          (test-assert "alice's job"
+            (match (wait-for-file "/home/alice/witness" marionette)
+              ((1000 gid)
+               (>= gid 100))))
+
+          ;; Last, the job that uses a command; allows us to test whether
+          ;; $PATH is sane.
+          (test-equal "root's job with command"
+            ""
+            (wait-for-file "/witness-touch" marionette
+                           #:read '(@ (ice-9 rdelim) read-string)))
+
+          (test-end)
+          (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
+
+  (gexp->derivation name test))
+
+(define %test-scron
+  (system-test
+   (name "scron")
+   (description "Make sure the scron service works as advertised.")
+   (value (run-scron-test name))))
+
 \f
 ;;;
 ;;; Avahi and NSS-mDNS.
-- 
2.24.0

  parent reply	other threads:[~2019-12-03 12:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-29 17:53 [bug#38429] [PATCH] Add scron service Robert Vollmert
2019-11-29 18:07 ` Robert Vollmert
2019-12-02  9:01   ` Ludovic Courtès
2019-12-03 12:46 ` [bug#38429] [PATCH 1/5] document scron Robert Vollmert
2019-12-03 12:46   ` [bug#38429] [PATCH 2/5] scron-service: remove job defaults Robert Vollmert
2019-12-03 12:46   ` [bug#38429] [PATCH 3/5] scron: Add description Robert Vollmert
2019-12-03 12:46   ` Robert Vollmert [this message]
2019-12-03 12:50     ` [bug#38429] [PATCH 4/5] scron: add system test Robert Vollmert
2019-12-03 12:46   ` [bug#38429] [PATCH 5/5] gnu/services: Add description to mcron-service-type Robert Vollmert
2019-12-07 23:32   ` [bug#38429] [PATCH 1/5] document scron Ludovic Courtès
2019-12-07 23:43     ` Robert Vollmert
2019-12-07 23:46       ` bug#38429: " Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191203124632.1987-4-rob@vllmrt.net \
    --to=rob@vllmrt.net \
    --cc=38429@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.