| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 |
|
| 20 | (define-module (gnu tests mcron)
|
| 21 | #:use-module (gnu tests)
|
| 22 | #:use-module (gnu system)
|
| 23 | #:use-module (gnu system vm)
|
| 24 | #:use-module (gnu services)
|
| 25 | #:use-module (gnu services mcron)
|
| 26 | #:use-module (guix gexp)
|
| 27 | #:use-module (guix store)
|
| 28 | #:use-module (guix monads)
|
| 29 | #:export (%test-mcron))
|
| 30 |
|
| 31 | |
| 32 | |
| 33 | |
| 34 |
|
| 35 | (define %mcron-os
|
| 36 | |
| 37 | |
| 38 | (let ((job1 #~(job '(next-second '(0 5 10 15 20 25 30 35 40 45 50 55))
|
| 39 | (lambda ()
|
| 40 | (unless (file-exists? "witness")
|
| 41 | (call-with-output-file "witness"
|
| 42 | (lambda (port)
|
| 43 | (display (list (getuid) (getgid)) port)))))))
|
| 44 | (job2 #~(job next-second-from
|
| 45 | (lambda ()
|
| 46 | (call-with-output-file "witness"
|
| 47 | (lambda (port)
|
| 48 | (display (list (getuid) (getgid)) port))))
|
| 49 | #:user "alice"))
|
| 50 | (job3 #~(job next-second-from |
| 51 | "touch witness-touch")))
|
| 52 | (simple-operating-system
|
| 53 | (service mcron-service-type
|
| 54 | (mcron-configuration (jobs (list job1 job2 job3)))))))
|
| 55 |
|
| 56 | (define (run-mcron-test name)
|
| 57 | (define os
|
| 58 | (marionette-operating-system
|
| 59 | %mcron-os
|
| 60 | #:imported-modules '((gnu services herd)
|
| 61 | (guix combinators))))
|
| 62 |
|
| 63 | (define test
|
| 64 | (with-imported-modules '((gnu build marionette))
|
| 65 | #~(begin
|
| 66 | (use-modules (gnu build marionette)
|
| 67 | (srfi srfi-64)
|
| 68 | (ice-9 match))
|
| 69 |
|
| 70 | (define marionette
|
| 71 | (make-marionette (list #$(virtual-machine os))))
|
| 72 |
|
| 73 | (test-runner-current (system-test-runner #$output))
|
| 74 | (test-begin "mcron")
|
| 75 |
|
| 76 | (test-assert "service running"
|
| 77 | (marionette-eval
|
| 78 | '(begin
|
| 79 | (use-modules (gnu services herd))
|
| 80 | (start-service 'mcron))
|
| 81 | marionette))
|
| 82 |
|
| 83 | |
| 84 | |
| 85 | (test-equal "root's job"
|
| 86 | '(0 0)
|
| 87 | (wait-for-file "/root/witness" marionette))
|
| 88 |
|
| 89 | |
| 90 | |
| 91 | (test-assert "alice's job"
|
| 92 | (match (wait-for-file "/home/alice/witness" marionette)
|
| 93 | ((1000 gid)
|
| 94 | (>= gid 100))))
|
| 95 |
|
| 96 | |
| 97 | |
| 98 | (test-equal "root's job with command"
|
| 99 | ""
|
| 100 | (wait-for-file "/root/witness-touch" marionette
|
| 101 | #:read '(@ (ice-9 rdelim) read-string)))
|
| 102 |
|
| 103 | |
| 104 | (test-equal "schedule action"
|
| 105 | '(#t) |
| 106 | (marionette-eval '(with-shepherd-action 'mcron ('schedule) result
|
| 107 | result)
|
| 108 | marionette))
|
| 109 |
|
| 110 | (test-end))))
|
| 111 |
|
| 112 | (gexp->derivation name test))
|
| 113 |
|
| 114 | (define %test-mcron
|
| 115 | (system-test
|
| 116 | (name "mcron")
|
| 117 | (description "Make sure the mcron service works as advertised.")
|
| 118 | (value (run-mcron-test name))))
|