rsync.scm 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. (test-assert "Test file copied to share"
  64. (marionette-eval
  65. '(begin
  66. (call-with-output-file "/tmp/input"
  67. (lambda (port)
  68. (display "test-file-contents\n" port)))
  69. (zero?
  70. (system* "rsync" "/tmp/input"
  71. (string-append "rsync://localhost:"
  72. (number->string #$rsync-port)
  73. "/files/input"))))
  74. marionette))
  75. (test-equal "Test file correctly received from share"
  76. "test-file-contents"
  77. (marionette-eval
  78. '(begin
  79. (use-modules (ice-9 rdelim))
  80. (zero?
  81. (system* "rsync"
  82. (string-append "rsync://localhost:"
  83. (number->string #$rsync-port)
  84. "/files/input")
  85. "/tmp/output"))
  86. (call-with-input-file "/tmp/output"
  87. (lambda (port)
  88. (read-line port))))
  89. marionette))
  90. (test-equal "Test file not copied to read-only share"
  91. 1 ;see "EXIT VALUES" in rsync(1)
  92. (marionette-eval
  93. '(status:exit-val
  94. (system* "rsync" "/tmp/input"
  95. (string-append "rsync://localhost:"
  96. (number->string #$rsync-port)
  97. "/read-only/input")))
  98. marionette))
  99. (test-equal "Test file correctly received from read-only share"
  100. "\"Hi!\" from the read-only share."
  101. (marionette-eval
  102. '(begin
  103. (use-modules (ice-9 rdelim))
  104. (call-with-output-file "/srv/read-only/the-file"
  105. (lambda (port)
  106. (display "\"Hi!\" from the read-only share." port)))
  107. (zero?
  108. (system* "rsync"
  109. (string-append "rsync://localhost:"
  110. (number->string #$rsync-port)
  111. "/read-only/the-file")
  112. "/tmp/output"))
  113. (call-with-input-file "/tmp/output" read-line))
  114. marionette))
  115. (test-end))))
  116. (gexp->derivation "rsync-test" test))
  117. (define* %rsync-os
  118. ;; Return operating system under test.
  119. (let ((base-os
  120. (simple-operating-system
  121. (service dhcp-client-service-type)
  122. (service rsync-service-type
  123. (rsync-configuration
  124. (modules (list (rsync-module
  125. (name "read-only")
  126. (file-name "/srv/read-only"))
  127. (rsync-module
  128. (name "files")
  129. (file-name "/srv/read-write")
  130. (read-only? #f)))))))))
  131. (operating-system
  132. (inherit base-os)
  133. (packages (cons* rsync
  134. (operating-system-packages base-os))))))
  135. (define %test-rsync
  136. (system-test
  137. (name "rsync")
  138. (description "Connect to a running RSYNC server.")
  139. (value (run-rsync-test %rsync-os))))