Commit | Line | Data |
---|---|---|
985a8599 | 1 | ;;; GNU Guix --- Functional package management for GNU |
7a4e2eaa | 2 | ;;; Copyright © 2017, 2018 Ludovic Courtès <ludo@gnu.org> |
c24b1547 | 3 | ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org> |
985a8599 LC |
4 | ;;; |
5 | ;;; This file is part of GNU Guix. | |
6 | ;;; | |
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. | |
11 | ;;; | |
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. | |
16 | ;;; | |
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/>. | |
19 | ||
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) | |
985a8599 LC |
31 | #:use-module (guix packages) |
32 | #:use-module (guix modules) | |
33 | #:export (%test-dicod)) | |
34 | ||
35 | (define %dicod-os | |
36 | (simple-operating-system | |
39d7fdce | 37 | (service dhcp-client-service-type) |
985a8599 LC |
38 | (service dicod-service-type |
39 | (dicod-configuration | |
40 | (interfaces '("0.0.0.0")) | |
41 | (handlers (list (dicod-handler | |
42 | (name "wordnet") | |
43 | (module "dictorg") | |
44 | (options | |
45 | ;; XXX: Not useful since WordNet does not | |
46 | ;; provide DICT-formatted data? | |
47 | (list #~(string-append "dbdir=" #$wordnet)))))) | |
48 | (databases (list (dicod-database | |
49 | (name "wordnet") | |
50 | (complex? #t) | |
51 | (handler "wordnet") | |
52 | (options '("database=wn"))) | |
53 | %dicod-database:gcide)))))) | |
54 | ||
55 | (define* (run-dicod-test) | |
56 | "Run tests of 'dicod-service-type'." | |
8b113790 LC |
57 | (define os |
58 | (marionette-operating-system | |
59 | %dicod-os | |
60 | #:imported-modules | |
61 | (source-module-closure '((gnu services herd))))) | |
62 | ||
63 | (define vm | |
64 | (virtual-machine | |
65 | (operating-system os) | |
66 | (port-forwardings '((8000 . 2628))))) | |
67 | ||
68 | (define test | |
69 | (with-imported-modules '((gnu build marionette)) | |
70 | #~(begin | |
71 | (use-modules (ice-9 rdelim) | |
72 | (ice-9 regex) | |
73 | (srfi srfi-64) | |
74 | (gnu build marionette)) | |
75 | (define marionette | |
76 | ;; Forward the guest's DICT port to local port 8000. | |
77 | (make-marionette (list #$vm))) | |
78 | ||
79 | (define %dico-socket | |
80 | (socket PF_INET SOCK_STREAM 0)) | |
81 | ||
82 | (mkdir #$output) | |
83 | (chdir #$output) | |
84 | ||
85 | (test-begin "dicod") | |
86 | ||
87 | ;; Wait for the service to be started. | |
c24b1547 | 88 | (test-assert "service is running" |
8b113790 LC |
89 | (marionette-eval |
90 | '(begin | |
91 | (use-modules (gnu services herd)) | |
c24b1547 | 92 | (start-service 'dicod)) |
8b113790 LC |
93 | marionette)) |
94 | ||
95 | ;; Wait until dicod is actually listening. | |
96 | ;; TODO: Use a PID file instead. | |
97 | (test-assert "connect inside" | |
7a4e2eaa | 98 | (wait-for-tcp-port 2628 marionette)) |
8b113790 LC |
99 | |
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))) | |
104 | ||
105 | (test-equal "CLIENT" | |
106 | "250 ok\r\n" | |
107 | (begin | |
108 | (display "CLIENT \"GNU Guile\"\r\n" %dico-socket) | |
109 | (read-line %dico-socket 'concat))) | |
110 | ||
111 | (test-assert "DEFINE" | |
112 | (begin | |
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") | |
118 | result)))) | |
119 | ||
120 | (test-end) | |
121 | (exit (= (test-runner-fail-count (test-runner-current)) 0))))) | |
122 | ||
123 | (gexp->derivation "dicod" test)) | |
985a8599 LC |
124 | |
125 | (define %test-dicod | |
126 | (system-test | |
127 | (name "dicod") | |
128 | (description "Connect to the dicod DICT server.") | |
129 | (value (run-dicod-test)))) |