Add (gnu store database).
[jackhill/guix/guix.git] / tests / store-database.scm
CommitLineData
7f9d184d
CR
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017, 2018 Ludovic Courtès <ludo@gnu.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
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.
10;;;
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.
15;;;
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/>.
18
19(define-module (test-store-database)
20 #:use-module (guix tests)
21 #:use-module ((guix store) #:hide (register-path))
22 #:use-module (guix store database)
23 #:use-module (srfi srfi-26)
24 #:use-module (srfi srfi-64))
25
26;; Test the (guix store database) module.
27
28(define %store
29 (open-connection-for-tests))
30
31\f
32(test-begin "store-database")
33
34(test-assert "register-path"
35 (let ((file (string-append (%store-prefix) "/" (make-string 32 #\f)
36 "-fake")))
37 (when (valid-path? %store file)
38 (delete-paths %store (list file)))
39 (false-if-exception (delete-file file))
40
41 (let ((ref (add-text-to-store %store "ref-of-fake" (random-text)))
42 (drv (string-append file ".drv")))
43 (call-with-output-file file
44 (cut display "This is a fake store item.\n" <>))
45 (register-path file
46 #:references (list ref)
47 #:deriver drv)
48
49 (and (valid-path? %store file)
50 (equal? (references %store file) (list ref))
51 (null? (valid-derivers %store file))
52 (null? (referrers %store file))))))
53
54(test-end "store-database")