unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob 228204e316f8b17703cac25a9924434fd68a222c 3721 bytes (raw)
name: gnu/tests/dns.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 Julien Lepiller <julien@lepiller.eu>
;;;
;;; 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 <http://www.gnu.org/licenses/>.

(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))))

debug log:

solving 228204e31 ...
found 228204e31 in https://yhetil.org/guix-patches/20171202121815.553c0b93@lepiller.eu/

applying [1/1] https://yhetil.org/guix-patches/20171202121815.553c0b93@lepiller.eu/
diff --git a/gnu/tests/dns.scm b/gnu/tests/dns.scm
new file mode 100644
index 000000000..228204e31

Checking patch gnu/tests/dns.scm...
Applied patch gnu/tests/dns.scm cleanly.

index at:
100644 228204e316f8b17703cac25a9924434fd68a222c	gnu/tests/dns.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).