import-github.scm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be>
  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-import-github)
  19. #:use-module (json)
  20. #:use-module (srfi srfi-35)
  21. #:use-module (srfi srfi-64)
  22. #:use-module (guix git-download)
  23. #:use-module (guix http-client)
  24. #:use-module (guix import github)
  25. #:use-module (guix packages)
  26. #:use-module (guix tests http)
  27. #:use-module (guix upstream)
  28. #:use-module (web client)
  29. #:use-module (web request)
  30. #:use-module (web uri)
  31. #:use-module (ice-9 match))
  32. (test-begin "github")
  33. (define (call-with-releases thunk tags releases)
  34. (with-http-server*
  35. (lambda (request _)
  36. (define resource (uri-path (request-uri request)))
  37. (define components (string-split resource #\/))
  38. (define json (match components
  39. (("" "repos" "foo" "foomatics" "releases") releases)
  40. (("" "repos" "foo" "foomatics" "tags") tags)
  41. (rest (error "TODO ~a" rest))))
  42. (values '() (lambda (port) (scm->json json port))))
  43. (parameterize ((%github-api (%local-url "")))
  44. (thunk))))
  45. ;; Copied from tests/minetest.scm
  46. (define (upstream-source->sexp upstream-source)
  47. (define url (upstream-source-urls upstream-source))
  48. (unless (git-reference? url)
  49. (error "a <git-reference> is expected"))
  50. `(,(upstream-source-package upstream-source)
  51. ,(upstream-source-version upstream-source)
  52. ,(git-reference-url url)
  53. ,(git-reference-commit url)))
  54. (define* (expected-sexp new-version new-commit)
  55. `("foomatics" ,new-version "https://github.com/foo/foomatics" ,new-commit))
  56. (define (example-package old-version old-commit)
  57. (package
  58. (name "foomatics")
  59. (version old-version)
  60. (source
  61. (origin
  62. (method git-fetch)
  63. (uri (git-reference
  64. (url "https://github.com/foo/foomatics")
  65. (commit old-commit)))
  66. (sha256 #f) ; not important for following tests
  67. (file-name (git-file-name name version))))
  68. (build-system #f)
  69. (license #f)
  70. (synopsis #f)
  71. (description #f)
  72. (home-page #f)))
  73. (define* (found-sexp old-version old-commit tags releases)
  74. (and=>
  75. (call-with-releases (lambda ()
  76. ((upstream-updater-latest %github-updater)
  77. (example-package old-version old-commit)))
  78. tags releases)
  79. upstream-source->sexp))
  80. (define-syntax-rule (test-release test-case old-version
  81. old-commit new-version new-commit
  82. tags releases)
  83. (test-equal test-case
  84. (expected-sexp new-version new-commit)
  85. (found-sexp old-version old-commit tags releases)))
  86. (test-release "newest release is choosen"
  87. "1.0.0" "v1.0.0" "1.9" "v1.9"
  88. #()
  89. ;; a mixture of current, older and newer versions
  90. #((("tag_name" . "v0.0"))
  91. (("tag_name" . "v1.0.1"))
  92. (("tag_name" . "v1.9"))
  93. (("tag_name" . "v1.0.0"))
  94. (("tag_name" . "v1.0.2"))))
  95. (test-release "tags are used when there are no formal releases"
  96. "1.0.0" "v1.0.0" "1.9" "v1.9"
  97. ;; a mixture of current, older and newer versions
  98. #((("name" . "v0.0"))
  99. (("name" . "v1.0.1"))
  100. (("name" . "v1.9"))
  101. (("name" . "v1.0.0"))
  102. (("name" . "v1.0.2")))
  103. #())
  104. (test-release "\"version-\" prefixes are recognised"
  105. "1.0.0" "v1.0.0" "1.9" "version-1.9"
  106. #((("name" . "version-1.9")))
  107. #())
  108. (test-release "prefixes are optional"
  109. "1.0.0" "v1.0.0" "1.9" "1.9"
  110. #((("name" . "1.9")))
  111. #())
  112. (test-release "prefixing by package name is acceptable"
  113. "1.0.0" "v1.0.0" "1.9" "foomatics-1.9"
  114. #((("name" . "foomatics-1.9")))
  115. #())
  116. (test-release "not all prefixes are acceptable"
  117. "1.0.0" "v1.0.0" "1.0.0" "v1.0.0"
  118. #((("name" . "v1.0.0"))
  119. (("name" . "barstatics-1.9")))
  120. #())
  121. (test-end "github")