gnu: Add rsync service.
[jackhill/guix/guix.git] / gnu / tests / rsync.scm
CommitLineData
9db7e9be
OP
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 Christopher Baines <mail@cbaines.net>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (gnu tests rsync)
20 #:use-module (gnu packages rsync)
21 #:use-module (gnu tests)
22 #:use-module (gnu system)
23 #:use-module (gnu system file-systems)
24 #:use-module (gnu system shadow)
25 #:use-module (gnu system vm)
26 #:use-module (gnu services)
27 #:use-module (gnu services rsync)
28 #:use-module (gnu services networking)
29 #:use-module (guix gexp)
30 #:use-module (guix store)
31 #:export (%test-rsync))
32
33(define* (run-rsync-test rsync-os #:optional (rsync-port 873))
34 "Run tests in %RSYNC-OS, which has rsync running and listening on
35PORT."
36 (define os
37 (marionette-operating-system
38 rsync-os
39 #:imported-modules '((gnu services herd)
40 (guix combinators))))
41
42 (define vm
43 (virtual-machine
44 (operating-system os)
45 (port-forwardings '())))
46
47 (define test
48 (with-imported-modules '((gnu build marionette))
49 #~(begin
50 (use-modules (srfi srfi-11) (srfi srfi-64)
51 (gnu build marionette))
52
53 (define marionette
54 (make-marionette (list #$vm)))
55
56 (mkdir #$output)
57 (chdir #$output)
58
59 (test-begin "rsync")
60
61 ;; Wait for rsync to be up and running.
62 (test-eq "service running"
63 'running!
64 (marionette-eval
65 '(begin
66 (use-modules (gnu services herd))
67 (start-service 'rsync)
68 'running!)
69 marionette))
70
71 ;; Make sure the PID file is created.
72 (test-assert "PID file"
73 (marionette-eval
74 '(file-exists? "/var/run/rsyncd/rsyncd.pid")
75 marionette))
76
77 (test-assert "Test file copied to share"
78 (marionette-eval
79 '(begin
80 (call-with-output-file "/tmp/input"
81 (lambda (port)
82 (display "test-file-contents\n" port)))
83 (zero?
84 (system* "rsync" "/tmp/input"
85 (string-append "rsync://localhost:"
86 (number->string #$rsync-port)
87 "/files/input"))))
88 marionette))
89
90 (test-equal "Test file correctly received from share"
91 "test-file-contents"
92 (marionette-eval
93 '(begin
94 (use-modules (ice-9 rdelim))
95 (zero?
96 (system* "rsync"
97 (string-append "rsync://localhost:"
98 (number->string #$rsync-port)
99 "/files/input")
100 "/tmp/output"))
101 (call-with-input-file "/tmp/output"
102 (lambda (port)
103 (read-line port))))
104 marionette))
105
106 (test-end)
107 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
108
109 (gexp->derivation "rsync-test" test))
110
111(define* %rsync-os
112 ;; Return operating system under test.
113 (let ((base-os
114 (simple-operating-system
115 (dhcp-client-service)
116 (service rsync-service-type))))
117 (operating-system
118 (inherit base-os)
119 (packages (cons* rsync
120 (operating-system-packages base-os))))))
121
122(define %test-rsync
123 (system-test
124 (name "rsync")
125 (description "Connect to a running RSYNC server.")
126 (value (run-rsync-test %rsync-os))))