repo.scm 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ;;;; repo.scm -- tests for (cuirass repo) module
  2. ;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
  3. ;;;
  4. ;;; This file is part of Cuirass.
  5. ;;;
  6. ;;; Cuirass is free software: you can redistribute it and/or modify
  7. ;;; it under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation, either version 3 of the License, or
  9. ;;; (at your option) any later version.
  10. ;;;
  11. ;;; Cuirass is distributed in the hope that it will be useful,
  12. ;;; but 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 Cuirass. If not, see <http://www.gnu.org/licenses/>.
  18. (use-modules (cuirass repo)
  19. (cuirass utils)
  20. (guix store)
  21. (srfi srfi-64))
  22. (test-begin "repo")
  23. (test-equal "<repo> datatype"
  24. ;; Check that all the procedures for manipulating <repo> objects are
  25. ;; exported and that the keywords of the constructor matches their slot.
  26. '(1 2 3 4 5 6)
  27. (let ((obj (repo #:id 1 #:url 2 #:location 3 #:ref 4
  28. #:snapshoter 5 #:updater 6)))
  29. (and (repo? obj)
  30. (list (repo-id obj)
  31. (repo-url obj)
  32. (repo-location obj)
  33. (repo-reference obj)
  34. (repo-snapshoter obj)
  35. (repo-updater obj)))))
  36. (define file-name
  37. (pk (simple-format #f "tmp-~S" (getpid))))
  38. (define store
  39. (open-connection))
  40. (define (create-file name)
  41. "Create a dummy file in current directory."
  42. (with-output-to-file name
  43. (λ () (display "test!\n"))))
  44. (define (in-store? file-name)
  45. "Check if FILE-NAME is in the store. FILE-NAME must be an absolute file
  46. name."
  47. (string-prefix? "/gnu/store" file-name))
  48. ;;;
  49. ;;; File repository.
  50. ;;;
  51. (test-group-with-cleanup "file-repo"
  52. (define rpt (pk (file-repo file-name)))
  53. ;; Since file doesn't exist yet, 'repo-update' should throw an error.
  54. (test-error "file-repo-update: file not found"
  55. 'system-error
  56. (repo-update rpt))
  57. (create-file file-name)
  58. (test-assert "file-repo-update"
  59. (repo-update rpt))
  60. (test-assert "file-repo-snapshot"
  61. (in-store? (repo-snapshot rpt store)))
  62. ;; Cleanup.
  63. (delete-file file-name))
  64. ;;;
  65. ;;; Git repository.
  66. ;;;
  67. (define (create-git-repository name)
  68. (let ((git "git"))
  69. (system* git "init" name)
  70. (with-directory-excursion name
  71. (create-file "foo")
  72. (system* git "add" "foo")
  73. (system* git "commit" "-m" "'foo'"))))
  74. (test-group-with-cleanup "git-repo"
  75. (define rpt (git-repo #:url file-name
  76. #:dir "git-example"))
  77. ;; Since repository doesn't exist yet, 'repo-update' should throw an error.
  78. (test-error "git-repo-update: file not found"
  79. 'system-error
  80. (repo-update rpt "master"))
  81. (create-git-repository file-name)
  82. (test-assert "git-repo-update"
  83. (repo-update rpt "master"))
  84. (test-assert "git-repo-snapshot"
  85. (in-store? (repo-snapshot rpt store)))
  86. ;; Cleanup.
  87. (system* "rm" "-rf" file-name "git-example"))
  88. (close-connection store)
  89. (test-end)