Subject: [PATCH 3/4] tests: databases: Add a system test for PostgreSQL.

From: Christopher Baines <[email-masked]>
Date: Sun, 4 Mar 2018 19:16:32 +0000

* gnu/tests/databases.scm (%postgresql-os, %test-postgresql): New variables.
  (run-postgresql-test): New procedure.
---
 gnu/tests/databases.scm | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/gnu/tests/databases.scm b/gnu/tests/databases.scm
index e7097690a..0597105da 100644
--- a/gnu/tests/databases.scm
+++ b/gnu/tests/databases.scm
@@ -30,6 +30,7 @@
   #:use-module (guix store)
   #:export (%test-memcached
             %test-mongodb
+            %test-postgresql
             %test-mysql))
 
 (define %memcached-os
@@ -208,6 +209,64 @@
    (value (run-mongodb-test))))
 
 
+;;;
+;;; The PostgreSQL service.
+;;;
+
+(define %postgresql-os
+  (simple-operating-system
+   (service postgresql-service-type)))
+
+(define* (run-postgresql-test)
+  "Run tests in %POSTGRESQL-OS."
+  (define os
+    (marionette-operating-system
+     %postgresql-os
+     #:imported-modules '((gnu services herd)
+                          (guix combinators))))
+
+  (define vm
+    (virtual-machine
+     (operating-system os)
+     (memory-size 512)))
+
+  (define test
+    (with-imported-modules '((gnu build marionette))
+      #~(begin
+          (use-modules (srfi srfi-11) (srfi srfi-64)
+                       (gnu build marionette))
+
+          (define marionette
+            (make-marionette (list #$vm)))
+
+          (mkdir #$output)
+          (chdir #$output)
+
+          (test-begin "postgresql")
+
+          (test-assert "service running"
+            (marionette-eval
+             '(begin
+                (use-modules (gnu services herd))
+                (match (start-service 'postgres)
+                  (#f #f)
+                  (('service response-parts ...)
+                   (match (assq-ref response-parts 'running)
+                     ((pid) (number? pid))))))
+             marionette))
+
+          (test-end)
+          (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
+
+  (gexp->derivation "postgresql-test" test))
+
+(define %test-postgresql
+  (system-test
+   (name "postgresql")
+   (description "Start the PostgreSQL service.")
+   (value (run-postgresql-test))))
+
+
 ;;;
 ;;; The MySQL service.
 ;;;
-- 
2.16.0