guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#27650] [PATCH 2/2] tests: Add 'tailon-service-type' test.


From: Christopher Baines
Subject: [bug#27650] [PATCH 2/2] tests: Add 'tailon-service-type' test.
Date: Wed, 26 Jul 2017 10:08:53 +0100

* gnu/local.mk (GNU_SYSTEM_MODULES): Add it.
* gnu/tests/web.scm: New file.
---
 gnu/local.mk        |   1 +
 gnu/tests/admin.scm | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+)
 create mode 100644 gnu/tests/admin.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index 9dfca9dbb..90dfcfeb5 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -479,6 +479,7 @@ GNU_SYSTEM_MODULES =                                \
   %D%/build/vm.scm                             \
                                                \
   %D%/tests.scm                                        \
+  %D%/tests/admin.scm                          \
   %D%/tests/base.scm                           \
   %D%/tests/dict.scm                           \
   %D%/tests/nfs.scm                            \
diff --git a/gnu/tests/admin.scm b/gnu/tests/admin.scm
new file mode 100644
index 000000000..06373be14
--- /dev/null
+++ b/gnu/tests/admin.scm
@@ -0,0 +1,106 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2017 Christopher Baines <address@hidden>
+;;;
+;;; 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 admin)
+  #:use-module (gnu tests)
+  #:use-module (gnu system)
+  #:use-module (gnu system file-systems)
+  #:use-module (gnu system shadow)
+  #:use-module (gnu system vm)
+  #:use-module (gnu services)
+  #:use-module (gnu services admin)
+  #:use-module (gnu services networking)
+  #:use-module (guix gexp)
+  #:use-module (guix store)
+  #:use-module (guix monads)
+  #:export (%test-tailon))
+
+(define %tailon-os
+  ;; Operating system under test.
+  (simple-operating-system
+   (dhcp-client-service)
+   (service tailon-service-type
+            (tailon-configuration
+             (config-file
+              (tailon-configuration-file
+               (bind "0.0.0.0:8080")))))))
+
+(define* (run-tailon-test #:optional (http-port 8081))
+  "Run tests in %TAILON-OS, which has tailon running and listening on
+HTTP-PORT."
+  (mlet* %store-monad ((os ->   (marionette-operating-system
+                                 %tailon-os
+                                 #:imported-modules '((gnu services herd)
+                                                      (guix combinators))))
+                       (command (system-qemu-image/shared-store-script
+                                 os #:graphic? #f)))
+    (define test
+      (with-imported-modules '((gnu build marionette))
+        #~(begin
+            (use-modules (srfi srfi-11) (srfi srfi-64)
+                         (gnu build marionette)
+                         (web uri)
+                         (web client)
+                         (web response))
+
+            (define marionette
+              ;; Forward the guest's HTTP-PORT, where tailon is listening, to
+              ;; port 8080 in the host.
+              (make-marionette (list #$command "-net"
+                                     #$(simple-format
+                                        #f
+                                        "user,hostfwd=tcp::~A-:8080"
+                                        http-port))))
+
+            (mkdir #$output)
+            (chdir #$output)
+
+            (test-begin "tailon")
+
+            (test-eq "service running"
+              'running!
+              (marionette-eval
+               '(begin
+                  (use-modules (gnu services herd))
+                  (start-service 'tailon)
+                  'running!)
+               marionette))
+
+            ;; Wait for tailon to be up and running.
+            (sleep 5)
+
+            (test-equal "http-get"
+              200
+              (let-values (((response text)
+                            (http-get #$(simple-format
+                                         #f
+                                         "http://localhost:~A/";
+                                         http-port)
+                                      #:decode-body? #t)))
+                (response-code response)))
+
+            (test-end)
+            (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
+
+    (gexp->derivation "tailon-test" test)))
+
+(define %test-tailon
+  (system-test
+   (name "tailon")
+   (description "Connect to a running Tailon server.")
+   (value (run-tailon-test))))
-- 
2.13.3






reply via email to

[Prev in Thread] Current Thread [Next in Thread]