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>
5 ;;; This file is part of GNU Guix.
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.
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.
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/>.
20 (define-module (gnu tests version-control)
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 version-control)
28 #:use-module (gnu services web)
29 #:use-module (gnu services networking)
30 #:use-module (gnu packages version-control)
31 #:use-module (guix gexp)
32 #:use-module (guix store)
33 #:export (%test-cgit))
35 (define %make-git-repository
36 ;; Create Git repository in /srv/git/test.
38 (mkdir-p "/srv/git/test")
39 (system* (string-append #$git "/bin/git") "-C" "/srv/git/test"
42 (define %cgit-configuration-nginx
44 (nginx-server-configuration
48 (nginx-location-configuration
50 (body '("fastcgi_param SCRIPT_FILENAME $document_root/lib/cgit/cgit.cgi;"
51 "fastcgi_param PATH_INFO $uri;"
52 "fastcgi_param QUERY_STRING $args;"
53 "fastcgi_param HTTP_HOST $server_name;"
54 "fastcgi_pass 127.0.0.1:9000;")))))
55 (try-files (list "$uri" "@cgit"))
59 (ssl-certificate-key #f))))
62 ;; Operating system under test.
64 (simple-operating-system
66 (service nginx-service-type)
67 (service fcgiwrap-service-type)
68 (service cgit-service-type
70 (nginx %cgit-configuration-nginx)))
71 (simple-service 'make-git-repository activation-service-type
72 %make-git-repository))))
76 (operating-system-packages base-os))))))
78 (define* (run-cgit-test #:optional (http-port 19418))
79 "Run tests in %CGIT-OS, which has nginx running and listening on
82 (marionette-operating-system
84 #:imported-modules '((gnu services herd)
90 (port-forwardings `((8080 . ,http-port)))))
93 (with-imported-modules '((gnu build marionette))
95 (use-modules (srfi srfi-11) (srfi srfi-64)
96 (gnu build marionette)
102 (make-marionette (list #$vm)))
109 ;; Wait for nginx to be up and running.
110 (test-eq "service running"
114 (use-modules (gnu services herd))
115 (start-service 'nginx)
119 ;; Wait for fcgiwrap to be up and running.
120 (test-eq "service running"
124 (use-modules (gnu services herd))
125 (start-service 'fcgiwrap)
129 ;; Make sure the PID file is created.
130 (test-assert "PID file"
132 '(file-exists? "/var/run/nginx/pid")
135 ;; Make sure the configuration file is created.
136 (test-assert "configuration file"
138 '(file-exists? "/etc/cgitrc")
141 ;; Make sure Git test repository is created.
142 (test-assert "Git test repository"
144 '(file-exists? "/srv/git/test")
147 ;; Make sure we can access pages that correspond to our repository.
148 (letrec-syntax ((test-url
151 (test-equal (string-append "GET " path)
153 (let-values (((response body)
154 (http-get (string-append
155 "http://localhost:8080"
157 (response-code response))))
159 (test-url path 200)))))
162 (test-url "/test/log")
163 (test-url "/test/tree")
164 (test-url "/test/does-not-exist" 404)
165 (test-url "/does-not-exist" 404))
168 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
170 (gexp->derivation "cgit-test" test))
175 (description "Connect to a running Cgit server.")
176 (value (run-cgit-test))))