From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkRvK-0005jO-2k for guix-patches@gnu.org; Wed, 23 Aug 2017 05:26:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkRvH-0007Th-Be for guix-patches@gnu.org; Wed, 23 Aug 2017 05:26:06 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:41648) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dkRvH-0007TZ-8Y for guix-patches@gnu.org; Wed, 23 Aug 2017 05:26:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dkRvH-0001WM-3H for guix-patches@gnu.org; Wed, 23 Aug 2017 05:26:03 -0400 Subject: [bug#28198] [PATCH 4/4] tests: databases: Add MongoDB test. Resent-Message-ID: From: Christopher Baines Date: Wed, 23 Aug 2017 10:25:16 +0100 Message-Id: <20170823092516.6846-4-mail@cbaines.net> In-Reply-To: <20170823092516.6846-1-mail@cbaines.net> References: <20170823092516.6846-1-mail@cbaines.net> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 28198@debbugs.gnu.org * gnu/tests/databases.scm (%test-mongodb): New variable. --- gnu/tests/databases.scm | 77 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/gnu/tests/databases.scm b/gnu/tests/databases.scm index 9d9a75374..1dbb8a12a 100644 --- a/gnu/tests/databases.scm +++ b/gnu/tests/databases.scm @@ -25,9 +25,11 @@ #:use-module (gnu services) #:use-module (gnu services databases) #:use-module (gnu services networking) + #:use-module (gnu packages databases) #:use-module (guix gexp) #:use-module (guix store) - #:export (%test-memcached)) + #:export (%test-memcached + %test-mongodb)) (define %memcached-os (simple-operating-system @@ -121,3 +123,76 @@ (name "memcached") (description "Connect to a running MEMCACHED server.") (value (run-memcached-test)))) + +(define %mongodb-os + (operating-system + (inherit + (simple-operating-system + (dhcp-client-service) + (service mongodb-service-type) + (extra-special-file "/etc/os-release" + (plain-file "os-release" "guix\n")))) + (packages (cons* mongodb + %base-packages)))) + +(define* (run-mongodb-test #:optional (port 27017)) + "Run tests in %MONGODB-OS, forwarding PORT." + (define os + (marionette-operating-system + %mongodb-os + #:imported-modules '((gnu services herd) + (guix combinators)))) + + (define vm + (virtual-machine + (operating-system os) + (memory-size 1024) + (disk-image-size (* 1024 (expt 2 20))) + (port-forwardings `((27017 . ,port))))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (srfi srfi-11) (srfi srfi-64) + (gnu build marionette) + (ice-9 rdelim)) + + (define marionette + (make-marionette (list #$vm))) + + (mkdir #$output) + (chdir #$output) + + (test-begin "mongodb") + + ;; Wait for mongodb to be up and running. + (test-assert "service running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (match (start-service 'mongodb) + (#f #f) + (('service response-parts ...) + (match (assq-ref response-parts 'running) + ((pid) (number? pid)))))) + marionette)) + + (test-eq "can connect" + 0 + (system* (string-append #$mongodb "/bin/mongo") + "test" + "--eval" + "help")) + + (test-end) + (exit (= (test-runner-fail-count (test-runner-current)) 0))))) + + (gexp->derivation "mongodb-test" test)) + +(define %test-mongodb + (system-test + (name "mongodb") + (description "Connect to a running MONGODB server.") + (value (run-mongodb-test)))) + +%mongodb-os -- 2.14.1