hexpm.scm 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. (define-module (test-hexpm)
  19. #:use-module (guix import hexpm)
  20. #:use-module (guix base32)
  21. #:use-module (gcrypt hash)
  22. #:use-module (guix tests)
  23. #:use-module (srfi srfi-64)
  24. #:use-module (ice-9 binary-ports)
  25. #:use-module (ice-9 match))
  26. (define test-bla-package
  27. "{\"name\": \"bla\",
  28. \"html_url\": \"https://hex.pm/packages/bla\",
  29. \"docs_html_url\": null,
  30. \"meta\": {
  31. \"description\": \"A cool package\",
  32. \"licenses\": [\"MIT\", \"Apache-2.0\"]
  33. },
  34. \"releases\": [
  35. {\"url\": \"https://hex.pm/api/packages/bla/releases/1.5.0\",
  36. \"version\": \"1.5.0\"},
  37. {\"url\": \"https://hex.pm/api/packages/bla/releases/1.4.7\",
  38. \"version\": \"1.4.7\"}
  39. ]
  40. }")
  41. (define test-bla-release
  42. "{
  43. \"version\": \"1.5.0\",
  44. \"url\": \"https://hex.pm/api/packages/bla/releases/1.5.0\",
  45. \"requirements\": {
  46. \"blubb\":{\"app\": \"blubb\",
  47. \"optional\": false,
  48. \"requirement\": \"~>0.3\"
  49. },
  50. \"fasel\":{\"app\": \"fasel\",
  51. \"optional\": false,
  52. \"requirement\": \"~>1.0\"
  53. }
  54. },
  55. \"meta\":{ \"build_tools\":[\"mix\", \"make\", \"rebar3\"] }
  56. }")
  57. (define test-blubb-package
  58. "{\"name\": \"blubb\",
  59. \"latest_stable_version\": \"0.3.1\",
  60. \"latest_version\": \"0.3.1\",
  61. \"html_url\": \"https://hex.pm/packages/blubb\",
  62. \"docs_html_url\": null,
  63. \"meta\": {
  64. \"description\": \"Another cool package\",
  65. \"licenses\": [\"MIT\"]
  66. },
  67. \"releases\": [
  68. {\"url\": \"https://hex.pm/api/packages/blubb/releases/0.3.1\",
  69. \"version\": \"0.3.1\"},
  70. {\"url\": \"https://hex.pm/api/packages/blubb/releases/0.3.0\",
  71. \"version\": \"0.3.0\"}
  72. ]
  73. }")
  74. (define test-blubb-release
  75. "{
  76. \"version\": \"0.3.1\",
  77. \"url\": \"https://hex.pm/api/packages/blubb/releases/0.3.1\",
  78. \"requirements\": {
  79. \"fasel\":{\"app\": \"fasel\",
  80. \"optional\": false,
  81. \"requirement\": \"~>1.0\"
  82. }
  83. },
  84. \"meta\": { \"build_tools\":[\"mix\"] }
  85. }")
  86. (define test-fasel-package
  87. "{\"name\": \"fasel\",
  88. \"latest_stable_version\": \"1.2.1\",
  89. \"latest_version\": \"1.2.1\",
  90. \"html_url\": \"https://hex.pm/packages/fasel\",
  91. \"docs_html_url\": null,
  92. \"meta\": {
  93. \"description\": \"Yet another cool package\",
  94. \"licenses\": [\"GPL\"]
  95. },
  96. \"releases\": [
  97. {\"url\": \"https://hex.pm/api/packages/fasel/releases/1.2.1\",
  98. \"version\": \"1.2.1\"}
  99. ]
  100. }")
  101. (define test-fasel-release
  102. "{
  103. \"version\": \"1.2.1\",
  104. \"url\": \"https://hex.pm/api/packages/fasel/releases/1.2.1\",
  105. \"requirements\" :{},
  106. \"meta\":{ \"build_tools\":[\"make\"] }
  107. }")
  108. (test-begin "hexpm")
  109. (test-assert "hexpm->guix-package"
  110. ;; Replace network resources with sample data.
  111. (mock ((guix http-client) http-fetch
  112. (lambda (url . rest)
  113. (match url
  114. ("https://hex.pm/api/packages/bla"
  115. (values (open-input-string test-bla-package)
  116. (string-length test-bla-package)))
  117. ("https://hex.pm/api/packages/bla/releases/1.5.0"
  118. (values (open-input-string test-bla-release)
  119. (string-length test-bla-release)))
  120. (_ (error "http-fetch got unexpected URL: " url)))))
  121. (mock ((guix build download) url-fetch
  122. (lambda* (url file-name
  123. #:key
  124. (mirrors '()) verify-certificate?)
  125. (with-output-to-file file-name
  126. (lambda ()
  127. (display
  128. (match url
  129. ("https://repo.hex.pm/tarballs/bla-1.5.0.tar"
  130. "source")
  131. (_ (error "url-fetch got unexpected URL: " url))))))))
  132. (match (hexpm->guix-package "bla")
  133. (`(package
  134. (name "erlang-bla")
  135. (version "1.5.0")
  136. (source
  137. (origin
  138. (method url-fetch)
  139. (uri (hexpm-uri "bla" version))
  140. (sha256
  141. (base32
  142. "0zcl4dgcmqwl1g5xb901pd6dz61r1xgmac9mqlwvh022paa6gks1"))))
  143. (build-system rebar-build-system)
  144. (inputs (list erlang-blubb erlang-fasel))
  145. (synopsis "A cool package")
  146. (description "This package provides a cool package")
  147. (home-page "https://hex.pm/packages/bla")
  148. (license (list license:expat license:asl2.0)))
  149. #t)
  150. (x
  151. (pk 'fail x #f))))))
  152. (test-assert "hexpm-recursive-import"
  153. ;; Replace network resources with sample data.
  154. (mock ((guix http-client) http-fetch
  155. (lambda (url . rest)
  156. (match url
  157. ("https://hex.pm/api/packages/bla"
  158. (values (open-input-string test-bla-package)
  159. (string-length test-bla-package)))
  160. ("https://hex.pm/api/packages/bla/releases/1.5.0"
  161. (values (open-input-string test-bla-release)
  162. (string-length test-bla-release)))
  163. ("https://hex.pm/api/packages/blubb"
  164. (values (open-input-string test-blubb-package)
  165. (string-length test-blubb-package)))
  166. ("https://hex.pm/api/packages/blubb/releases/0.3.1"
  167. (values (open-input-string test-blubb-release)
  168. (string-length test-blubb-release)))
  169. ("https://hex.pm/api/packages/fasel"
  170. (values (open-input-string test-fasel-package)
  171. (string-length test-fasel-package)))
  172. ("https://hex.pm/api/packages/fasel/releases/1.2.1"
  173. (values (open-input-string test-fasel-release)
  174. (string-length test-fasel-release)))
  175. (_ (error "http-fetch got unexpected URL: " url)))))
  176. (mock ((guix build download) url-fetch
  177. (lambda* (url file-name
  178. #:key
  179. (mirrors '()) verify-certificate?)
  180. (with-output-to-file file-name
  181. (lambda ()
  182. (display
  183. (match url
  184. ("https://repo.hex.pm/tarballs/bla-1.5.0.tar"
  185. "bla-source")
  186. ("https://repo.hex.pm/tarballs/blubb-0.3.1.tar"
  187. "blubb-source")
  188. ("https://repo.hex.pm/tarballs/fasel-1.2.1.tar"
  189. "fasel-source")
  190. (_ (error "url-fetch got unexpected URL: " url))))))))
  191. (match (hexpm-recursive-import "bla")
  192. (`((package
  193. (name "erlang-blubb")
  194. (version "0.3.1")
  195. (source
  196. (origin
  197. (method url-fetch)
  198. (uri (hexpm-uri "blubb" version))
  199. (sha256
  200. (base32
  201. "17y88b5y8ld7s1c2bcwwwa04pf1cl4402i9zk3inna221ps3ppj2"))))
  202. (build-system mix-build-system)
  203. (inputs (list erlang-fasel))
  204. (synopsis "Another cool package")
  205. (description "Another cool package")
  206. (home-page "https://hex.pm/packages/blubb")
  207. (license license:expat))
  208. (package
  209. (name "erlang-fasel")
  210. (version "1.2.1")
  211. (source
  212. (origin
  213. (method url-fetch)
  214. (uri (hexpm-uri "fasel" version))
  215. (sha256
  216. (base32
  217. "1k6d70mxwqgq78jrbr7yqnw187yki74jnagybi7nacrj4a67qjha"))))
  218. (build-system gnu-build-system)
  219. (synopsis "Yet another cool package")
  220. (description "Yet another cool package")
  221. (home-page "https://hex.pm/packages/fasel")
  222. (license "GPL"))
  223. (package
  224. (name "erlang-bla")
  225. (version "1.5.0")
  226. (source
  227. (origin
  228. (method url-fetch)
  229. (uri (hexpm-uri "bla" version))
  230. (sha256
  231. (base32
  232. "0d3gj746c4swbb1m6ycylxb239jsavvdcizag6bfbg2aqccxwij8"))))
  233. (build-system rebar-build-system)
  234. (inputs (list erlang-blubb erlang-fasel))
  235. (synopsis "A cool package")
  236. (description "This package provides a cool package")
  237. (home-page "https://hex.pm/packages/bla")
  238. (license (list license:expat license:asl2.0))))
  239. #t)
  240. (x
  241. (pk 'fail x #f))))))
  242. (test-end "hexpm")