rsync.scm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. (start-service 'rsync))
  60. marionette))
  61. ;; Make sure the PID file is created.
  62. (test-assert "PID file"
  63. (marionette-eval
  64. '(file-exists? "/var/run/rsyncd/rsyncd.pid")
  65. marionette))
  66. (test-assert "Test file copied to share"
  67. (marionette-eval
  68. '(begin
  69. (call-with-output-file "/tmp/input"
  70. (lambda (port)
  71. (display "test-file-contents\n" port)))
  72. (zero?
  73. (system* "rsync" "/tmp/input"
  74. (string-append "rsync://localhost:"
  75. (number->string #$rsync-port)
  76. "/files/input"))))
  77. marionette))
  78. (test-equal "Test file correctly received from share"
  79. "test-file-contents"
  80. (marionette-eval
  81. '(begin
  82. (use-modules (ice-9 rdelim))
  83. (zero?
  84. (system* "rsync"
  85. (string-append "rsync://localhost:"
  86. (number->string #$rsync-port)
  87. "/files/input")
  88. "/tmp/output"))
  89. (call-with-input-file "/tmp/output"
  90. (lambda (port)
  91. (read-line port))))
  92. marionette))
  93. (test-end)
  94. (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
  95. (gexp->derivation "rsync-test" test))
  96. (define* %rsync-os
  97. ;; Return operating system under test.
  98. (let ((base-os
  99. (simple-operating-system
  100. (service dhcp-client-service-type)
  101. (service rsync-service-type))))
  102. (operating-system
  103. (inherit base-os)
  104. (packages (cons* rsync
  105. (operating-system-packages base-os))))))
  106. (define %test-rsync
  107. (system-test
  108. (name "rsync")
  109. (description "Connect to a running RSYNC server.")
  110. (value (run-rsync-test %rsync-os))))