rsync.scm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. (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. (define* (run-rsync-test rsync-os #:optional (rsync-port 873))
  33. "Run tests in %RSYNC-OS, which has rsync running and listening on
  34. PORT."
  35. (define os
  36. (marionette-operating-system
  37. rsync-os
  38. #:imported-modules '((gnu services herd)
  39. (guix combinators))))
  40. (define vm
  41. (virtual-machine
  42. (operating-system os)
  43. (port-forwardings '())))
  44. (define test
  45. (with-imported-modules '((gnu build marionette))
  46. #~(begin
  47. (use-modules (srfi srfi-11) (srfi srfi-64)
  48. (gnu build marionette))
  49. (define marionette
  50. (make-marionette (list #$vm)))
  51. (mkdir #$output)
  52. (chdir #$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-end)
  96. (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
  97. (gexp->derivation "rsync-test" test))
  98. (define* %rsync-os
  99. ;; Return operating system under test.
  100. (let ((base-os
  101. (simple-operating-system
  102. (service dhcp-client-service-type)
  103. (service rsync-service-type))))
  104. (operating-system
  105. (inherit base-os)
  106. (packages (cons* rsync
  107. (operating-system-packages base-os))))))
  108. (define %test-rsync
  109. (system-test
  110. (name "rsync")
  111. (description "Connect to a running RSYNC server.")
  112. (value (run-rsync-test %rsync-os))))