Commit | Line | Data |
---|---|---|
9db7e9be OP |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2017 Christopher Baines <mail@cbaines.net> | |
c24b1547 | 3 | ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org> |
9db7e9be OP |
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. | |
c24b1547 | 63 | (test-assert "service running" |
9db7e9be OP |
64 | (marionette-eval |
65 | '(begin | |
66 | (use-modules (gnu services herd)) | |
4df02ab6 LC |
67 | |
68 | ;; Make sure the 'rsync' command is found. | |
69 | (setenv "PATH" "/run/current-system/profile/bin") | |
70 | ||
c24b1547 | 71 | (start-service 'rsync)) |
9db7e9be OP |
72 | marionette)) |
73 | ||
74 | ;; Make sure the PID file is created. | |
75 | (test-assert "PID file" | |
76 | (marionette-eval | |
77 | '(file-exists? "/var/run/rsyncd/rsyncd.pid") | |
78 | marionette)) | |
79 | ||
80 | (test-assert "Test file copied to share" | |
81 | (marionette-eval | |
82 | '(begin | |
83 | (call-with-output-file "/tmp/input" | |
84 | (lambda (port) | |
85 | (display "test-file-contents\n" port))) | |
86 | (zero? | |
87 | (system* "rsync" "/tmp/input" | |
88 | (string-append "rsync://localhost:" | |
89 | (number->string #$rsync-port) | |
90 | "/files/input")))) | |
91 | marionette)) | |
92 | ||
93 | (test-equal "Test file correctly received from share" | |
94 | "test-file-contents" | |
95 | (marionette-eval | |
96 | '(begin | |
97 | (use-modules (ice-9 rdelim)) | |
98 | (zero? | |
99 | (system* "rsync" | |
100 | (string-append "rsync://localhost:" | |
101 | (number->string #$rsync-port) | |
102 | "/files/input") | |
103 | "/tmp/output")) | |
104 | (call-with-input-file "/tmp/output" | |
105 | (lambda (port) | |
106 | (read-line port)))) | |
107 | marionette)) | |
108 | ||
109 | (test-end) | |
110 | (exit (= (test-runner-fail-count (test-runner-current)) 0))))) | |
111 | ||
112 | (gexp->derivation "rsync-test" test)) | |
113 | ||
114 | (define* %rsync-os | |
115 | ;; Return operating system under test. | |
116 | (let ((base-os | |
117 | (simple-operating-system | |
39d7fdce | 118 | (service dhcp-client-service-type) |
9db7e9be OP |
119 | (service rsync-service-type)))) |
120 | (operating-system | |
121 | (inherit base-os) | |
122 | (packages (cons* rsync | |
123 | (operating-system-packages base-os)))))) | |
124 | ||
125 | (define %test-rsync | |
126 | (system-test | |
127 | (name "rsync") | |
128 | (description "Connect to a running RSYNC server.") | |
129 | (value (run-rsync-test %rsync-os)))) |