rsync.scm 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. ;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  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. (define* (run-rsync-test rsync-os #:optional (rsync-port 873))
  34. "Run tests in %RSYNC-OS, which has rsync running and listening on
  35. PORT."
  36. (define os
  37. (marionette-operating-system
  38. rsync-os
  39. #:imported-modules '((gnu services herd)
  40. (guix combinators))))
  41. (define vm
  42. (virtual-machine
  43. (operating-system os)
  44. (port-forwardings '())))
  45. (define test
  46. (with-imported-modules '((gnu build marionette))
  47. #~(begin
  48. (use-modules (srfi srfi-11) (srfi srfi-64)
  49. (gnu build marionette))
  50. (define marionette
  51. (make-marionette (list #$vm)))
  52. (test-runner-current (system-test-runner #$output))
  53. (test-begin "rsync")
  54. ;; Wait for rsync to be up and running.
  55. (test-assert "service running"
  56. (marionette-eval
  57. '(begin
  58. (use-modules (gnu services herd))
  59. ;; Make sure the 'rsync' command is found.
  60. (setenv "PATH" "/run/current-system/profile/bin")
  61. (start-service 'rsync))
  62. marionette))
  63. ;; Make sure the PID file is created.
  64. (test-assert "PID file"
  65. (marionette-eval
  66. '(file-exists? "/var/run/rsyncd/rsyncd.pid")
  67. marionette))
  68. (test-assert "Test file copied to share"
  69. (marionette-eval
  70. '(begin
  71. (call-with-output-file "/tmp/input"
  72. (lambda (port)
  73. (display "test-file-contents\n" port)))
  74. (zero?
  75. (system* "rsync" "/tmp/input"
  76. (string-append "rsync://localhost:"
  77. (number->string #$rsync-port)
  78. "/files/input"))))
  79. marionette))
  80. (test-equal "Test file correctly received from share"
  81. "test-file-contents"
  82. (marionette-eval
  83. '(begin
  84. (use-modules (ice-9 rdelim))
  85. (zero?
  86. (system* "rsync"
  87. (string-append "rsync://localhost:"
  88. (number->string #$rsync-port)
  89. "/files/input")
  90. "/tmp/output"))
  91. (call-with-input-file "/tmp/output"
  92. (lambda (port)
  93. (read-line port))))
  94. marionette))
  95. (test-equal "Test file not copied to read-only share"
  96. 1 ;see "EXIT VALUES" in rsync(1)
  97. (marionette-eval
  98. '(status:exit-val
  99. (system* "rsync" "/tmp/input"
  100. (string-append "rsync://localhost:"
  101. (number->string #$rsync-port)
  102. "/read-only/input")))
  103. marionette))
  104. (test-equal "Test file correctly received from read-only share"
  105. "\"Hi!\" from the read-only share."
  106. (marionette-eval
  107. '(begin
  108. (use-modules (ice-9 rdelim))
  109. (call-with-output-file "/srv/read-only/the-file"
  110. (lambda (port)
  111. (display "\"Hi!\" from the read-only share." port)))
  112. (zero?
  113. (system* "rsync"
  114. (string-append "rsync://localhost:"
  115. (number->string #$rsync-port)
  116. "/read-only/the-file")
  117. "/tmp/output"))
  118. (call-with-input-file "/tmp/output" read-line))
  119. marionette))
  120. (test-end))))
  121. (gexp->derivation "rsync-test" test))
  122. (define* %rsync-os
  123. ;; Return operating system under test.
  124. (let ((base-os
  125. (simple-operating-system
  126. (service dhcp-client-service-type)
  127. (service rsync-service-type
  128. (rsync-configuration
  129. (modules (list (rsync-module
  130. (name "read-only")
  131. (file-name "/srv/read-only"))
  132. (rsync-module
  133. (name "files")
  134. (file-name "/srv/read-write")
  135. (read-only? #f)))))))))
  136. (operating-system
  137. (inherit base-os)
  138. (packages (cons* rsync
  139. (operating-system-packages base-os))))))
  140. (define %test-rsync
  141. (system-test
  142. (name "rsync")
  143. (description "Connect to a running RSYNC server.")
  144. (value (run-rsync-test %rsync-os))))