gtk and wayland update
[jackhill/guix/guix.git] / tests / hexpm.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2022 Hartmut Goebel <h.goebel@crazy-compilers.com>
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-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))
27
28 (define test-bla-package
29 "{\"name\": \"bla\",
30 \"html_url\": \"https://hex.pm/packages/bla\",
31 \"docs_html_url\": null,
32 \"meta\": {
33 \"description\": \"A cool package\",
34 \"licenses\": [\"MIT\", \"Apache-2.0\"]
35 },
36 \"releases\": [
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\"}
41 ]
42 }")
43
44 (define test-bla-release
45 "{
46 \"version\": \"1.5.0\",
47 \"url\": \"https://hex.pm/api/packages/bla/releases/1.5.0\",
48 \"requirements\": {
49 \"blubb\":{\"app\": \"blubb\",
50 \"optional\": false,
51 \"requirement\": \"~>0.3\"
52 },
53 \"fasel\":{\"app\": \"fasel\",
54 \"optional\": false,
55 \"requirement\": \"~>1.0\"
56 }
57 },
58 \"meta\":{ \"build_tools\":[\"mix\", \"make\", \"rebar3\"] }
59 }")
60
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,
67 \"meta\": {
68 \"description\": \"Another cool package\",
69 \"licenses\": [\"MIT\"]
70 },
71 \"releases\": [
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\"}
76 ]
77 }")
78
79 (define test-blubb-release
80 "{
81 \"version\": \"0.3.1\",
82 \"url\": \"https://hex.pm/api/packages/blubb/releases/0.3.1\",
83 \"requirements\": {
84 \"fasel\":{\"app\": \"fasel\",
85 \"optional\": false,
86 \"requirement\": \"~>1.0\"
87 }
88 },
89 \"meta\": { \"build_tools\":[\"mix\"] }
90 }")
91
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,
98 \"meta\": {
99 \"description\": \"Yet another cool package\",
100 \"licenses\": [\"GPL\"]
101 },
102 \"releases\": [
103 {\"url\": \"https://hex.pm/api/packages/fasel/releases/1.2.1\",
104 \"version\": \"1.2.1\"}
105 ]
106 }")
107
108 (define test-fasel-release
109 "{
110 \"version\": \"1.2.1\",
111 \"url\": \"https://hex.pm/api/packages/fasel/releases/1.2.1\",
112 \"requirements\" :{},
113 \"meta\":{ \"build_tools\":[\"make\"] }
114 }")
115
116 (test-begin "hexpm")
117
118 (test-assert "hexpm->guix-package"
119 ;; Replace network resources with sample data.
120 (mock ((guix http-client) http-fetch
121 (lambda (url . rest)
122 (match url
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
132 #:key
133 (mirrors '()) verify-certificate?)
134 (with-output-to-file file-name
135 (lambda ()
136 (display
137 (match url
138 ("https://repo.hex.pm/tarballs/bla-1.5.0.tar"
139 "source")
140 (_ (error "url-fetch got unexpected URL: " url))))))))
141 (match (hexpm->guix-package "bla")
142 (('package
143 ('name "erlang-bla")
144 ('version "1.5.0")
145 ('source
146 ('origin
147 ('method 'url-fetch)
148 ('uri ('hexpm-uri "bla" 'version))
149 ('sha256
150 ('base32
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)))
158 #t)
159 (x
160 (pk 'fail x #f))))))
161
162 (test-assert "hexpm-recursive-import"
163 ;; Replace network resources with sample data.
164 (mock ((guix http-client) http-fetch
165 (lambda (url . rest)
166 (match url
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
188 #:key
189 (mirrors '()) verify-certificate?)
190 (with-output-to-file file-name
191 (lambda ()
192 (display
193 (match url
194 ("https://repo.hex.pm/tarballs/bla-1.5.0.tar"
195 "bla-source")
196 ("https://repo.hex.pm/tarballs/blubb-0.3.1.tar"
197 "blubb-source")
198 ("https://repo.hex.pm/tarballs/fasel-1.2.1.tar"
199 "fasel-source")
200 (_ (error "url-fetch got unexpected URL: " url))))))))
201 (match (hexpm-recursive-import "bla")
202 ((('package
203 ('name "erlang-blubb")
204 ('version "0.3.1")
205 ('source
206 ('origin
207 ('method 'url-fetch)
208 ('uri ('hexpm-uri "blubb" 'version))
209 ('sha256
210 ('base32
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))
218 ('package
219 ('name "erlang-fasel")
220 ('version "1.2.1")
221 ('source
222 ('origin
223 ('method 'url-fetch)
224 ('uri ('hexpm-uri "fasel" 'version))
225 ('sha256
226 ('base32
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")
232 ('license "GPL"))
233 ('package
234 ('name "erlang-bla")
235 ('version "1.5.0")
236 ('source
237 ('origin
238 ('method 'url-fetch)
239 ('uri ('hexpm-uri "bla" 'version))
240 ('sha256
241 ('base32
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))))
249 #t)
250 (x
251 (pk 'fail x #f))))))
252
253 (test-end "hexpm")