summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2025-02-27 10:49:58 +0100
committerLudovic Courtès <ludo@gnu.org>2025-03-10 15:41:33 +0100
commit7e4627f9c7a160a7ad997437b3fdbc589047a314 (patch)
treef17adef568394894e00be6a06b0e45a637a61fa4 /gnu
parentab18efcf40dabe379509abb7c2372de7035fcf45 (diff)
tests: Move mcron test to its own file.
This mirrors the (gnu services mcron) module. * gnu/tests/base.scm (%mcron-os, run-mcron-test, %test-mcron): Move to… * gnu/tests/mcron.scm: … here. New file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add it. Change-Id: Id2830d08d8e797e008c5fec7964fb5f6a5ea2fad
Diffstat (limited to 'gnu')
-rw-r--r--gnu/local.mk1
-rw-r--r--gnu/tests/base.scm92
-rw-r--r--gnu/tests/mcron.scm118
3 files changed, 119 insertions, 92 deletions
diff --git a/gnu/local.mk b/gnu/local.mk
index 880af091685..45d9e859b7c 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -864,6 +864,7 @@ GNU_SYSTEM_MODULES = \
%D%/tests/lightdm.scm \
%D%/tests/linux-modules.scm \
%D%/tests/mail.scm \
+ %D%/tests/mcron.scm \
%D%/tests/messaging.scm \
%D%/tests/networking.scm \
%D%/tests/package-management.scm \
diff --git a/gnu/tests/base.scm b/gnu/tests/base.scm
index 223a27be1fe..96dbadfc096 100644
--- a/gnu/tests/base.scm
+++ b/gnu/tests/base.scm
@@ -33,7 +33,6 @@
#:use-module (gnu services base)
#:use-module (gnu services dbus)
#:use-module (gnu services avahi)
- #:use-module (gnu services mcron)
#:use-module (gnu services shepherd)
#:use-module (gnu services networking)
#:use-module (gnu packages base)
@@ -60,7 +59,6 @@
%test-halt
%test-root-unmount
%test-cleanup
- %test-mcron
%test-nss-mdns
%test-activation))
@@ -874,96 +872,6 @@ non-ASCII names from /tmp.")
;;;
-;;; Mcron.
-;;;
-
-(define %mcron-os
- ;; System with an mcron service, with one mcron job for "root" and one mcron
- ;; job for an unprivileged user.
- (let ((job1 #~(job '(next-second '(0 5 10 15 20 25 30 35 40 45 50 55))
- (lambda ()
- (unless (file-exists? "witness")
- (call-with-output-file "witness"
- (lambda (port)
- (display (list (getuid) (getgid)) port)))))))
- (job2 #~(job next-second-from
- (lambda ()
- (call-with-output-file "witness"
- (lambda (port)
- (display (list (getuid) (getgid)) port))))
- #:user "alice"))
- (job3 #~(job next-second-from ;to test $PATH
- "touch witness-touch")))
- (simple-operating-system
- (service mcron-service-type
- (mcron-configuration (jobs (list job1 job2 job3)))))))
-
-(define (run-mcron-test name)
- (define os
- (marionette-operating-system
- %mcron-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))))
-
- (test-runner-current (system-test-runner #$output))
- (test-begin "mcron")
-
- (test-assert "service running"
- (marionette-eval
- '(begin
- (use-modules (gnu services herd))
- (start-service 'mcron))
- marionette))
-
- ;; Make sure root's mcron job runs, has its cwd set to "/root", and
- ;; runs with the right UID/GID.
- (test-equal "root's job"
- '(0 0)
- (wait-for-file "/root/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 "/root/witness-touch" marionette
- #:read '(@ (ice-9 rdelim) read-string)))
-
- ;; Make sure the 'schedule' action is accepted.
- (test-equal "schedule action"
- '(#t) ;one value, #t
- (marionette-eval '(with-shepherd-action 'mcron ('schedule) result
- result)
- marionette))
-
- (test-end))))
-
- (gexp->derivation name test))
-
-(define %test-mcron
- (system-test
- (name "mcron")
- (description "Make sure the mcron service works as advertised.")
- (value (run-mcron-test name))))
-
-
-;;;
;;; Avahi and NSS-mDNS.
;;;
diff --git a/gnu/tests/mcron.scm b/gnu/tests/mcron.scm
new file mode 100644
index 00000000000..052c8439cc7
--- /dev/null
+++ b/gnu/tests/mcron.scm
@@ -0,0 +1,118 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2016-2020, 2022, 2024 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
+;;;
+;;; 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 (gnu tests mcron)
+ #:use-module (gnu tests)
+ #:use-module (gnu system)
+ #:use-module (gnu system vm)
+ #:use-module (gnu services)
+ #:use-module (gnu services mcron)
+ #:use-module (guix gexp)
+ #:use-module (guix store)
+ #:use-module (guix monads)
+ #:export (%test-mcron))
+
+;;;
+;;; Mcron.
+;;;
+
+(define %mcron-os
+ ;; System with an mcron service, with one mcron job for "root" and one mcron
+ ;; job for an unprivileged user.
+ (let ((job1 #~(job '(next-second '(0 5 10 15 20 25 30 35 40 45 50 55))
+ (lambda ()
+ (unless (file-exists? "witness")
+ (call-with-output-file "witness"
+ (lambda (port)
+ (display (list (getuid) (getgid)) port)))))))
+ (job2 #~(job next-second-from
+ (lambda ()
+ (call-with-output-file "witness"
+ (lambda (port)
+ (display (list (getuid) (getgid)) port))))
+ #:user "alice"))
+ (job3 #~(job next-second-from ;to test $PATH
+ "touch witness-touch")))
+ (simple-operating-system
+ (service mcron-service-type
+ (mcron-configuration (jobs (list job1 job2 job3)))))))
+
+(define (run-mcron-test name)
+ (define os
+ (marionette-operating-system
+ %mcron-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))))
+
+ (test-runner-current (system-test-runner #$output))
+ (test-begin "mcron")
+
+ (test-assert "service running"
+ (marionette-eval
+ '(begin
+ (use-modules (gnu services herd))
+ (start-service 'mcron))
+ marionette))
+
+ ;; Make sure root's mcron job runs, has its cwd set to "/root", and
+ ;; runs with the right UID/GID.
+ (test-equal "root's job"
+ '(0 0)
+ (wait-for-file "/root/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 "/root/witness-touch" marionette
+ #:read '(@ (ice-9 rdelim) read-string)))
+
+ ;; Make sure the 'schedule' action is accepted.
+ (test-equal "schedule action"
+ '(#t) ;one value, #t
+ (marionette-eval '(with-shepherd-action 'mcron ('schedule) result
+ result)
+ marionette))
+
+ (test-end))))
+
+ (gexp->derivation name test))
+
+(define %test-mcron
+ (system-test
+ (name "mcron")
+ (description "Make sure the mcron service works as advertised.")
+ (value (run-mcron-test name))))