You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.8 KiB

  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. (define-module (test-store-database)
  19. #:use-module (guix tests)
  20. #:use-module ((guix store) #:hide (register-path))
  21. #:use-module (guix store database)
  22. #:use-module ((guix utils) #:select (call-with-temporary-output-file))
  23. #:use-module (srfi srfi-26)
  24. #:use-module (srfi srfi-64))
  25. ;; Test the (guix store database) module.
  26. (define %store
  27. (open-connection-for-tests))
  28. (test-begin "store-database")
  29. (test-assert "register-path"
  30. (let ((file (string-append (%store-prefix) "/" (make-string 32 #\f)
  31. "-fake")))
  32. (when (valid-path? %store file)
  33. (delete-paths %store (list file)))
  34. (false-if-exception (delete-file file))
  35. (let ((ref (add-text-to-store %store "ref-of-fake" (random-text)))
  36. (drv (string-append file ".drv")))
  37. (call-with-output-file file
  38. (cut display "This is a fake store item.\n" <>))
  39. (register-path file
  40. #:references (list ref)
  41. #:deriver drv)
  42. (and (valid-path? %store file)
  43. (equal? (references %store file) (list ref))
  44. (null? (valid-derivers %store file))
  45. (null? (referrers %store file))))))
  46. (test-equal "new database"
  47. (list 1 2)
  48. (call-with-temporary-output-file
  49. (lambda (db-file port)
  50. (delete-file db-file)
  51. (sqlite-register #:db-file db-file
  52. #:path "/gnu/foo"
  53. #:references '()
  54. #:deriver "/gnu/foo.drv"
  55. #:hash (string-append "sha256:" (make-string 64 #\e))
  56. #:nar-size 1234)
  57. (sqlite-register #:db-file db-file
  58. #:path "/gnu/bar"
  59. #:references '("/gnu/foo")
  60. #:deriver "/gnu/bar.drv"
  61. #:hash (string-append "sha256:" (make-string 64 #\a))
  62. #:nar-size 4321)
  63. (let ((path-id (@@ (guix store database) path-id)))
  64. (with-database db-file db
  65. (list (path-id db "/gnu/foo")
  66. (path-id db "/gnu/bar")))))))
  67. (test-end "store-database")