summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-07-20 20:13:39 +0200
committerLudovic Courtès <ludo@gnu.org>2019-07-22 11:53:39 +0200
commit96f1cbeff84819f9886d15763b4c477cdecd7784 (patch)
treeeffda7227bcda05d87cd317a29301b55c3328858
parent5a90d5635226255e65b19a094a4851ff3886c0c5 (diff)
swh: Add basic tests.
* guix/swh.scm (%swh-base-url): Turn into a parameter and export it. * tests/swh.scm: New file. * Makefile.am (SCM_TESTS): Add it.
-rw-r--r--Makefile.am1
-rw-r--r--guix/swh.scm10
-rw-r--r--tests/swh.scm76
3 files changed, 83 insertions, 4 deletions
diff --git a/Makefile.am b/Makefile.am
index b63c55d784d..e36f2d9f210 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -375,6 +375,7 @@ SCM_TESTS = \
375 tests/modules.scm \ 375 tests/modules.scm \
376 tests/gnu-maintenance.scm \ 376 tests/gnu-maintenance.scm \
377 tests/substitute.scm \ 377 tests/substitute.scm \
378 tests/swh.scm \
378 tests/builders.scm \ 379 tests/builders.scm \
379 tests/derivations.scm \ 380 tests/derivations.scm \
380 tests/glob.scm \ 381 tests/glob.scm \
diff --git a/guix/swh.scm b/guix/swh.scm
index 89cddb2bddd..d692f81806b 100644
--- a/guix/swh.scm
+++ b/guix/swh.scm
@@ -1,5 +1,5 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org> 2;;; Copyright © 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3;;; 3;;;
4;;; This file is part of GNU Guix. 4;;; This file is part of GNU Guix.
5;;; 5;;;
@@ -31,7 +31,9 @@
31 #:use-module (ice-9 regex) 31 #:use-module (ice-9 regex)
32 #:use-module (ice-9 popen) 32 #:use-module (ice-9 popen)
33 #:use-module ((ice-9 ftw) #:select (scandir)) 33 #:use-module ((ice-9 ftw) #:select (scandir))
34 #:export (origin? 34 #:export (%swh-base-url
35
36 origin?
35 origin-id 37 origin-id
36 origin-type 38 origin-type
37 origin-url 39 origin-url
@@ -115,11 +117,11 @@
115 117
116(define %swh-base-url 118(define %swh-base-url
117 ;; Presumably we won't need to change it. 119 ;; Presumably we won't need to change it.
118 "https://archive.softwareheritage.org") 120 (make-parameter "https://archive.softwareheritage.org"))
119 121
120(define (swh-url path . rest) 122(define (swh-url path . rest)
121 (define url 123 (define url
122 (string-append %swh-base-url path 124 (string-append (%swh-base-url) path
123 (string-join rest "/" 'prefix))) 125 (string-join rest "/" 'prefix)))
124 126
125 ;; Ensure there's a trailing slash or we get a redirect. 127 ;; Ensure there's a trailing slash or we get a redirect.
diff --git a/tests/swh.scm b/tests/swh.scm
new file mode 100644
index 00000000000..07f0fda37bb
--- /dev/null
+++ b/tests/swh.scm
@@ -0,0 +1,76 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2019 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
19(define-module (test-swh)
20 #:use-module (guix swh)
21 #:use-module (guix tests http)
22 #:use-module (srfi srfi-64))
23
24;; Test the JSON mapping machinery used in (guix swh).
25
26(define %origin
27 "{ \"id\": 42,
28 \"visits_url\": \"/visits/42\",
29 \"type\": \"git\",
30 \"url\": \"http://example.org/guix.git\" }")
31
32(define %directory-entries
33 "[ { \"name\": \"one\",
34 \"type\": \"regular\",
35 \"length\": 123,
36 \"dir_id\": 1 }
37 { \"name\": \"two\",
38 \"type\": \"regular\",
39 \"length\": 456,
40 \"dir_id\": 2 } ]")
41
42(define-syntax-rule (with-json-result str exp ...)
43 (with-http-server 200 str
44 (parameterize ((%swh-base-url (%local-url)))
45 exp ...)))
46
47(test-begin "swh")
48
49(test-equal "lookup-origin"
50 (list 42 "git" "http://example.org/guix.git")
51 (with-json-result %origin
52 (let ((origin (lookup-origin "http://example.org/guix.git")))
53 (list (origin-id origin)
54 (origin-type origin)
55 (origin-url origin)))))
56
57(test-equal "lookup-origin, not found"
58 #f
59 (with-http-server 404 "Nope."
60 (parameterize ((%swh-base-url (%local-url)))
61 (lookup-origin "http://example.org/whatever"))))
62
63(test-equal "lookup-directory"
64 '(("one" 123) ("two" 456))
65 (with-json-result %directory-entries
66 (map (lambda (entry)
67 (list (directory-entry-name entry)
68 (directory-entry-length entry)))
69 (lookup-directory "123"))))
70
71(test-end "swh")
72
73;; Local Variables:
74;; eval: (put 'with-json-result 'scheme-indent-function 1)
75;; End:
76