1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2022 Hartmut Goebel <h.goebel@crazy-compilers.com>
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-hexpm)
20 #:use-module (guix import hexpm)
21 #:use-module (guix base32)
22 #:use-module (gcrypt hash)
23 #:use-module (guix tests)
24 #:use-module (srfi srfi-64)
25 #:use-module (ice-9 binary-ports)
26 #:use-module (ice-9 match))
28 (define test-bla-package
30 \"html_url\": \"https://hex.pm/packages/bla\",
31 \"docs_html_url\": null,
33 \"description\": \"A cool package\",
34 \"licenses\": [\"MIT\", \"Apache-2.0\"]
37 {\"url\": \"https://hex.pm/api/packages/bla/releases/1.5.0\",
38 \"version\": \"1.5.0\"},
39 {\"url\": \"https://hex.pm/api/packages/bla/releases/1.4.7\",
40 \"version\": \"1.4.7\"}
44 (define test-bla-release
46 \"version\": \"1.5.0\",
47 \"url\": \"https://hex.pm/api/packages/bla/releases/1.5.0\",
49 \"blubb\":{\"app\": \"blubb\",
51 \"requirement\": \"~>0.3\"
53 \"fasel\":{\"app\": \"fasel\",
55 \"requirement\": \"~>1.0\"
58 \"meta\":{ \"build_tools\":[\"mix\", \"make\", \"rebar3\"] }
61 (define test-blubb-package
62 "{\"name\": \"blubb\",
63 \"latest_stable_version\": \"0.3.1\",
64 \"latest_version\": \"0.3.1\",
65 \"html_url\": \"https://hex.pm/packages/blubb\",
66 \"docs_html_url\": null,
68 \"description\": \"Another cool package\",
69 \"licenses\": [\"MIT\"]
72 {\"url\": \"https://hex.pm/api/packages/blubb/releases/0.3.1\",
73 \"version\": \"0.3.1\"},
74 {\"url\": \"https://hex.pm/api/packages/blubb/releases/0.3.0\",
75 \"version\": \"0.3.0\"}
79 (define test-blubb-release
81 \"version\": \"0.3.1\",
82 \"url\": \"https://hex.pm/api/packages/blubb/releases/0.3.1\",
84 \"fasel\":{\"app\": \"fasel\",
86 \"requirement\": \"~>1.0\"
89 \"meta\": { \"build_tools\":[\"mix\"] }
92 (define test-fasel-package
93 "{\"name\": \"fasel\",
94 \"latest_stable_version\": \"1.2.1\",
95 \"latest_version\": \"1.2.1\",
96 \"html_url\": \"https://hex.pm/packages/fasel\",
97 \"docs_html_url\": null,
99 \"description\": \"Yet another cool package\",
100 \"licenses\": [\"GPL\"]
103 {\"url\": \"https://hex.pm/api/packages/fasel/releases/1.2.1\",
104 \"version\": \"1.2.1\"}
108 (define test-fasel-release
110 \"version\": \"1.2.1\",
111 \"url\": \"https://hex.pm/api/packages/fasel/releases/1.2.1\",
112 \"requirements\" :{},
113 \"meta\":{ \"build_tools\":[\"make\"] }
118 (test-assert "hexpm->guix-package"
119 ;; Replace network resources with sample data.
120 (mock ((guix http-client) http-fetch
123 ("https://hex.pm/api/packages/bla"
124 (values (open-input-string test-bla-package)
125 (string-length test-bla-package)))
126 ("https://hex.pm/api/packages/bla/releases/1.5.0"
127 (values (open-input-string test-bla-release)
128 (string-length test-bla-release)))
129 (_ (error "http-fetch got unexpected URL: " url)))))
130 (mock ((guix build download) url-fetch
131 (lambda* (url file-name
133 (mirrors '()) verify-certificate?)
134 (with-output-to-file file-name
138 ("https://repo.hex.pm/tarballs/bla-1.5.0.tar"
140 (_ (error "url-fetch got unexpected URL: " url))))))))
141 (match (hexpm->guix-package "bla")
148 ('uri ('hexpm-uri "bla" 'version))
151 "0zcl4dgcmqwl1g5xb901pd6dz61r1xgmac9mqlwvh022paa6gks1"))))
152 ('build-system 'rebar-build-system)
153 ('inputs ('list 'erlang-blubb 'erlang-fasel))
154 ('synopsis "A cool package")
155 ('description "This package provides a cool package")
156 ('home-page "https://hex.pm/packages/bla")
157 ('license ('list 'license:expat 'license:asl2.0)))
162 (test-assert "hexpm-recursive-import"
163 ;; Replace network resources with sample data.
164 (mock ((guix http-client) http-fetch
167 ("https://hex.pm/api/packages/bla"
168 (values (open-input-string test-bla-package)
169 (string-length test-bla-package)))
170 ("https://hex.pm/api/packages/bla/releases/1.5.0"
171 (values (open-input-string test-bla-release)
172 (string-length test-bla-release)))
173 ("https://hex.pm/api/packages/blubb"
174 (values (open-input-string test-blubb-package)
175 (string-length test-blubb-package)))
176 ("https://hex.pm/api/packages/blubb/releases/0.3.1"
177 (values (open-input-string test-blubb-release)
178 (string-length test-blubb-release)))
179 ("https://hex.pm/api/packages/fasel"
180 (values (open-input-string test-fasel-package)
181 (string-length test-fasel-package)))
182 ("https://hex.pm/api/packages/fasel/releases/1.2.1"
183 (values (open-input-string test-fasel-release)
184 (string-length test-fasel-release)))
185 (_ (error "http-fetch got unexpected URL: " url)))))
186 (mock ((guix build download) url-fetch
187 (lambda* (url file-name
189 (mirrors '()) verify-certificate?)
190 (with-output-to-file file-name
194 ("https://repo.hex.pm/tarballs/bla-1.5.0.tar"
196 ("https://repo.hex.pm/tarballs/blubb-0.3.1.tar"
198 ("https://repo.hex.pm/tarballs/fasel-1.2.1.tar"
200 (_ (error "url-fetch got unexpected URL: " url))))))))
201 (match (hexpm-recursive-import "bla")
203 ('name "erlang-blubb")
208 ('uri ('hexpm-uri "blubb" 'version))
211 "17y88b5y8ld7s1c2bcwwwa04pf1cl4402i9zk3inna221ps3ppj2"))))
212 ('build-system 'mix-build-system)
213 ('inputs ('list 'erlang-fasel))
214 ('synopsis "Another cool package")
215 ('description "Another cool package")
216 ('home-page "https://hex.pm/packages/blubb")
217 ('license 'license:expat))
219 ('name "erlang-fasel")
224 ('uri ('hexpm-uri "fasel" 'version))
227 "1k6d70mxwqgq78jrbr7yqnw187yki74jnagybi7nacrj4a67qjha"))))
228 ('build-system 'gnu-build-system)
229 ('synopsis "Yet another cool package")
230 ('description "Yet another cool package")
231 ('home-page "https://hex.pm/packages/fasel")
239 ('uri ('hexpm-uri "bla" 'version))
242 "0d3gj746c4swbb1m6ycylxb239jsavvdcizag6bfbg2aqccxwij8"))))
243 ('build-system 'rebar-build-system)
244 ('inputs ('list 'erlang-blubb 'erlang-fasel))
245 ('synopsis "A cool package")
246 ('description "This package provides a cool package")
247 ('home-page "https://hex.pm/packages/bla")
248 ('license ('list 'license:expat 'license:asl2.0))))