rsync.scm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017 Christopher Baines <mail@cbaines.net>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gnu tests rsync)
  19. #:use-module (gnu packages rsync)
  20. #:use-module (gnu tests)
  21. #:use-module (gnu system)
  22. #:use-module (gnu system file-systems)
  23. #:use-module (gnu system shadow)
  24. #:use-module (gnu system vm)
  25. #:use-module (gnu services)
  26. #:use-module (gnu services rsync)
  27. #:use-module (gnu services networking)
  28. #:use-module (guix gexp)
  29. #:use-module (guix store)
  30. #:export (%test-rsync))
  31. (define* (run-rsync-test rsync-os #:optional (rsync-port 873))
  32. "Run tests in %RSYNC-OS, which has rsync running and listening on
  33. PORT."
  34. (define os
  35. (marionette-operating-system
  36. rsync-os
  37. #:imported-modules '((gnu services herd)
  38. (guix combinators))))
  39. (define vm
  40. (virtual-machine
  41. (operating-system os)
  42. (port-forwardings '())))
  43. (define test
  44. (with-imported-modules '((gnu build marionette))
  45. #~(begin
  46. (use-modules (srfi srfi-11) (srfi srfi-64)
  47. (gnu build marionette))
  48. (define marionette
  49. (make-marionette (list #$vm)))
  50. (mkdir #$output)
  51. (chdir #$output)
  52. (test-begin "rsync")
  53. ;; Wait for rsync to be up and running.
  54. (test-eq "service running"
  55. 'running!
  56. (marionette-eval
  57. '(begin
  58. (use-modules (gnu services herd))
  59. (start-service 'rsync)
  60. 'running!)
  61. marionette))
  62. ;; Make sure the PID file is created.
  63. (test-assert "PID file"
  64. (marionette-eval
  65. '(file-exists? "/var/run/rsyncd/rsyncd.pid")
  66. marionette))
  67. (test-assert "Test file copied to share"
  68. (marionette-eval
  69. '(begin
  70. (call-with-output-file "/tmp/input"
  71. (lambda (port)
  72. (display "test-file-contents\n" port)))
  73. (zero?
  74. (system* "rsync" "/tmp/input"
  75. (string-append "rsync://localhost:"
  76. (number->string #$rsync-port)
  77. "/files/input"))))
  78. marionette))
  79. (test-equal "Test file correctly received from share"
  80. "test-file-contents"
  81. (marionette-eval
  82. '(begin
  83. (use-modules (ice-9 rdelim))
  84. (zero?
  85. (system* "rsync"
  86. (string-append "rsync://localhost:"
  87. (number->string #$rsync-port)
  88. "/files/input")
  89. "/tmp/output"))
  90. (call-with-input-file "/tmp/output"
  91. (lambda (port)
  92. (read-line port))))
  93. marionette))
  94. (test-end)
  95. (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
  96. (gexp->derivation "rsync-test" test))
  97. (define* %rsync-os
  98. ;; Return operating system under test.
  99. (let ((base-os
  100. (simple-operating-system
  101. (dhcp-client-service)
  102. (service rsync-service-type))))
  103. (operating-system
  104. (inherit base-os)
  105. (packages (cons* rsync
  106. (operating-system-packages base-os))))))
  107. (define %test-rsync
  108. (system-test
  109. (name "rsync")
  110. (description "Connect to a running RSYNC server.")
  111. (value (run-rsync-test %rsync-os))))