version-control.scm 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017 Oleg Pykhalov <go.wigust@gmail.com>
  3. ;;; Copyright © 2017 Ludovic Courtès <ludo@gnu.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 version-control)
  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 version-control)
  27. #:use-module (gnu services web)
  28. #:use-module (gnu services networking)
  29. #:use-module (gnu packages version-control)
  30. #:use-module (guix gexp)
  31. #:use-module (guix store)
  32. #:export (%test-cgit))
  33. (define %make-git-repository
  34. ;; Create Git repository in /srv/git/test.
  35. #~(begin
  36. (mkdir-p "/srv/git/test")
  37. (system* (string-append #$git "/bin/git") "-C" "/srv/git/test"
  38. "init" "--bare")))
  39. (define %cgit-configuration-nginx
  40. (list
  41. (nginx-server-configuration
  42. (root cgit)
  43. (locations
  44. (list
  45. (nginx-location-configuration
  46. (uri "@cgit")
  47. (body '("fastcgi_param SCRIPT_FILENAME $document_root/lib/cgit/cgit.cgi;"
  48. "fastcgi_param PATH_INFO $uri;"
  49. "fastcgi_param QUERY_STRING $args;"
  50. "fastcgi_param HTTP_HOST $server_name;"
  51. "fastcgi_pass 127.0.0.1:9000;")))))
  52. (try-files (list "$uri" "@cgit"))
  53. (http-port 19418)
  54. (https-port #f)
  55. (ssl-certificate #f)
  56. (ssl-certificate-key #f))))
  57. (define %cgit-os
  58. ;; Operating system under test.
  59. (let ((base-os
  60. (simple-operating-system
  61. (dhcp-client-service)
  62. (service nginx-service-type)
  63. (service fcgiwrap-service-type)
  64. (service cgit-service-type
  65. (cgit-configuration
  66. (nginx %cgit-configuration-nginx)))
  67. (simple-service 'make-git-repository activation-service-type
  68. %make-git-repository))))
  69. (operating-system
  70. (inherit base-os)
  71. (packages (cons* git
  72. (operating-system-packages base-os))))))
  73. (define* (run-cgit-test #:optional (http-port 19418))
  74. "Run tests in %CGIT-OS, which has nginx running and listening on
  75. HTTP-PORT."
  76. (define os
  77. (marionette-operating-system
  78. %cgit-os
  79. #:imported-modules '((gnu services herd)
  80. (guix combinators))))
  81. (define vm
  82. (virtual-machine
  83. (operating-system os)
  84. (port-forwardings `((8080 . ,http-port)))))
  85. (define test
  86. (with-imported-modules '((gnu build marionette))
  87. #~(begin
  88. (use-modules (srfi srfi-11) (srfi srfi-64)
  89. (gnu build marionette)
  90. (web uri)
  91. (web client)
  92. (web response))
  93. (define marionette
  94. (make-marionette (list #$vm)))
  95. (mkdir #$output)
  96. (chdir #$output)
  97. (test-begin "cgit")
  98. ;; Wait for nginx to be up and running.
  99. (test-eq "service running"
  100. 'running!
  101. (marionette-eval
  102. '(begin
  103. (use-modules (gnu services herd))
  104. (start-service 'nginx)
  105. 'running!)
  106. marionette))
  107. ;; Wait for fcgiwrap to be up and running.
  108. (test-eq "service running"
  109. 'running!
  110. (marionette-eval
  111. '(begin
  112. (use-modules (gnu services herd))
  113. (start-service 'fcgiwrap)
  114. 'running!)
  115. marionette))
  116. ;; Make sure the PID file is created.
  117. (test-assert "PID file"
  118. (marionette-eval
  119. '(file-exists? "/var/run/nginx/pid")
  120. marionette))
  121. ;; Make sure the configuration file is created.
  122. (test-assert "configuration file"
  123. (marionette-eval
  124. '(file-exists? "/etc/cgitrc")
  125. marionette))
  126. ;; Make sure Git test repository is created.
  127. (test-assert "Git test repository"
  128. (marionette-eval
  129. '(file-exists? "/srv/git/test")
  130. marionette))
  131. ;; Make sure we can access pages that correspond to our repository.
  132. (letrec-syntax ((test-url
  133. (syntax-rules ()
  134. ((_ path code)
  135. (test-equal (string-append "GET " path)
  136. code
  137. (let-values (((response body)
  138. (http-get (string-append
  139. "http://localhost:8080"
  140. path))))
  141. (response-code response))))
  142. ((_ path)
  143. (test-url path 200)))))
  144. (test-url "/")
  145. (test-url "/test")
  146. (test-url "/test/log")
  147. (test-url "/test/tree")
  148. (test-url "/test/does-not-exist" 404)
  149. (test-url "/does-not-exist" 404))
  150. (test-end)
  151. (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
  152. (gexp->derivation "cgit-test" test))
  153. (define %test-cgit
  154. (system-test
  155. (name "cgit")
  156. (description "Connect to a running Cgit server.")
  157. (value (run-cgit-test))))