dict.scm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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>
  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. (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))
  33. (define %dicod-os
  34. (simple-operating-system
  35. (service dhcp-client-service-type)
  36. (service dicod-service-type
  37. (dicod-configuration
  38. (interfaces '("0.0.0.0"))
  39. (handlers (list (dicod-handler
  40. (name "wordnet")
  41. (module "dictorg")
  42. (options
  43. ;; XXX: Not useful since WordNet does not
  44. ;; provide DICT-formatted data?
  45. (list #~(string-append "dbdir=" #$wordnet))))))
  46. (databases (list (dicod-database
  47. (name "wordnet")
  48. (complex? #t)
  49. (handler "wordnet")
  50. (options '("database=wn")))
  51. %dicod-database:gcide))))))
  52. (define* (run-dicod-test)
  53. "Run tests of 'dicod-service-type'."
  54. (define os
  55. (marionette-operating-system
  56. %dicod-os
  57. #:imported-modules
  58. (source-module-closure '((gnu services herd)))))
  59. (define vm
  60. (virtual-machine
  61. (operating-system os)
  62. (port-forwardings '((8000 . 2628)))))
  63. (define test
  64. (with-imported-modules '((gnu build marionette))
  65. #~(begin
  66. (use-modules (ice-9 rdelim)
  67. (ice-9 regex)
  68. (srfi srfi-64)
  69. (gnu build marionette))
  70. (define marionette
  71. ;; Forward the guest's DICT port to local port 8000.
  72. (make-marionette (list #$vm)))
  73. (define %dico-socket
  74. (socket PF_INET SOCK_STREAM 0))
  75. (mkdir #$output)
  76. (chdir #$output)
  77. (test-begin "dicod")
  78. ;; Wait for the service to be started.
  79. (test-assert "service is running"
  80. (marionette-eval
  81. '(begin
  82. (use-modules (gnu services herd))
  83. (start-service 'dicod))
  84. marionette))
  85. ;; Wait until dicod is actually listening.
  86. ;; TODO: Use a PID file instead.
  87. (test-assert "connect inside"
  88. (wait-for-tcp-port 2628 marionette))
  89. (test-assert "connect"
  90. (let ((addr (make-socket-address AF_INET INADDR_LOOPBACK 8000)))
  91. (connect %dico-socket addr)
  92. (read-line %dico-socket 'concat)))
  93. (test-equal "CLIENT"
  94. "250 ok\r\n"
  95. (begin
  96. (display "CLIENT \"GNU Guile\"\r\n" %dico-socket)
  97. (read-line %dico-socket 'concat)))
  98. (test-assert "DEFINE"
  99. (begin
  100. (display "DEFINE ! hello\r\n" %dico-socket)
  101. (display "QUIT\r\n" %dico-socket)
  102. (let ((result (read-string %dico-socket)))
  103. (and (string-contains result "gcide")
  104. (string-contains result "hello")
  105. result))))
  106. (test-end)
  107. (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
  108. (gexp->derivation "dicod" test))
  109. (define %test-dicod
  110. (system-test
  111. (name "dicod")
  112. (description "Connect to the dicod DICT server.")
  113. (value (run-dicod-test))))