1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu tests dict)
20 #:use-module (gnu tests)
21 #:use-module (gnu system)
22 #:use-module (gnu system nss)
23 #:use-module (gnu system vm)
24 #:use-module (gnu services)
25 #:use-module (gnu services dict)
26 #:use-module (gnu services networking)
27 #:use-module (gnu packages wordnet)
28 #:use-module (guix gexp)
29 #:use-module (guix store)
30 #:use-module (guix monads)
31 #:use-module (guix packages)
32 #:use-module (guix modules)
33 #:export (%test-dicod))
36 (simple-operating-system
38 (service dicod-service-type
40 (interfaces '("0.0.0.0"))
41 (handlers (list (dicod-handler
45 ;; XXX: Not useful since WordNet does not
46 ;; provide DICT-formatted data?
47 (list #~(string-append "dbdir=" #$wordnet))))))
48 (databases (list (dicod-database
52 (options '("database=wn")))
53 %dicod-database:gcide))))))
55 (define* (run-dicod-test)
56 "Run tests of 'dicod-service-type'."
57 (mlet* %store-monad ((os -> (marionette-operating-system
60 (source-module-closure '((gnu services herd)))))
61 (command (system-qemu-image/shared-store-script
64 (with-imported-modules '((gnu build marionette))
66 (use-modules (ice-9 rdelim)
69 (gnu build marionette))
71 ;; Forward the guest's DICT port to local port 8000.
72 (make-marionette (list #$command "-net"
73 "user,hostfwd=tcp::8000-:2628")))
76 (socket PF_INET SOCK_STREAM 0))
83 ;; Wait for the service to be started.
84 (test-eq "service is running"
88 (use-modules (gnu services herd))
89 (start-service 'dicod)
93 ;; Wait until dicod is actually listening.
94 ;; TODO: Use a PID file instead.
95 (test-assert "connect inside"
98 (use-modules (ice-9 rdelim))
99 (let ((sock (socket PF_INET SOCK_STREAM 0)))
104 (connect sock AF_INET INADDR_LOOPBACK 2628))
106 (pk 'connection-error args)
109 (read-line sock 'concat)))
112 (test-assert "connect"
113 (let ((addr (make-socket-address AF_INET INADDR_LOOPBACK 8000)))
114 (connect %dico-socket addr)
115 (read-line %dico-socket 'concat)))
120 (display "CLIENT \"GNU Guile\"\r\n" %dico-socket)
121 (read-line %dico-socket 'concat)))
123 (test-assert "DEFINE"
125 (display "DEFINE ! hello\r\n" %dico-socket)
126 (display "QUIT\r\n" %dico-socket)
127 (let ((result (read-string %dico-socket)))
128 (and (string-contains result "gcide")
129 (string-contains result "hello")
133 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
135 (gexp->derivation "dicod" test)))
140 (description "Connect to the dicod DICT server.")
141 (value (run-dicod-test))))