1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (test-store-database)
20 #:use-module (guix tests)
21 #:use-module (guix store)
22 #:use-module (guix store database)
23 #:use-module ((guix utils) #:select (call-with-temporary-output-file))
24 #:use-module (srfi srfi-26)
25 #:use-module (srfi srfi-64))
27 ;; Test the (guix store database) module.
30 (open-connection-for-tests))
33 (test-begin "store-database")
35 (test-assert "register-path"
36 (let ((file (string-append (%store-prefix) "/" (make-string 32 #\f)
38 (when (valid-path? %store file)
39 (delete-paths %store (list file)))
40 (false-if-exception (delete-file file))
42 (let ((ref (add-text-to-store %store "ref-of-fake" (random-text)))
43 (drv (string-append file ".drv")))
44 (call-with-output-file file
45 (cut display "This is a fake store item.\n" <>))
47 #:references (list ref)
50 (and (valid-path? %store file)
51 (equal? (references %store file) (list ref))
52 (null? (valid-derivers %store file))
53 (null? (referrers %store file))))))
55 (test-equal "new database"
57 (call-with-temporary-output-file
58 (lambda (db-file port)
60 (with-database db-file db
64 #:deriver "/gnu/foo.drv"
65 #:hash (string-append "sha256:" (make-string 64 #\e))
69 #:references '("/gnu/foo")
70 #:deriver "/gnu/bar.drv"
71 #:hash (string-append "sha256:" (make-string 64 #\a))
73 (let ((path-id (@@ (guix store database) path-id)))
74 (list (path-id db "/gnu/foo")
75 (path-id db "/gnu/bar")))))))
77 (test-assert "register-path with unregistered references"
78 ;; Make sure we get a "NOT NULL constraint failed: Refs.reference" error
79 ;; when we try to add references that are not registered yet. Better safe
81 (call-with-temporary-output-file
82 (lambda (db-file port)
86 (with-database db-file db
87 (sqlite-register db #:path "/gnu/foo"
88 #:references '("/gnu/bar")
89 #:deriver "/gnu/foo.drv"
90 #:hash (string-append "sha256:" (make-string 64 #\e))
94 (pk 'welcome-exception! args)
97 (test-end "store-database")