aboutsummaryrefslogtreecommitdiff
path: root/gnu/tests
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2017-10-06 21:24:30 +0100
committerChristopher Baines <mail@cbaines.net>2017-10-06 21:24:30 +0100
commit5266ff719e274056cb3e2b9740183f0063177255 (patch)
tree6cb4b938f8d00566425762fba3799cc3105cf915 /gnu/tests
parent6bbbca90736b6a34776a4ef15e954c80d8085878 (diff)
downloadpatches-5266ff719e274056cb3e2b9740183f0063177255.tar
patches-5266ff719e274056cb3e2b9740183f0063177255.tar.gz
services: Add MongoDB.
* gnu/services/databases.scm (%default-mongodb-configuration-file, %mongodb-accounts, mongodb-service-type): New variables. (<mongodb-configuration>): New record type. (mongodb-activation, mongodb-shepherd-service): New procedures. * gnu/tests/databases.scm (%test-mongodb): New variable. * doc/guix.texi (Database Services): Add MongoDB documentation.
Diffstat (limited to 'gnu/tests')
-rw-r--r--gnu/tests/databases.scm86
1 files changed, 85 insertions, 1 deletions
diff --git a/gnu/tests/databases.scm b/gnu/tests/databases.scm
index 9d9a753747..9e335b27c6 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,85 @@
(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)))
+ (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 popen)
+ (ice-9 rdelim))
+
+ (define marionette
+ (make-marionette (list #$vm)))
+
+ (mkdir #$output)
+ (chdir #$output)
+
+ (test-begin "mongodb")
+
+ (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 "test insert"
+ 0
+ (system* (string-append #$mongodb "/bin/mongo")
+ "test"
+ "--eval"
+ "db.testCollection.insert({data: 'test-data'})"))
+
+ (test-equal "test find"
+ "test-data"
+ (let* ((port (open-pipe*
+ OPEN_READ
+ (string-append #$mongodb "/bin/mongo")
+ "test"
+ "--quiet"
+ "--eval"
+ "db.testCollection.findOne().data"))
+ (output (read-line port))
+ (status (close-pipe port)))
+ output))
+
+ (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))))