tests: Add a common module.
* tests/common.scm: New file. * tests/database.scm: Use it. * tests/http.scm: Ditto. * tests/metrics.scm: Ditto.
This commit is contained in:
parent
2bd6e80482
commit
d13314d02d
|
@ -0,0 +1,36 @@
|
|||
;;; 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)
|
||||
#:export (%db
|
||||
test-init-db!))
|
||||
|
||||
(define %db
|
||||
(make-parameter #f))
|
||||
|
||||
(define (test-init-db!)
|
||||
"Initialize the test database."
|
||||
(%create-database? #t)
|
||||
(%cuirass-database "test_tmp")
|
||||
(%db (db-open))
|
||||
(%db-channel (make-worker-thread-channel
|
||||
(lambda ()
|
||||
(list (%db))))))
|
|
@ -26,6 +26,7 @@
|
|||
(cuirass remote)
|
||||
(cuirass specification)
|
||||
(cuirass utils)
|
||||
(tests common)
|
||||
(guix channels)
|
||||
((guix utils) #:select (call-with-temporary-output-file))
|
||||
(rnrs io ports)
|
||||
|
@ -102,20 +103,12 @@
|
|||
(systems '("a" "b"))
|
||||
(last-seen 1)))
|
||||
|
||||
(define %db
|
||||
(make-parameter #f))
|
||||
|
||||
(define db-name "test_database")
|
||||
(%record-events? #t)
|
||||
|
||||
(test-group-with-cleanup "database"
|
||||
(test-assert "db-init"
|
||||
(begin
|
||||
(%create-database? #t)
|
||||
(%db (db-open))
|
||||
(%db-channel (make-worker-thread-channel
|
||||
(lambda ()
|
||||
(list (%db)))))
|
||||
(test-init-db!)
|
||||
#t))
|
||||
|
||||
(test-equal "db-add-specification"
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
(cuirass database)
|
||||
(cuirass specification)
|
||||
(cuirass utils)
|
||||
(tests common)
|
||||
(guix channels)
|
||||
(json)
|
||||
(fibers)
|
||||
|
@ -51,9 +52,6 @@
|
|||
(define (test-cuirass-uri route)
|
||||
(string-append "http://localhost:6688" route))
|
||||
|
||||
(define %db
|
||||
(make-parameter #f))
|
||||
|
||||
(define build-query-result
|
||||
'((#:id . 1)
|
||||
(#:evaluation . 1)
|
||||
|
@ -69,11 +67,9 @@
|
|||
(#:buildstatus . 0)
|
||||
(#:weather . -1)
|
||||
(#:busy . 0)
|
||||
(#:priority . 0)
|
||||
(#:priority . 9)
|
||||
(#:finished . 1)
|
||||
(#:buildproducts . #())
|
||||
(#:releasename . #nil)
|
||||
(#:buildinputs_builds . #nil)))
|
||||
(#:buildproducts . #())))
|
||||
|
||||
(define evaluations-query-result
|
||||
#(((#:id . 2)
|
||||
|
@ -110,11 +106,7 @@
|
|||
|
||||
(test-assert "db-init"
|
||||
(begin
|
||||
(%create-database? #t)
|
||||
(%db (db-open))
|
||||
(%db-channel (make-worker-thread-channel
|
||||
(lambda ()
|
||||
(list (%db)))))
|
||||
(test-init-db!)
|
||||
#t))
|
||||
|
||||
(test-assert "cuirass-run"
|
||||
|
@ -247,7 +239,7 @@
|
|||
(test-cuirass-uri
|
||||
"/api/latestbuilds?nr=1&jobset=guix"))))
|
||||
(#(build)
|
||||
(lset= equal? build
|
||||
(lset= equal? (pk build)
|
||||
(json-string->scm
|
||||
(object->json-string build-query-result))))))
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
(use-modules (cuirass database)
|
||||
(cuirass metrics)
|
||||
(cuirass utils)
|
||||
(tests common)
|
||||
((guix utils) #:select (call-with-temporary-output-file))
|
||||
(squee)
|
||||
(srfi srfi-64))
|
||||
|
@ -31,17 +32,10 @@
|
|||
(define yesterday
|
||||
(- today 86400))
|
||||
|
||||
(define %db
|
||||
(make-parameter #f))
|
||||
|
||||
(test-group-with-cleanup "database"
|
||||
(test-assert "db-init"
|
||||
(begin
|
||||
(%create-database? #t)
|
||||
(%db (db-open))
|
||||
(%db-channel (make-worker-thread-channel
|
||||
(lambda ()
|
||||
(list (%db)))))
|
||||
(test-init-db!)
|
||||
#t))
|
||||
|
||||
(test-assert "exec-query"
|
||||
|
|
Loading…
Reference in New Issue