From 5146714c6615161fe3e496909f5a157c24d57ea0 Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Sat, 2 Dec 2017 12:15:28 +0100 Subject: [PATCH 2/2] gnu: tests: Add knot test. * gnu/tests/dns.scm: New file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add it. --- gnu/local.mk | 1 + gnu/tests/dns.scm | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 gnu/tests/dns.scm diff --git a/gnu/local.mk b/gnu/local.mk index 2e74c4d81..2fa736523 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -507,6 +507,7 @@ GNU_SYSTEM_MODULES = \ %D%/tests/databases.scm \ %D%/tests/desktop.scm \ %D%/tests/dict.scm \ + %D%/tests/dns.scm \ %D%/tests/nfs.scm \ %D%/tests/install.scm \ %D%/tests/mail.scm \ diff --git a/gnu/tests/dns.scm b/gnu/tests/dns.scm new file mode 100644 index 000000000..228204e31 --- /dev/null +++ b/gnu/tests/dns.scm @@ -0,0 +1,118 @@ +;;; 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)))) -- 2.15.0