diff options
author | Ludovic Courtès <ludo@gnu.org> | 2017-07-18 10:41:51 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2017-07-20 11:57:13 +0200 |
commit | 8b113790fa3bfd2300c737901ba161f079fedbdf (patch) | |
tree | 72b7aa4fa9be2a6c129b97b04a11cfbe0d298a79 /gnu/tests/dict.scm | |
parent | ed419fa0c56e6ff3aa8bd8e8f100a81442c51e6d (diff) | |
download | guix-8b113790fa3bfd2300c737901ba161f079fedbdf.tar guix-8b113790fa3bfd2300c737901ba161f079fedbdf.tar.gz |
tests: Use 'virtual-machine' records instead of monadic procedures.
* gnu/tests/base.scm (%test-basic-os): Use 'let*' instead of 'mlet*' and
'virtual-machine' instead of 'system-qemu-image/shared-store-script'.
(run-mcron-test): Likewise.
(run-nss-mdns-test): Likewise.
* gnu/tests/dict.scm (run-dicod-test): Likewise.
* gnu/tests/mail.scm (run-opensmtpd-test): Likewise.
(run-exim-test): Likewise.
* gnu/tests/messaging.scm (run-xmpp-test): Likewise.
* gnu/tests/networking.scm (run-inetd-test): Likewise.
* gnu/tests/nfs.scm (run-nfs-test): Likewise.
* gnu/tests/ssh.scm (run-ssh-test): Likewise.
* gnu/tests/web.scm (run-nginx-test): Likewise.
Diffstat (limited to 'gnu/tests/dict.scm')
-rw-r--r-- | gnu/tests/dict.scm | 165 |
1 files changed, 84 insertions, 81 deletions
diff --git a/gnu/tests/dict.scm b/gnu/tests/dict.scm index 16b6edbd9e..b9c741e3e0 100644 --- a/gnu/tests/dict.scm +++ b/gnu/tests/dict.scm @@ -27,7 +27,6 @@ #:use-module (gnu packages wordnet) #:use-module (guix gexp) #:use-module (guix store) - #:use-module (guix monads) #:use-module (guix packages) #:use-module (guix modules) #:export (%test-dicod)) @@ -54,86 +53,90 @@ (define* (run-dicod-test) "Run tests of 'dicod-service-type'." - (mlet* %store-monad ((os -> (marionette-operating-system - %dicod-os - #:imported-modules - (source-module-closure '((gnu services herd))))) - (command (system-qemu-image/shared-store-script - os #:graphic? #f))) - (define test - (with-imported-modules '((gnu build marionette)) - #~(begin - (use-modules (ice-9 rdelim) - (ice-9 regex) - (srfi srfi-64) - (gnu build marionette)) - (define marionette - ;; Forward the guest's DICT port to local port 8000. - (make-marionette (list #$command "-net" - "user,hostfwd=tcp::8000-:2628"))) - - (define %dico-socket - (socket PF_INET SOCK_STREAM 0)) - - (mkdir #$output) - (chdir #$output) - - (test-begin "dicod") - - ;; Wait for the service to be started. - (test-eq "service is running" - 'running! - (marionette-eval - '(begin - (use-modules (gnu services herd)) - (start-service 'dicod) - 'running!) - marionette)) - - ;; Wait until dicod is actually listening. - ;; TODO: Use a PID file instead. - (test-assert "connect inside" - (marionette-eval - '(begin - (use-modules (ice-9 rdelim)) - (let ((sock (socket PF_INET SOCK_STREAM 0))) - (let loop ((i 0)) - (pk 'try i) - (catch 'system-error - (lambda () - (connect sock AF_INET INADDR_LOOPBACK 2628)) - (lambda args - (pk 'connection-error args) - (when (< i 20) - (sleep 1) - (loop (+ 1 i)))))) - (read-line sock 'concat))) - marionette)) - - (test-assert "connect" - (let ((addr (make-socket-address AF_INET INADDR_LOOPBACK 8000))) - (connect %dico-socket addr) - (read-line %dico-socket 'concat))) - - (test-equal "CLIENT" - "250 ok\r\n" - (begin - (display "CLIENT \"GNU Guile\"\r\n" %dico-socket) - (read-line %dico-socket 'concat))) - - (test-assert "DEFINE" - (begin - (display "DEFINE ! hello\r\n" %dico-socket) - (display "QUIT\r\n" %dico-socket) - (let ((result (read-string %dico-socket))) - (and (string-contains result "gcide") - (string-contains result "hello") - result)))) - - (test-end) - (exit (= (test-runner-fail-count (test-runner-current)) 0))))) - - (gexp->derivation "dicod" test))) + (define os + (marionette-operating-system + %dicod-os + #:imported-modules + (source-module-closure '((gnu services herd))))) + + (define vm + (virtual-machine + (operating-system os) + (port-forwardings '((8000 . 2628))))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (ice-9 rdelim) + (ice-9 regex) + (srfi srfi-64) + (gnu build marionette)) + (define marionette + ;; Forward the guest's DICT port to local port 8000. + (make-marionette (list #$vm))) + + (define %dico-socket + (socket PF_INET SOCK_STREAM 0)) + + (mkdir #$output) + (chdir #$output) + + (test-begin "dicod") + + ;; Wait for the service to be started. + (test-eq "service is running" + 'running! + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (start-service 'dicod) + 'running!) + marionette)) + + ;; Wait until dicod is actually listening. + ;; TODO: Use a PID file instead. + (test-assert "connect inside" + (marionette-eval + '(begin + (use-modules (ice-9 rdelim)) + (let ((sock (socket PF_INET SOCK_STREAM 0))) + (let loop ((i 0)) + (pk 'try i) + (catch 'system-error + (lambda () + (connect sock AF_INET INADDR_LOOPBACK 2628)) + (lambda args + (pk 'connection-error args) + (when (< i 20) + (sleep 1) + (loop (+ 1 i)))))) + (read-line sock 'concat))) + marionette)) + + (test-assert "connect" + (let ((addr (make-socket-address AF_INET INADDR_LOOPBACK 8000))) + (connect %dico-socket addr) + (read-line %dico-socket 'concat))) + + (test-equal "CLIENT" + "250 ok\r\n" + (begin + (display "CLIENT \"GNU Guile\"\r\n" %dico-socket) + (read-line %dico-socket 'concat))) + + (test-assert "DEFINE" + (begin + (display "DEFINE ! hello\r\n" %dico-socket) + (display "QUIT\r\n" %dico-socket) + (let ((result (read-string %dico-socket))) + (and (string-contains result "gcide") + (string-contains result "hello") + result)))) + + (test-end) + (exit (= (test-runner-fail-count (test-runner-current)) 0))))) + + (gexp->derivation "dicod" test)) (define %test-dicod (system-test |