1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018 Oleg Pykhalov <go.wigust@gmail.com>
3 ;;; Copyright © 2017, 2018 Ludovic Courtès <ludo@gnu.org>
4 ;;; Copyright © 2017, 2018 Clément Lassieur <clement@lassieur.org>
6 ;;; This file is part of GNU Guix.
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 (define-module (gnu tests version-control)
22 #:use-module (gnu tests)
23 #:use-module (gnu system)
24 #:use-module (gnu system file-systems)
25 #:use-module (gnu system shadow)
26 #:use-module (gnu system vm)
27 #:use-module (gnu services)
28 #:use-module (gnu services version-control)
29 #:use-module (gnu services cgit)
30 #:use-module (gnu services web)
31 #:use-module (gnu services networking)
32 #:use-module (gnu packages version-control)
33 #:use-module (guix gexp)
34 #:use-module (guix store)
35 #:use-module (guix modules)
39 (define README-contents
40 "Hello! This is what goes inside the 'README' file.")
42 (define %make-git-repository
43 ;; Create Git repository in /srv/git/test.
44 (with-imported-modules (source-module-closure
45 '((guix build utils)))
47 (use-modules (guix build utils))
49 (let ((git (string-append #$git "/bin/git")))
50 (mkdir-p "/tmp/test-repo")
51 (with-directory-excursion "/tmp/test-repo"
52 (call-with-output-file "/tmp/test-repo/README"
54 (display #$README-contents port)))
55 (invoke git "config" "--global" "user.email" "charlie@example.org")
56 (invoke git "config" "--global" "user.name" "A U Thor")
58 (invoke git "add" ".")
59 (invoke git "commit" "-m" "That's a commit."))
62 (rename-file "/tmp/test-repo/.git" "/srv/git/test")))))
64 (define %test-repository-service
65 ;; Service that creates /srv/git/test.
66 (simple-service 'make-git-repository activation-service-type
67 %make-git-repository))
69 (define %cgit-configuration-nginx
71 (nginx-server-configuration
75 (nginx-location-configuration
77 (body '("fastcgi_param SCRIPT_FILENAME $document_root/lib/cgit/cgit.cgi;"
78 "fastcgi_param PATH_INFO $uri;"
79 "fastcgi_param QUERY_STRING $args;"
80 "fastcgi_param HTTP_HOST $server_name;"
81 "fastcgi_pass 127.0.0.1:9000;")))))
82 (try-files (list "$uri" "@cgit"))
85 (ssl-certificate-key #f))))
88 ;; Operating system under test.
90 (simple-operating-system
92 (service cgit-service-type
94 (nginx %cgit-configuration-nginx)))
95 %test-repository-service)))
99 (operating-system-packages base-os))))))
101 (define* (run-cgit-test #:optional (http-port 19418))
102 "Run tests in %CGIT-OS, which has nginx running and listening on
105 (marionette-operating-system
107 #:imported-modules '((gnu services herd)
108 (guix combinators))))
112 (operating-system os)
113 (port-forwardings `((8080 . ,http-port)))))
116 (with-imported-modules '((gnu build marionette))
118 (use-modules (srfi srfi-11) (srfi srfi-64)
119 (gnu build marionette)
125 (make-marionette (list #$vm)))
132 ;; XXX: Shepherd reads the config file *before* binding its control
133 ;; socket, so /var/run/shepherd/socket might not exist yet when the
134 ;; 'marionette' service is started.
135 (test-assert "shepherd socket ready"
138 (use-modules (gnu services herd))
140 (cond ((file-exists? (%shepherd-socket-file))
149 ;; Wait for nginx to be up and running.
150 (test-assert "nginx running"
153 (use-modules (gnu services herd))
154 (start-service 'nginx))
157 ;; Wait for fcgiwrap to be up and running.
158 (test-assert "fcgiwrap running"
161 (use-modules (gnu services herd))
162 (start-service 'fcgiwrap))
165 ;; Make sure the PID file is created.
166 (test-assert "PID file"
168 '(file-exists? "/var/run/nginx/pid")
171 ;; Make sure the configuration file is created.
172 (test-assert "configuration file"
174 '(file-exists? "/etc/cgitrc")
177 ;; Make sure Git test repository is created.
178 (test-assert "Git test repository"
180 '(file-exists? "/srv/git/test")
183 ;; Make sure we can access pages that correspond to our repository.
184 (letrec-syntax ((test-url
187 (test-equal (string-append "GET " path)
189 (let-values (((response body)
190 (http-get (string-append
191 "http://localhost:8080"
193 (response-code response))))
195 (test-url path 200)))))
198 (test-url "/test/log")
199 (test-url "/test/tree")
200 (test-url "/test/tree/README")
201 (test-url "/test/does-not-exist" 404)
202 (test-url "/test/tree/does-not-exist" 404)
203 (test-url "/does-not-exist" 404))
206 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
208 (gexp->derivation "cgit-test" test))
213 (description "Connect to a running Cgit server.")
214 (value (run-cgit-test))))
221 (define %git-nginx-configuration
225 (nginx-server-configuration
228 (ssl-certificate-key #f)
230 (list (git-http-nginx-location-configuration
231 (git-http-configuration (export-all? #t)
232 (uri-path "/git"))))))))))
235 (simple-operating-system
236 (dhcp-client-service)
237 (service fcgiwrap-service-type)
238 (service nginx-service-type %git-nginx-configuration)
239 %test-repository-service))
241 (define* (run-git-http-test #:optional (http-port 19418))
243 (marionette-operating-system
245 #:imported-modules '((gnu services herd)
246 (guix combinators))))
250 (operating-system os)
251 (port-forwardings `((8080 . ,http-port)))))
254 (with-imported-modules '((gnu build marionette)
257 (use-modules (srfi srfi-64)
259 (gnu build marionette)
263 (make-marionette (list #$vm)))
268 (test-begin "git-http")
270 ;; Wait for nginx to be up and running.
271 (test-assert "nginx running"
274 (use-modules (gnu services herd))
275 (start-service 'nginx))
278 ;; Make sure Git test repository is created.
279 (test-assert "Git test repository"
281 '(file-exists? "/srv/git/test")
284 ;; Make sure we can clone the repo from the host.
288 (invoke #$(file-append git "/bin/git") "clone" "-v"
289 "http://localhost:8080/git/test" "/tmp/clone")
290 (call-with-input-file "/tmp/clone/README"
294 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
296 (gexp->derivation "git-http" test))
298 (define %test-git-http
301 (description "Connect to a running Git HTTP server.")
302 (value (run-git-http-test))))