;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017 Julien Lepiller ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (gnu tests dns) #:use-module (gnu tests) #:use-module (gnu system) #:use-module (gnu system vm) #:use-module (gnu services) #:use-module (gnu services dns) #:use-module (gnu services networking) #:use-module (guix dns) #:use-module (guix gexp) #:use-module (guix store) #:use-module (ice-9 ftw) #:export (%test-knot)) (define %ip4-addr ;; a random IPv4 address "136.12.251.84") (define-zone-entries %test-entries ;; Test entries, with no real data ;; Name TTL Class Type Data ("@" "" "IN" "A" "1.2.3.4") ("@" "" "IN" "MX" "10 mail") ("mail" "" "IN" "A" %ip4-addr)) (define %test-zone ;; A test zone that uses the fake data (knot-zone-configuration (domain "guix-test.org") (zone (zone-file (origin "guix-test.org") (entries %test-entries))))) (define %knot-zones (list %test-zone)) (define %knot-os (simple-operating-system (dhcp-client-service) (service knot-service-type (knot-configuration (zones %knot-zones))))) (define (run-knot-test) "Return a test of an OS running Knot service." (define vm (virtual-machine (operating-system (marionette-operating-system %knot-os #:imported-modules '((gnu services herd)))) (port-forwardings '((1053 . 53))))) (define test (with-imported-modules '((gnu build marionette) (guix dns)) #~(begin (use-modules (guix dns) (gnu build marionette) (srfi srfi-64)) (define marionette (make-marionette '(#$vm))) (mkdir #$output) (chdir #$output) (test-begin "knot") (test-assert "service is running" (marionette-eval '(begin (use-modules (gnu services herd)) (start-service 'knot) #t) marionette)) (test-eq "get the correct answer" #$%ip4-addr (begin (format #t "test:\n") (let* ((query (simple-a-query "mail.guix-test.org")) (dns (socket AF_INET SOCK_STREAM 0)) (addr (make-socket-address AF_INET INADDR_LOOPBACK 1053))) (connect dns addr) (put-bytevector dns (dns-query->bytevector query #t)) (bytevector->ipv4 (dns-record-rdata (car (dns-query-answers (bytevector->dns-query (get-bytevector-n dns 500))))))))) (test-end) (exit (= (test-runner-fail-count (test-runner-current)) 0))))) (gexp->derivation "knot-test" test)) (define %test-knot (system-test (name "knot") (description "Send a DNS request to a running Knot server.") (value (run-knot-test))))