aboutsummaryrefslogtreecommitdiff
path: root/tests/store-database.scm
blob: 4d9188425056612d67ee434e33662316c6b36dbf (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017, 2018 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix 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.
;;;
;;; GNU Guix 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 GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-store-database)
  #:use-module (guix tests)
  #:use-module (guix store)
  #:use-module (guix store database)
  #:use-module ((guix utils) #:select (call-with-temporary-output-file))
  #:use-module (srfi srfi-26)
  #:use-module (srfi srfi-64))

;; Test the (guix store database) module.

(define %store
  (open-connection-for-tests))


(test-begin "store-database")

(test-equal "register-path"
  '(1 1)
  (let ((file (string-append (%store-prefix) "/" (make-string 32 #\f)
                             "-fake")))
    (when (valid-path? %store file)
      (delete-paths %store (list file)))
    (false-if-exception (delete-file file))

    (let ((ref (add-text-to-store %store "ref-of-fake" (random-text)))
          (drv (string-append file ".drv")))
      (call-with-output-file file
        (cut display "This is a fake store item.\n" <>))
      (register-path file
                     #:references (list ref)
                     #:deriver drv)

      (and (valid-path? %store file)
           (equal? (references %store file) (list ref))
           (null? (valid-derivers %store file))
           (null? (referrers %store file))
           (list (stat:mtime (lstat file))
                 (stat:mtime (lstat ref)))))))

(test-equal "new database"
  (list 1 2)
  (call-with-temporary-output-file
   (lambda (db-file port)
     (delete-file db-file)
     (with-database db-file db
       (sqlite-register db
                        #:path "/gnu/foo"
                        #:references '()
                        #:deriver "/gnu/foo.drv"
                        #:hash (string-append "sha256:" (make-string 64 #\e))
                        #:nar-size 1234)
       (sqlite-register db
                        #:path "/gnu/bar"
                        #:references '("/gnu/foo")
                        #:deriver "/gnu/bar.drv"
                        #:hash (string-append "sha256:" (make-string 64 #\a))
                        #:nar-size 4321)
       (let ((path-id (@@ (guix store database) path-id)))
         (list (path-id db "/gnu/foo")
               (path-id db "/gnu/bar")))))))

(test-assert "register-path with unregistered references"
  ;; Make sure we get a "NOT NULL constraint failed: Refs.reference" error
  ;; when we try to add references that are not registered yet.  Better safe
  ;; than sorry.
  (call-with-temporary-output-file
   (lambda (db-file port)
     (delete-file db-file)
     (catch 'sqlite-error
       (lambda ()
         (with-database db-file db
           (sqlite-register db #:path "/gnu/foo"
                            #:references '("/gnu/bar")
                            #:deriver "/gnu/foo.drv"
                            #:hash (string-append "sha256:" (make-string 64 #\e))
                            #:nar-size 1234))
         #f)
       (lambda args
         (pk 'welcome-exception! args)
         #t)))))

(test-end "store-database")
7440 26BA 7CA3 C668 E940 1D53 0B43 1E98 3705 6942" (name "ipetkov")) (;; primary: "66A5 6D9C 9A98 BE7F 719A B401 2652 5665 AE72 7D37" "0325 78A6 8298 94E7 2AA2 66F5 D415 BF25 3B51 5976" (name "iyzsong")) ("1A85 8392 E331 EAFD B8C2 7FFB F3C1 A0D9 C1D6 5273" (name "janneke")) (;; primary: "1BA4 08C5 8BF2 0EA7 3179 635A 865D C0A3 DED9 B5D0" "E31D 9DDE EBA5 4A14 8A20 4550 DA45 97F9 47B4 1025" (name "jlicht")) ("83B6 703A DCCA 3B69 4BCE 2DA6 E6A5 EE3C 1946 7A0D" (name "kkebreau")) ("45E5 75FA 53EA 8BD6 1BCE 0B4E 3ADC 75F0 13D6 78F9" (name "leungbk")) (;; primary: "4F71 6F9A 8FA2 C80E F1B5 E1BA 5E35 F231 DE1A C5E0" "B051 5948 F1E7 D3C1 B980 38A0 2646 FA30 BACA 7F08" (name "lfam")) ("2AE3 1395 932B E642 FC0E D99C 9BED 6EDA 32E5 B0BC" (name "lsl88")) ("CBF5 9755 CBE7 E7EF EF18 3FB1 DD40 9A15 D822 469D" (name "marusich")) ("BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA" (name "mbakke")) ("D919 0965 CE03 199E AF28 B3BE 7CEF 2984 7562 C516" (name "mhw")) ("4008 6A7E 0252 9B60 31FB 8607 8354 7635 3176 9CA6" (name "mothacehe")) (;; primary: "F5BC 5534 C36F 0087 B39D 36EF 1C9D C4FE B9DB 7C4B" "F5DA 2032 4B87 3D0B 7A38 7672 0DB0 FF88 4F55 6D79" (name "nckx")) ("E576 BFB2 CF6E B13D F571 33B9 E315 A758 4613 1564" (name "niedzejkob")) ("ED0E F1C8 E126 BA83 1B48 5FE9 DA00 B4F0 48E9 2F2D" (name "ngz")) ("CEF4 CB91 4856 BA38 0A20 A7E2 3008 88CB 39C6 3817" (name "pelzflorian")) (;; primary: "B68B DF22 73F9 DA0E 63C1 8A32 515B F416 9242 D600" "C699 ED09 E51B CE89 FD1D A078 AAC7 E891 896B 568A" (name "pgarlick")) ("3A86 380E 58A8 B942 8D39 60E1 327C 1EF3 8DF5 4C32" (name "phant0mas")) ("74D6 A930 F44B 9B84 9EA5 5606 C166 AA49 5F7F 189C" (name "reepca")) ("BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAC" (name "rekado")) ("0154 E1B9 1CC9 D9EF 7764 8DE7 F3A7 27DB 44FC CA36" (name "rhelling")) (;; From commit cc51c03ff867d4633505354819c6d88af88bf919 (March 2020). ;; See <https://lists.gnu.org/archive/html/guix-devel/2020-03/msg00070.html>. "F556 FD94 FB8F 8B87 79E3 6832 CBD0 CD51 38C1 9AFC" (name "roelj")) (;; From commit 2cbede5935eb6a40173bbdf30a9ad22bf7574c22 (Jan. 2020). See ;; <https://lists.gnu.org/archive/html/guix-devel/2020-01/msg00499.html>. "1EFB 0909 1F17 D28C CBF9 B13A 53D4 57B2 D636 EE82" (name "roptat")) (;; primary: "D6B0 C593 DA8C 5EDC A44C 7A58 C336 91F7 1188 B004" "A02C 2D82 0EF4 B25B A6B5 1D90 2AC6 A5EC 1C35 7C59" (name "samplet")) ("77DD AD2D 97F5 31BB C0F3 C7FD DFB5 EB09 AA62 5423" (name "sleep_walker")) ("F494 72F4 7A59 00D5 C235 F212 89F9 6D48 08F3 59C7" (name "snape")) ("9ADE 9ECF 2B19 C180 9C99 5CEA A1F4 CFCC 5283 6BAC" (name "taylanub")) ;; https://lists.gnu.org/archive/html/guix-devel/2017-03/msg00826.html (;; primary: "1DD1 681F E285 E07F 11DC 0C59 2E15 A6BC D77D 54FD" "3D2C DA58 819C 08C2 A649 D43D 5C3B 064C 724A 5726" (name "thomasd")) ("6580 7361 3BFC C5C7 E2E4 5D45 DC51 8FC8 7F97 16AA" (name "vagrantc")) (;; primary: "C955 CC5D C048 7FB1 7966 40A9 199A F6A3 67E9 4ABB" "7238 7123 8EAC EB63 4548 5857 167F 8EA5 001A FA9C" (name "wigust")) ("FF47 8FB2 64DE 32EC 2967 25A3 DDC0 F535 8812 F8F2" (name "wingo"))))