summaryrefslogtreecommitdiff
path: root/tests/repo.scm
blob: fc73a64066c59c9e93a2205bc08af91d5682365b (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
101
102
103
104
105
106
107
108
109
110
111
112
113
;;;; repo.scm -- tests for (cuirass repo) module
;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
;;;
;;; This file is part of Cuirass.
;;;
;;; Cuirass 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.
;;;
;;; Cuirass 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 Cuirass.  If not, see <http://www.gnu.org/licenses/>.

(use-modules (cuirass repo)
             (cuirass utils)
             (guix store)
             (srfi srfi-64))

(test-begin "repo")

(test-equal "<repo> datatype"
  ;; Check that all the procedures for manipulating <repo> objects are
  ;; exported and that the keywords of the constructor matches their slot.
  '(1 2 3 4 5 6)
  (let ((obj (repo #:id 1 #:url 2 #:location 3 #:ref 4
                   #:snapshoter 5 #:updater 6)))
    (and (repo? obj)
         (list (repo-id obj)
               (repo-url obj)
               (repo-location obj)
               (repo-reference obj)
               (repo-snapshoter obj)
               (repo-updater obj)))))

(define file-name
  (pk (simple-format #f "tmp-~S" (getpid))))

(define store
  (open-connection))

(define (create-file name)
  "Create a dummy file in current directory."
  (with-output-to-file name
    (λ () (display "test!\n"))))

(define (in-store? file-name)
  "Check if FILE-NAME is in the store.  FILE-NAME must be an absolute file
name."
  (string-prefix? "/gnu/store" file-name))

;;;
;;; File repository.
;;;

(test-group-with-cleanup "file-repo"
  (define rpt (pk (file-repo file-name)))

  ;; Since file doesn't exist yet, 'repo-update' should throw an error.
  (test-error "file-repo-update: file not found"
    'system-error
    (repo-update rpt))

  (create-file file-name)

  (test-assert "file-repo-update"
    (repo-update rpt))

  (test-assert "file-repo-snapshot"
    (in-store? (repo-snapshot rpt store)))

  ;; Cleanup.
  (delete-file file-name))

;;;
;;; Git repository.
;;;

(define (create-git-repository name)
  (let ((git "git"))
    (system* git "init" name)
    (with-directory-excursion name
      (create-file "foo")
      (system* git "add" "foo")
      (system* git "commit" "-m" "'foo'"))))

(test-group-with-cleanup "git-repo"
  (define rpt (git-repo #:url file-name
                        #:dir "git-example"))

  ;; Since repository doesn't exist yet, 'repo-update' should throw an error.
  (test-error "git-repo-update: file not found"
    'system-error
    (repo-update rpt "master"))

  (create-git-repository file-name)

  (test-assert "git-repo-update"
    (repo-update rpt "master"))

  (test-assert "git-repo-snapshot"
    (in-store? (repo-snapshot rpt store)))

  ;; Cleanup.
  (system* "rm" "-rf" file-name "git-example"))

(close-connection store)

(test-end)