Commit | Line | Data |
---|---|---|
96f1cbef LC |
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 |