1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be>
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-import-github)
21 #:use-module (srfi srfi-35)
22 #:use-module (srfi srfi-64)
23 #:use-module (guix git-download)
24 #:use-module (guix http-client)
25 #:use-module (guix import github)
26 #:use-module (guix packages)
27 #:use-module (guix tests)
28 #:use-module (guix upstream)
29 #:use-module (ice-9 match))
33 (define (call-with-releases thunk tags releases)
34 (mock ((guix http-client) http-fetch
35 (lambda* (uri #:key headers)
36 (unless (string-prefix? "mock://" uri)
37 (error "the URI ~a should not be used" uri))
39 (string-split (substring uri 8) #\/))
40 (pk 'stuff components headers)
41 (define (scm->json-port scm)
42 (open-input-string (scm->json-string scm)))
44 (("repos" "foo" "foomatics" "releases")
45 (scm->json-port releases))
46 (("repos" "foo" "foomatics" "tags")
47 (scm->json-port tags))
48 (rest (error "TODO ~a" rest)))))
49 (parameterize ((%github-api "mock://"))
52 ;; Copied from tests/minetest.scm
53 (define (upstream-source->sexp upstream-source)
54 (define url (upstream-source-urls upstream-source))
55 (unless (git-reference? url)
56 (error "a <git-reference> is expected"))
57 `(,(upstream-source-package upstream-source)
58 ,(upstream-source-version upstream-source)
59 ,(git-reference-url url)
60 ,(git-reference-commit url)))
62 (define* (expected-sexp new-version new-commit)
63 `("foomatics" ,new-version "https://github.com/foo/foomatics" ,new-commit))
65 (define (example-package old-version old-commit)
73 (url "https://github.com/foo/foomatics")
75 (sha256 #f) ; not important for following tests
76 (file-name (git-file-name name version))))
83 (define* (found-sexp old-version old-commit tags releases)
85 (call-with-releases (lambda ()
86 ((upstream-updater-latest %github-updater)
87 (example-package old-version old-commit)))
89 upstream-source->sexp))
91 (define-syntax-rule (test-release test-case old-version
92 old-commit new-version new-commit
95 (expected-sexp new-version new-commit)
96 (found-sexp old-version old-commit tags releases)))
98 (test-release "newest release is choosen"
99 "1.0.0" "v1.0.0" "1.9" "v1.9"
101 ;; a mixture of current, older and newer versions
102 #((("tag_name" . "v0.0"))
103 (("tag_name" . "v1.0.1"))
104 (("tag_name" . "v1.9"))
105 (("tag_name" . "v1.0.0"))
106 (("tag_name" . "v1.0.2"))))
108 (test-release "tags are used when there are no formal releases"
109 "1.0.0" "v1.0.0" "1.9" "v1.9"
110 ;; a mixture of current, older and newer versions
111 #((("name" . "v0.0"))
112 (("name" . "v1.0.1"))
114 (("name" . "v1.0.0"))
115 (("name" . "v1.0.2")))
118 (test-release "\"version-\" prefixes are recognised"
119 "1.0.0" "v1.0.0" "1.9" "version-1.9"
120 #((("name" . "version-1.9")))
123 (test-release "prefixes are optional"
124 "1.0.0" "v1.0.0" "1.9" "1.9"
125 #((("name" . "1.9")))
128 (test-release "prefixing by package name is acceptable"
129 "1.0.0" "v1.0.0" "1.9" "foomatics-1.9"
130 #((("name" . "foomatics-1.9")))
133 (test-release "not all prefixes are acceptable"
134 "1.0.0" "v1.0.0" "1.0.0" "v1.0.0"
135 #((("name" . "v1.0.0"))
136 (("name" . "barstatics-1.9")))