1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (test-swh)
20 #:use-module (guix swh)
21 #:use-module (guix tests http)
22 #:use-module (srfi srfi-64))
24 ;; Test the JSON mapping machinery used in (guix swh).
28 \"visits_url\": \"/visits/42\",
30 \"url\": \"http://example.org/guix.git\" }")
32 (define %directory-entries
33 "[ { \"name\": \"one\",
34 \"type\": \"regular\",
38 \"type\": \"regular\",
42 (define-syntax-rule (with-json-result str exp ...)
43 (with-http-server 200 str
44 (parameterize ((%swh-base-url (%local-url)))
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)
55 (origin-url origin)))))
57 (test-equal "lookup-origin, not found"
59 (with-http-server 404 "Nope."
60 (parameterize ((%swh-base-url (%local-url)))
61 (lookup-origin "http://example.org/whatever"))))
63 (test-equal "lookup-directory"
64 '(("one" 123) ("two" 456))
65 (with-json-result %directory-entries
67 (list (directory-entry-name entry)
68 (directory-entry-length entry)))
69 (lookup-directory "123"))))
74 ;; eval: (put 'with-json-result 'scheme-indent-function 1)