1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (gnu tests dict)
21 #:use-module (gnu tests)
22 #:use-module (gnu system)
23 #:use-module (gnu system nss)
24 #:use-module (gnu system vm)
25 #:use-module (gnu services)
26 #:use-module (gnu services dict)
27 #:use-module (gnu services networking)
28 #:use-module (gnu packages wordnet)
29 #:use-module (guix gexp)
30 #:use-module (guix store)
31 #:use-module (guix packages)
32 #:use-module (guix modules)
33 #:export (%test-dicod))
36 (simple-operating-system
37 (service dhcp-client-service-type)
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'."
58 (marionette-operating-system
61 (source-module-closure '((gnu services herd)))))
66 (port-forwardings '((8000 . 2628)))))
69 (with-imported-modules '((gnu build marionette))
71 (use-modules (ice-9 rdelim)
74 (gnu build marionette))
76 ;; Forward the guest's DICT port to local port 8000.
77 (make-marionette (list #$vm)))
80 (socket PF_INET SOCK_STREAM 0))
87 ;; Wait for the service to be started.
88 (test-assert "service is running"
91 (use-modules (gnu services herd))
92 (start-service 'dicod))
95 ;; Wait until dicod is actually listening.
96 ;; TODO: Use a PID file instead.
97 (test-assert "connect inside"
98 (wait-for-tcp-port 2628 marionette))
100 (test-assert "connect"
101 (let ((addr (make-socket-address AF_INET INADDR_LOOPBACK 8000)))
102 (connect %dico-socket addr)
103 (read-line %dico-socket 'concat)))
108 (display "CLIENT \"GNU Guile\"\r\n" %dico-socket)
109 (read-line %dico-socket 'concat)))
111 (test-assert "DEFINE"
113 (display "DEFINE ! hello\r\n" %dico-socket)
114 (display "QUIT\r\n" %dico-socket)
115 (let ((result (read-string %dico-socket)))
116 (and (string-contains result "gcide")
117 (string-contains result "hello")
121 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
123 (gexp->derivation "dicod" test))
128 (description "Connect to the dicod DICT server.")
129 (value (run-dicod-test))))