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 packages)
31 #:use-module (guix modules)
32 #:export (%test-dicod))
35 (simple-operating-system
37 (service dicod-service-type
39 (interfaces '("0.0.0.0"))
40 (handlers (list (dicod-handler
44 ;; XXX: Not useful since WordNet does not
45 ;; provide DICT-formatted data?
46 (list #~(string-append "dbdir=" #$wordnet))))))
47 (databases (list (dicod-database
51 (options '("database=wn")))
52 %dicod-database:gcide))))))
54 (define* (run-dicod-test)
55 "Run tests of 'dicod-service-type'."
57 (marionette-operating-system
60 (source-module-closure '((gnu services herd)))))
65 (port-forwardings '((8000 . 2628)))))
68 (with-imported-modules '((gnu build marionette))
70 (use-modules (ice-9 rdelim)
73 (gnu build marionette))
75 ;; Forward the guest's DICT port to local port 8000.
76 (make-marionette (list #$vm)))
79 (socket PF_INET SOCK_STREAM 0))
86 ;; Wait for the service to be started.
87 (test-eq "service is running"
91 (use-modules (gnu services herd))
92 (start-service 'dicod)
96 ;; Wait until dicod is actually listening.
97 ;; TODO: Use a PID file instead.
98 (test-assert "connect inside"
101 (use-modules (ice-9 rdelim))
102 (let ((sock (socket PF_INET SOCK_STREAM 0)))
107 (connect sock AF_INET INADDR_LOOPBACK 2628))
109 (pk 'connection-error args)
113 (read-line sock 'concat)))
116 (test-assert "connect"
117 (let ((addr (make-socket-address AF_INET INADDR_LOOPBACK 8000)))
118 (connect %dico-socket addr)
119 (read-line %dico-socket 'concat)))
124 (display "CLIENT \"GNU Guile\"\r\n" %dico-socket)
125 (read-line %dico-socket 'concat)))
127 (test-assert "DEFINE"
129 (display "DEFINE ! hello\r\n" %dico-socket)
130 (display "QUIT\r\n" %dico-socket)
131 (let ((result (read-string %dico-socket)))
132 (and (string-contains result "gcide")
133 (string-contains result "hello")
137 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
139 (gexp->derivation "dicod" test))
144 (description "Connect to the dicod DICT server.")
145 (value (run-dicod-test))))