diff options
| author | Christopher Baines <mail@cbaines.net> | 2017-10-06 21:24:30 +0100 |
|---|---|---|
| committer | Christopher Baines <mail@cbaines.net> | 2017-10-06 21:24:30 +0100 |
| commit | 5266ff719e274056cb3e2b9740183f0063177255 (patch) | |
| tree | 6cb4b938f8d00566425762fba3799cc3105cf915 /gnu/tests/databases.scm | |
| parent | 6bbbca90736b6a34776a4ef15e954c80d8085878 (diff) | |
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/databases.scm')
| -rw-r--r-- | gnu/tests/databases.scm | 86 |
1 files changed, 85 insertions, 1 deletions
diff --git a/gnu/tests/databases.scm b/gnu/tests/databases.scm index 9d9a7537479..9e335b27c67 100644 --- a/gnu/tests/databases.scm +++ b/gnu/tests/databases.scm | |||
| @@ -25,9 +25,11 @@ | |||
| 25 | #:use-module (gnu services) | 25 | #:use-module (gnu services) |
| 26 | #:use-module (gnu services databases) | 26 | #:use-module (gnu services databases) |
| 27 | #:use-module (gnu services networking) | 27 | #:use-module (gnu services networking) |
| 28 | #:use-module (gnu packages databases) | ||
| 28 | #:use-module (guix gexp) | 29 | #:use-module (guix gexp) |
| 29 | #:use-module (guix store) | 30 | #:use-module (guix store) |
| 30 | #:export (%test-memcached)) | 31 | #:export (%test-memcached |
| 32 | %test-mongodb)) | ||
| 31 | 33 | ||
| 32 | (define %memcached-os | 34 | (define %memcached-os |
| 33 | (simple-operating-system | 35 | (simple-operating-system |
| @@ -121,3 +123,85 @@ | |||
| 121 | (name "memcached") | 123 | (name "memcached") |
| 122 | (description "Connect to a running MEMCACHED server.") | 124 | (description "Connect to a running MEMCACHED server.") |
| 123 | (value (run-memcached-test)))) | 125 | (value (run-memcached-test)))) |
| 126 | |||
| 127 | (define %mongodb-os | ||
| 128 | (operating-system | ||
| 129 | (inherit | ||
| 130 | (simple-operating-system | ||
| 131 | (dhcp-client-service) | ||
| 132 | (service mongodb-service-type))) | ||
| 133 | (packages (cons* mongodb | ||
| 134 | %base-packages)))) | ||
| 135 | |||
| 136 | (define* (run-mongodb-test #:optional (port 27017)) | ||
| 137 | "Run tests in %MONGODB-OS, forwarding PORT." | ||
| 138 | (define os | ||
| 139 | (marionette-operating-system | ||
| 140 | %mongodb-os | ||
| 141 | #:imported-modules '((gnu services herd) | ||
| 142 | (guix combinators)))) | ||
| 143 | |||
| 144 | (define vm | ||
| 145 | (virtual-machine | ||
| 146 | (operating-system os) | ||
| 147 | (memory-size 1024) | ||
| 148 | (disk-image-size (* 1024 (expt 2 20))) | ||
| 149 | (port-forwardings `((27017 . ,port))))) | ||
| 150 | |||
| 151 | (define test | ||
| 152 | (with-imported-modules '((gnu build marionette)) | ||
| 153 | #~(begin | ||
| 154 | (use-modules (srfi srfi-11) (srfi srfi-64) | ||
| 155 | (gnu build marionette) | ||
| 156 | (ice-9 popen) | ||
| 157 | (ice-9 rdelim)) | ||
| 158 | |||
| 159 | (define marionette | ||
| 160 | (make-marionette (list #$vm))) | ||
| 161 | |||
| 162 | (mkdir #$output) | ||
| 163 | (chdir #$output) | ||
| 164 | |||
| 165 | (test-begin "mongodb") | ||
| 166 | |||
| 167 | (test-assert "service running" | ||
| 168 | (marionette-eval | ||
| 169 | '(begin | ||
| 170 | (use-modules (gnu services herd)) | ||
| 171 | (match (start-service 'mongodb) | ||
| 172 | (#f #f) | ||
| 173 | (('service response-parts ...) | ||
| 174 | (match (assq-ref response-parts 'running) | ||
| 175 | ((pid) (number? pid)))))) | ||
| 176 | marionette)) | ||
| 177 | |||
| 178 | (test-eq "test insert" | ||
| 179 | 0 | ||
| 180 | (system* (string-append #$mongodb "/bin/mongo") | ||
| 181 | "test" | ||
| 182 | "--eval" | ||
| 183 | "db.testCollection.insert({data: 'test-data'})")) | ||
| 184 | |||
| 185 | (test-equal "test find" | ||
| 186 | "test-data" | ||
| 187 | (let* ((port (open-pipe* | ||
| 188 | OPEN_READ | ||
| 189 | (string-append #$mongodb "/bin/mongo") | ||
| 190 | "test" | ||
| 191 | "--quiet" | ||
| 192 | "--eval" | ||
| 193 | "db.testCollection.findOne().data")) | ||
| 194 | (output (read-line port)) | ||
| 195 | (status (close-pipe port))) | ||
| 196 | output)) | ||
| 197 | |||
| 198 | (test-end) | ||
| 199 | (exit (= (test-runner-fail-count (test-runner-current)) 0))))) | ||
| 200 | |||
| 201 | (gexp->derivation "mongodb-test" test)) | ||
| 202 | |||
| 203 | (define %test-mongodb | ||
| 204 | (system-test | ||
| 205 | (name "mongodb") | ||
| 206 | (description "Connect to a running MONGODB server.") | ||
| 207 | (value (run-mongodb-test)))) | ||
