2
0
Fork 0
mirror of git://git.savannah.gnu.org/guix/guix-cuirass.git synced 2023-12-14 06:03:04 +01:00
guix-cuirass/tests/common.scm
Mathieu Othacehe 50b423c2cd
Use EphemeralPG for the tests.
* README: Update dependencies.
* tests/common.scm (pg-tmp): New procedure.
(test-init-db!): Use it.
* tests/database.scm ("db-close"): Do not drop database content.
* tests/http.scm: Ditto.
* tests/metrics.scm: Ditto.
2021-03-10 07:46:17 +01:00

47 lines
1.5 KiB
Scheme

;;; common.scm -- Common test helpers.
;;; Copyright © 2021 Mathieu Othacehe <othacehe@gnu.org>
;;;
;;; This file is part of Cuirass.
;;;
;;; Cuirass is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; Cuirass is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with Cuirass. If not, see <http://www.gnu.org/licenses/>.
(define-module (tests common)
#:use-module (cuirass database)
#:use-module (cuirass parameters)
#:use-module (cuirass utils)
#:use-module (ice-9 popen)
#:use-module (ice-9 rdelim)
#:export (%db
test-init-db!))
(define %db
(make-parameter #f))
(define (pg-tmp)
"Start a temporary PostgreSQL instance using ephemeralpg."
;; Destroy the database right after disconnection.
(let* ((pipe (open-input-pipe "pg_tmp -w 1"))
(uri (read-string pipe)))
(close-pipe pipe)
uri))
(define (test-init-db!)
"Initialize the test database."
(%create-database? #t)
(%package-database (pg-tmp))
(%db (db-open))
(%db-channel (make-worker-thread-channel
(lambda ()
(list (%db))))))