diff options
author | Marius Bakke <marius@gnu.org> | 2022-02-13 14:24:53 +0100 |
---|---|---|
committer | Marius Bakke <marius@gnu.org> | 2022-02-13 14:24:53 +0100 |
commit | 76b6bbdf232b4b82cdd23cfe0d81331a4fd2edec (patch) | |
tree | 0e6a57ba08b9c6f9f5cbcdc5b5d9daeea91e428d /gnu/tests | |
parent | 1a5302435ff0d2822b823f5a6fe01faa7a85c629 (diff) | |
parent | e8af2ea63a7f497b8f8e19e206645109c0646e72 (diff) |
Merge branch 'master' into staging
Diffstat (limited to 'gnu/tests')
-rw-r--r-- | gnu/tests/databases.scm | 141 | ||||
-rw-r--r-- | gnu/tests/guix.scm | 81 |
2 files changed, 218 insertions, 4 deletions
diff --git a/gnu/tests/databases.scm b/gnu/tests/databases.scm index a20de1a8c7..296d91d118 100644 --- a/gnu/tests/databases.scm +++ b/gnu/tests/databases.scm @@ -1,6 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017 Christopher Baines <mail@cbaines.net> -;;; Copyright © 2020 Marius Bakke <marius@gnu.org> +;;; Copyright © 2020, 2022 Marius Bakke <marius@gnu.org> ;;; ;;; This file is part of GNU Guix. ;;; @@ -29,10 +29,16 @@ #:use-module (gnu packages databases) #:use-module (guix gexp) #:use-module (guix store) + #:use-module (srfi srfi-1) #:export (%test-memcached %test-postgresql + %test-timescaledb %test-mysql)) +;;; +;;; The Memcached service. +;;; + (define %memcached-os (simple-operating-system (service dhcp-client-service-type) @@ -138,7 +144,7 @@ (simple-operating-system (service postgresql-service-type (postgresql-configuration - (postgresql postgresql-10) + (postgresql postgresql) (config-file (postgresql-config-file (extra-config @@ -245,6 +251,137 @@ (description "Start the PostgreSQL service.") (value (run-postgresql-test)))) +;; Test TimescaleDB, a PostgreSQL extension. +(define %timescaledb-os + (let* ((postgresql-services (operating-system-services %postgresql-os)) + (postgresql-service-configuration + (service-value (find (lambda (svc) + (eq? (service-kind svc) postgresql-service-type)) + postgresql-services))) + (postgresql-role-service-configuration + (service-value (find (lambda (svc) + (eq? (service-kind svc) + postgresql-role-service-type)) + postgresql-services)))) + (simple-operating-system + (service postgresql-service-type + (postgresql-configuration + (inherit postgresql-service-configuration) + (extension-packages (list timescaledb)) + (config-file + (postgresql-config-file + (inherit (postgresql-configuration-file + postgresql-service-configuration)) + (extra-config + (append '(("shared_preload_libraries" "timescaledb")) + (postgresql-config-file-extra-config + (postgresql-configuration-file + postgresql-service-configuration)))))))) + (service postgresql-role-service-type + (postgresql-role-configuration + (inherit postgresql-role-service-configuration)))))) + +(define (run-timescaledb-test) + "Run tests in %TIMESCALEDB-OS." + (define os + (marionette-operating-system + %timescaledb-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-64) + (gnu build marionette)) + + (define marionette + (make-marionette (list #$vm))) + + (test-runner-current (system-test-runner #$output)) + (test-begin "timescaledb") + + (test-assert "PostgreSQL running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (start-service 'postgres)) + marionette)) + + (test-assert "database ready" + (begin + (marionette-eval + '(begin + (let loop ((i 10)) + (unless (or (zero? i) + (and (file-exists? #$%role-log-file) + (string-contains + (call-with-input-file #$%role-log-file + get-string-all) + ";\nCREATE DATABASE"))) + (sleep 1) + (loop (- i 1))))) + marionette))) + + (test-assert "database creation" + (marionette-eval + '(begin + (current-output-port + (open-file "/dev/console" "w0")) + (invoke #$(file-append postgresql "/bin/psql") + "-tA" "-c" "CREATE DATABASE test")) + marionette)) + + (test-assert "load extension" + (marionette-eval + '(begin + (current-output-port (open-file "/dev/console" "w0")) + ;; Capture stderr for the next test. + (current-error-port (open-file "timescaledb.stderr" "w0")) + (invoke #$(file-append postgresql "/bin/psql") + "-tA" "-c" "CREATE EXTENSION timescaledb" + "test")) + marionette)) + + (test-assert "telemetry is disabled" + (marionette-eval + '(begin + (string-contains (call-with-input-file "timescaledb.stderr" + (lambda (port) + (get-string-all port))) + "Please enable telemetry")) + marionette)) + + (test-assert "create hypertable" + (marionette-eval + '(begin + (current-output-port (open-file "/dev/console" "w0")) + (invoke #$(file-append postgresql "/bin/psql") + "-tA" "-c" "CREATE TABLE ht ( +time TIMESTAMP NOT NULL, +data double PRECISION NULL +)" + "test") + (invoke #$(file-append postgresql "/bin/psql") + "-tA" "-c" "SELECT create_hypertable('ht','time')" + "test")) + marionette)) + + (test-end)))) + + (gexp->derivation "timescaledb-test" test)) + +(define %test-timescaledb + (system-test + (name "timescaledb") + (description "Test the TimescaleDB PostgreSQL extension.") + (value (run-timescaledb-test)))) + ;;; ;;; The MySQL service. diff --git a/gnu/tests/guix.scm b/gnu/tests/guix.scm index 69cac7c1aa..a4c3e35e5d 100644 --- a/gnu/tests/guix.scm +++ b/gnu/tests/guix.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2019 Christopher Baines <mail@cbaines.net> +;;; Copyright © 2019, 2020, 2021, 2022 Christopher Baines <mail@cbaines.net> ;;; ;;; This file is part of GNU Guix. ;;; @@ -36,7 +36,8 @@ #:use-module (guix utils) #:use-module (ice-9 match) #:export (%test-guix-build-coordinator - %test-guix-data-service)) + %test-guix-data-service + %test-nar-herder)) ;;; ;;; Guix Build Coordinator @@ -239,3 +240,79 @@ host all all ::1/128 trust")))))) (name "guix-data-service") (description "Connect to a running Guix Data Service.") (value (run-guix-data-service-test)))) + + +;;; +;;; Nar Herder +;;; + +(define %nar-herder-os + (simple-operating-system + (service dhcp-client-service-type) + (service nar-herder-service-type + (nar-herder-configuration + (host "0.0.0.0") + ;; Not a realistic value, but works for the test + (storage "/tmp"))))) + +(define (run-nar-herder-test) + (define os + (marionette-operating-system + %nar-herder-os + #:imported-modules '((gnu services herd) + (guix combinators)))) + + (define forwarded-port + (nar-herder-configuration-port + (nar-herder-configuration))) + + (define vm + (virtual-machine + (operating-system os) + (memory-size 1024) + (port-forwardings `((,forwarded-port . ,forwarded-port))))) + + (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 + (make-marionette (list #$vm))) + + (test-runner-current (system-test-runner #$output)) + (test-begin "nar-herder") + + (test-assert "service running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (match (start-service 'nar-herder) + (#f #f) + (('service response-parts ...) + (match (assq-ref response-parts 'running) + ((pid) (number? pid)))))) + marionette)) + + (test-equal "http-get" + 404 + (let-values + (((response text) + (http-get #$(simple-format + #f "http://localhost:~A/" forwarded-port) + #:decode-body? #t))) + (response-code response))) + + (test-end)))) + + (gexp->derivation "nar-herder-test" test)) + +(define %test-nar-herder + (system-test + (name "nar-herder") + (description "Connect to a running Nar Herder server.") + (value (run-nar-herder-test)))) |