guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Mathieu Othacehe
Date: Tue, 9 Mar 2021 12:15:13 -0500 (EST)

branch: master
commit d13314d02d7b2c7d2812fe90e0fd6e0b5082ffec
Author: Mathieu Othacehe <othacehe@gnu.org>
AuthorDate: Tue Mar 9 18:06:57 2021 +0100

    tests: Add a common module.
    
    * tests/common.scm: New file.
    * tests/database.scm: Use it.
    * tests/http.scm: Ditto.
    * tests/metrics.scm: Ditto.
---
 tests/common.scm   | 36 ++++++++++++++++++++++++++++++++++++
 tests/database.scm | 11 ++---------
 tests/http.scm     | 18 +++++-------------
 tests/metrics.scm  | 10 ++--------
 4 files changed, 45 insertions(+), 30 deletions(-)

diff --git a/tests/common.scm b/tests/common.scm
new file mode 100644
index 0000000..6b52d31
--- /dev/null
+++ b/tests/common.scm
@@ -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))))))
diff --git a/tests/database.scm b/tests/database.scm
index 8321ce0..9c6f192 100644
--- a/tests/database.scm
+++ b/tests/database.scm
@@ -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"
diff --git a/tests/http.scm b/tests/http.scm
index 776b8db..177cdca 100644
--- a/tests/http.scm
+++ b/tests/http.scm
@@ -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))))))
 
diff --git a/tests/metrics.scm b/tests/metrics.scm
index e7ab5ff..8e5daba 100644
--- a/tests/metrics.scm
+++ b/tests/metrics.scm
@@ -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"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]