;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017 Ludovic Courtès ;;; Copyright © 2017, 2019 Christopher Baines ;;; Copyright © 2017, 2018 Clément Lassieur ;;; Copyright © 2018 Pierre-Antoine Rouby ;;; Copyright © 2018 Marius Bakke ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (gnu tests web) #:use-module (gnu tests) #:use-module (gnu system) #:use-module (gnu system file-systems) #:use-module (gnu system shadow) #:use-module (gnu system vm) #:use-module (gnu services) #:use-module (gnu services web) #:use-module (gnu services databases) #:use-module (gnu services getmail) #:use-module (gnu services networking) #:use-module (gnu services shepherd) #:use-module (gnu services mail) #:use-module (gnu packages databases) #:use-module (gnu packages patchutils) #:use-module (gnu packages python) #:use-module (gnu packages web) #:use-module (guix packages) #:use-module (guix modules) #:use-module (guix records) #:use-module (guix gexp) #:use-module (guix store) #:use-module (guix utils) #:use-module (ice-9 match) #:export (%test-httpd %test-nginx %test-varnish %test-php-fpm %test-hpcguix-web %test-tailon %test-patchwork)) (define %index.html-contents ;; Contents of the /index.html file. "Hello, guix!") (define %make-http-root ;; Create our server root in /srv. #~(begin (mkdir "/srv") (mkdir "/srv/http") (call-with-output-file "/srv/http/index.html" (lambda (port) (display #$%index.html-contents port))))) (define* (run-webserver-test name test-os #:key (log-file #f) (http-port 8080)) "Run tests in %NGINX-OS, which has nginx running and listening on HTTP-PORT." (define os (marionette-operating-system test-os #:imported-modules '((gnu services herd) (guix combinators)))) (define forwarded-port 8080) (define vm (virtual-machine (operating-system os) (port-forwardings `((,http-port . ,forwarded-port))))) (define test (with-imported-modules '((gnu build marionette)) #~(begin (use-modules (srfi srfi-11) (srfi srfi-64) (gnu build marionette) (web uri) (web client) (web response)) (define marionette (make-marionette (list #$vm))) (mkdir #$output) (chdir #$output) (test-begin #$name) (test-assert #$(string-append name " service running") (marionette-eval '(begin (use-modules (gnu services herd)) (match (start-service '#$(string->symbol name)) (#f #f) (('service response-parts ...) (match (assq-ref response-parts 'running) ((#t) #t) ((pid) (number? pid)))))) marionette)) ;; Retrieve the index.html file we put in /srv. (test-equal "http-get" '(200 #$%index.html-contents) (let-values (((response text) (http-get #$(simple-format #f "http://localhost:~A/index.html" forwarded-port) #:decode-body? #t))) (list (response-code response) text))) #$@(if log-file `((test-assert ,(string-append "log file exists " log-file) (marionette-eval '(file-exists? ,log-file) marionette))) '()) (test-end) (exit (= (test-runner-fail-count (test-runner-current)) 0))))) (gexp->derivation (string-append name "-test") test)) ;;; ;;; HTTPD ;;; (define %httpd-os (simple-operating-system (service dhcp-client-service-type) (service httpd-service-type (httpd-configuration (config (httpd-config-file (listen '("8080")))))) (simple-service 'ma