Commit | Line | Data |
---|---|---|
985a8599 | 1 | ;;; GNU Guix --- Functional package management for GNU |
1fb75128 | 2 | ;;; Copyright © 2017, 2018, 2021 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) | |
5f07efda MO |
66 | (port-forwardings '((8000 . 2628))) |
67 | (memory-size 1024))) | |
8b113790 LC |
68 | |
69 | (define test | |
70 | (with-imported-modules '((gnu build marionette)) | |
71 | #~(begin | |
72 | (use-modules (ice-9 rdelim) | |
73 | (ice-9 regex) | |
74 | (srfi srfi-64) | |
75 | (gnu build marionette)) | |
76 | (define marionette | |
77 | ;; Forward the guest's DICT port to local port 8000. | |
78 | (make-marionette (list #$vm))) | |
79 | ||
80 | (define %dico-socket | |
81 | (socket PF_INET SOCK_STREAM 0)) | |
82 | ||
89b05442 | 83 | (test-runner-current (system-test-runner #$output)) |
8b113790 LC |
84 | (test-begin "dicod") |
85 | ||
86 | ;; Wait for the service to be started. | |
c24b1547 | 87 | (test-assert "service is running" |
8b113790 LC |
88 | (marionette-eval |
89 | '(begin | |
90 | (use-modules (gnu services herd)) | |
c24b1547 | 91 | (start-service 'dicod)) |
8b113790 LC |
92 | marionette)) |
93 | ||
94 | ;; Wait until dicod is actually listening. | |
95 | ;; TODO: Use a PID file instead. | |
96 | (test-assert "connect inside" | |
7a4e2eaa | 97 | (wait-for-tcp-port 2628 marionette)) |
8b113790 LC |
98 | |
99 | (test-assert "connect" | |
100 | (let ((addr (make-socket-address AF_INET INADDR_LOOPBACK 8000))) | |
101 | (connect %dico-socket addr) | |
102 | (read-line %dico-socket 'concat))) | |
103 | ||
104 | (test-equal "CLIENT" | |
105 | "250 ok\r\n" | |
106 | (begin | |
107 | (display "CLIENT \"GNU Guile\"\r\n" %dico-socket) | |
108 | (read-line %dico-socket 'concat))) | |
109 | ||
110 | (test-assert "DEFINE" | |
111 | (begin | |
112 | (display "DEFINE ! hello\r\n" %dico-socket) | |
113 | (display "QUIT\r\n" %dico-socket) | |
114 | (let ((result (read-string %dico-socket))) | |
115 | (and (string-contains result "gcide") | |
116 | (string-contains result "hello") | |
117 | result)))) | |
118 | ||
1fb75128 | 119 | (test-end)))) |
8b113790 LC |
120 | |
121 | (gexp->derivation "dicod" test)) | |
985a8599 LC |
122 | |
123 | (define %test-dicod | |
124 | (system-test | |
125 | (name "dicod") | |
126 | (description "Connect to the dicod DICT server.") | |
127 | (value (run-dicod-test)))) |