aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017-2018, 2020-2021, 2024 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 build store-copy)
  #:use-module ((guix build utils)
                #:select (mkdir-p delete-file-recursively
                          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-assert "register-items"
  (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" <>))
      (reset-timestamps file)
      (with-database (store-database-file) db
        (register-items db (list (store-info file drv (list ref)))))

      (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 "register-items, directory"
  '(1 1 1)
  (let ((file (string-append (%store-prefix) "/" (make-string 32 #\f)
                             "-fake-directory")))
    (when (valid-path? %store file)
      (delete-paths %store (list file)))
    (false-if-exception (delete-file-recursively file))

    (let ((drv (string-append file ".drv")))
      (mkdir-p (string-append file "/a"))
      (call-with-output-file (string-append file "/a/b")
        (const #t))
      (reset-timestamps file)
      (with-database (store-database-file) db
        (register-items db (list (store-info file drv '()))))

      (and (valid-path? %store file)
           (null? (references %store file))
           (null? (valid-derivers %store file))
           (null? (referrers %store file))
           (list (stat:mtime (lstat file))
                 (stat:mtime (lstat (string-append file "/a")))
                 (stat:mtime (lstat (string-append file "/a/b"))))))))

(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
       (register-valid-path db
                            #:path "/gnu/foo"
                            #:references '()
                            #:deriver "/gnu/foo.drv"
                            #:hash (string-append "sha256:" (make-string 64 #\e))
                            #:nar-size 1234)
       (register-valid-path db
                            #:path "/gnu/bar"
                            #:references '("/gnu/foo")
                            #:deriver "/gnu/bar.drv"
                            #:hash (string-append "sha256:" (make-string 64 #\a))
                            #:nar-size 4321)
       (list (valid-path-id db "/gnu/foo")
             (valid-path-id db "/gnu/bar"))))))

(test-assert "register-valid-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
           (register-valid-path 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-equal "register-valid-path with incorrect size"
  'out-of-range
  (call-with-temporary-output-file
   (lambda (db-file port)
     (delete-file db-file)
     (catch #t
       (lambda ()
         (with-database db-file db
           (register-valid-path db #:path "/gnu/foo"
                                #:references '("/gnu/bar")
                                #:deriver "/gnu/foo.drv"
                                #:hash (string-append "sha256:" (make-string 64 #\e))
                                #:nar-size -1234))
         #f)
       (lambda (key . _)
         key)))))

(test-end "store-database")
21-05-03 09:29:45 -0400'>2021-05-03nls: Remove the doc-po-update target....As discussed with Julien Lepiller on IRC, updating the PO files is not useful. This change removes the target and associated rules that allowed updating them. This has the benefit of not having the PO files updated automatically when generating the .pot files, which was causing spurious changes under the po sub-directory. * po/doc/local.mk (make-update-po-files-rule): Remove function and its uses. (doc-po-update): Remove target. Maxim Cournoyer 2021-04-30build: Correct a mistake in the guix-manual.pot rule....This is a follow-up to commit 0d353b06ec. * po/doc/local.mk: Fix function name in comment. (%D%/guix-manual.pot): Refer to *all* the prerequisites via the $^ special variable rather than $<, which only refers to the first one. Reported-by: Julien Lepiller <julien@lepiller.eu> Maxim Cournoyer 2021-04-29build: Make doc-po-update and doc-pot-update targets idempotent....It used to be that the running the doc-po-update and doc-pot-update targets would redo the same work on every run. This change splits the problem in smaller chunks and specifies build dependencies in a way that outputs only get rebuilt when their inputs changed. * po/doc/local.mk (DOC_PO_FILES): Harmonize escapes. (POT_OPTIONS): Re-indent uniformly. (doc-po-update-%, doc-po-update-cookbook-%): Re-implement with... (make-update-po-files-rule): ... this new function. (TMP_POT_FILES): Remove variable. (%D%/%.pot, %D%/guix-manual.pot): New pattern rules. (doc-pot-update, doc-po-update): Adjust prerequisites accordingly. Maxim Cournoyer 2021-04-29build: Build the guix.pot-update and contributing.pot-update targets only once....* po/doc/local.mk (doc-pot-update): Fix an issue where guix.pot-update an contributing.pot-update were built twice. Maxim Cournoyer 2021-04-18nls: Fix Chinese cookbook inclusion....* po/doc/local.mk: zh_Hans is for the cookbook, not the manual. Julien Lepiller 2021-04-18nls: Update 'ru' translation.Julien Lepiller 2021-04-18nls: Add Chinese (Traditional) translation....* po/doc/guix-cookbook.zh_Hans.po: New file. * doc/local.mk (info_TEXINFOS): Add it. * po/doc/local.mk (DOC_COOKBOOK_PO_FILES): Add it. Julien Lepiller 2021-04-18nls: Add Korean translation....* po/doc/guix-cookbook.ko.po: New file. * po/doc/guix-manual.ko.po: New file. * doc/local.mk (info_TEXINFOS): Add them. * po/doc/local.mk (DOC_PO_FILES, DOC_COOKBOOK_PO_FILES): Add them. * po/guix/ko.po: New file. * po/guix/LINGUAS: Add 'ko'. * po/packages/ko.po: New file. * po/packages/LINGUAS: Add 'ko'. Julien Lepiller 2021-04-18nls: Add Italian translation....* po/doc/guix-manual.it.po: New file. * po/doc/local.mk (DOC_PO_FILES): Add it. * doc/local.mk (info_TEXINFOS): Add it. * po/guix/it.po: New file. * po/guix/LINGUAS: Add 'it'. Julien Lepiller 2021-04-18nls: Add Persian translation....* po/packages/fa.po: New file. * po/packages/LINGUAS: Add 'fa'. * po/doc/guix-cookbook.fa.po: New file. * po/doc/guix-manual.fa.po: New file. * po/doc/local.mk (DOC_PO_FILES, DOC_COOKBOOK_PO_FILES): Add them. * doc/local.mk (info_TEXINFOS): Add them. Julien Lepiller 2021-04-18nls: Add Slovak translation....* po/packages/sk.po: New file. * po/packages/LINGUAS: Add 'sk'. * po/doc/guix-manual.sk.po: New file. * doc/local.mk (info_TEXINFOS): Add it. * po/doc/local.mk (DOC_PO_FILES): Add it. Julien Lepiller 2021-04-18nls: Add Portuguese (Brazil) translation of the manual.Julien Lepiller 2021-04-18nls: Update 'zh_CN' translations.Julien Lepiller 2021-04-18nls: Update 'es' translations.Julien Lepiller 2021-04-18nls: Update 'de' translations.Julien Lepiller 2021-04-18nls: Update 'fr' translations.Julien Lepiller 2021-04-18nls: Add French translation of the cookbook.Julien Lepiller 2021-01-28nls: Update 'fr' translation.Julien Lepiller 2021-01-22Revert "nls: Update 'fr' translation."...This reverts commit 5d03ef73c3c1d995714abdaff650f73ac9fafc0f, which led to these errors: /gnu/store/…-guix/fr.po:7206: 'msgstr' is not a valid Scheme format string, unlike 'msgid'. Reason: In the directive number 3, the character ' ' is not a valid conversion specifier. /gnu/store/…-guix/fr.po:7554: format specifications in 'msgid' and 'msgstr' are not equivalent /gnu/store/…-gettext-minimal-0.20.1/bin/msgfmt: found 2 fatal errors Ludovic Courtès 2021-01-22nls: Update 'fr' translation.Julien Lepiller 2020-12-03nls: Update 'fr' translation of the manual.Ludovic Courtès 2020-11-21nls: Update 'fr' translation of the manual.Ludovic Courtès 2020-11-12nls: Update translations of the manual.Ludovic Courtès 2020-11-12nls: Update translations of the manual.Julien Lepiller 2020-11-03nls: Fix Texinfo typo....* po/doc/guix-manual.de.po: Fix ‘@sasmp{}’ that broke ‘make’. Tobias Geerinckx-Rice 2020-11-03nls: Update translations of the manual.Julien Lepiller 2020-11-01nls: Update ‘de’ cookbook translation.Florian Pelz 2020-10-30nls: Update 'fr' translation of the manual.Julien Lepiller 2020-10-29nls: Update 'ru' translation of the manual.Julien Lepiller 2020-10-27nls: Update.Ludovic Courtès 2020-10-16nls: Update manual translations.Ludovic Courtès 2020-09-29nls: Fix documentation pot generation....* po/doc/local.mk: Fix POT_OPTIONS to properly assign copyright and define the proper license. Julien Lepiller