From: Christopher Baines <mail@cbaines.net>
To: 29741@debbugs.gnu.org
Subject: [bug#29741] [PATCH 1/2] gnu: tests: web: Generalise the nginx test.
Date: Sun, 24 Dec 2017 18:01:56 +0000 [thread overview]
Message-ID: <20171224180157.21873-1-mail@cbaines.net> (raw)
In-Reply-To: <87zi6gtkhx.fsf@gnu.org>
So that it can also be used for other web servers.
* gnu/tests/web.scm (%index.html-contents): Change nginx to guix.
(%make-http-root): Move the index.html file from /srv to /srv/http.
(%nginx-servers): Remove the setting of root.
(run-nginx-test, run-webserver-test): Rename run-nginx-test to
run-webserver-test and generalise its behaviour
(%test-nginx): Change to use run-webserver-test, rather than run-nginx-test.
---
gnu/tests/web.scm | 97 +++++++++++++++++++++++++++++--------------------------
1 file changed, 52 insertions(+), 45 deletions(-)
diff --git a/gnu/tests/web.scm b/gnu/tests/web.scm
index 336f25b3c..5595e9ddf 100644
--- a/gnu/tests/web.scm
+++ b/gnu/tests/web.scm
@@ -33,47 +33,33 @@
%test-php-fpm))
(define %index.html-contents
- ;; Contents of the /index.html file served by nginx.
- "Hello, nginx!")
+ ;; Contents of the /index.html file.
+ "Hello, guix!")
(define %make-http-root
;; Create our server root in /srv.
#~(begin
(mkdir "/srv")
- (call-with-output-file "/srv/index.html"
+ (mkdir "/srv/http")
+ (call-with-output-file "/srv/http/index.html"
(lambda (port)
(display #$%index.html-contents port)))))
-(define %nginx-servers
- ;; Server blocks.
- (list (nginx-server-configuration
- (root "/srv")
- (listen '("8042" "443 ssl")))))
-
-(define %nginx-os
- ;; Operating system under test.
- (simple-operating-system
- (dhcp-client-service)
- (service nginx-service-type
- (nginx-configuration
- (log-directory "/var/log/nginx")
- (server-blocks %nginx-servers)))
- (simple-service 'make-http-root activation-service-type
- %make-http-root)))
-
-(define* (run-nginx-test #:optional (http-port 8042))
+(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
- %nginx-os
+ test-os
#:imported-modules '((gnu services herd)
(guix combinators))))
+ (define forwarded-port 8080)
+
(define vm
(virtual-machine
(operating-system os)
- (port-forwardings `((8080 . ,http-port)))))
+ (port-forwardings `((,http-port . ,forwarded-port)))))
(define test
(with-imported-modules '((gnu build marionette))
@@ -90,48 +76,69 @@ HTTP-PORT."
(mkdir #$output)
(chdir #$output)
- (test-begin "nginx")
+ (test-begin #$name)
- ;; Wait for nginx to be up and running.
- (test-eq "service running"
- 'running!
+ (test-assert #$(string-append name " service running")
(marionette-eval
'(begin
(use-modules (gnu services herd))
- (start-service 'nginx)
- 'running!)
- marionette))
-
- ;; Make sure the PID file is created.
- (test-assert "PID file"
- (marionette-eval
- '(file-exists? "/var/run/nginx/pid")
+ (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 "http://localhost:8080/index.html"
- #:decode-body? #t)))
+ (let-values
+ (((response text)
+ (http-get #$(simple-format
+ #f "http://localhost:~A/index.html" forwarded-port)
+ #:decode-body? #t)))
(list (response-code response) text)))
- ;; There should be a log file in here.
- (test-assert "log file"
- (marionette-eval
- '(file-exists? "/var/log/nginx/access.log")
- marionette))
+ #$@(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 "nginx-test" test))
+ (gexp->derivation (string-append name "-test") test))
+
+\f
+;;;
+;;; NGINX
+;;;
+
+(define %nginx-servers
+ ;; Server blocks.
+ (list (nginx-server-configuration
+ (listen '("8080")))))
+
+(define %nginx-os
+ ;; Operating system under test.
+ (simple-operating-system
+ (dhcp-client-service)
+ (service nginx-service-type
+ (nginx-configuration
+ (log-directory "/var/log/nginx")
+ (server-blocks %nginx-servers)))
+ (simple-service 'make-http-root activation-service-type
+ %make-http-root)))
(define %test-nginx
(system-test
(name "nginx")
(description "Connect to a running NGINX server.")
- (value (run-nginx-test))))
+ (value (run-webserver-test name %nginx-os
+ #:log-file "/var/log/nginx/access.log"))))
\f
;;;
--
2.14.1
next prev parent reply other threads:[~2017-12-24 18:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <handler.29741.B.15134551667792.ack@debbugs.gnu.org>
2017-12-16 20:16 ` [bug#29741] [PATCH 1/2] gnu: tests: web: Generalise the test data for the nginx test Christopher Baines
2017-12-16 20:17 ` [bug#29741] [PATCH 2/2] gnu: services: web: Add service for apache-httpd Christopher Baines
2017-12-18 10:10 ` Ludovic Courtès
2017-12-19 8:03 ` Christopher Baines
2017-12-24 18:01 ` Christopher Baines [this message]
2017-12-24 18:01 ` [bug#29741] [PATCH 2/2] gnu: services: web: Add service for httpd Christopher Baines
2017-12-16 20:12 ` [bug#29741] [PATCH] gnu: services: web: Add service for apache-httpd Christopher Baines
2018-01-11 9:46 ` [bug#29741] [PATCH 2/2] gnu: services: web: Add service for httpd Ludovic Courtès
2018-01-17 8:45 ` bug#29741: " Christopher Baines
2017-12-24 18:08 ` [bug#29741] [PATCH 2/2] gnu: services: web: Add service for apache-httpd Christopher Baines
2017-12-18 10:02 ` [bug#29741] [PATCH 1/2] gnu: tests: web: Generalise the test data for the nginx test Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171224180157.21873-1-mail@cbaines.net \
--to=mail@cbaines.net \
--cc=29741@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.