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