summaryrefslogtreecommitdiff
path: root/tests/import
diff options
context:
space:
mode:
authorNicolas Graves <ngraves@ngraves.fr>2025-09-17 00:28:37 +0200
committerLudovic Courtès <ludo@gnu.org>2025-10-01 11:00:36 +0200
commitd4fda72d8f991fa2102fe2ef121dbade2d322382 (patch)
tree91b3d19b24db891874d51f58d378234bcbde8f65 /tests/import
parentfbc1da99ea6d557a6a3835b655e37552e479e1c4 (diff)
import: go: Move tests to tests/import/go.scm.
* tests/go.scm: Move to tests/import/go.scm. * Makefile.am: Refresh it. * CODEOWNERS: Refresh it. * etc/teams.scm: Refresh it. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'tests/import')
-rw-r--r--tests/import/go.scm418
1 files changed, 418 insertions, 0 deletions
diff --git a/tests/import/go.scm b/tests/import/go.scm
new file mode 100644
index 00000000000..a72f3068711
--- /dev/null
+++ b/tests/import/go.scm
@@ -0,0 +1,418 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2021 François Joulaud <francois.joulaud@radiofrance.com>
3;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
4;;; Copyright © 2023 Nicolas Graves <ngraves@ngraves.fr>
5;;;
6;;; This file is part of GNU Guix.
7;;;
8;;; GNU Guix is free software; you can redistribute it and/or modify it
9;;; under the terms of the GNU General Public License as published by
10;;; the Free Software Foundation; either version 3 of the License, or (at
11;;; your option) any later version.
12;;;
13;;; GNU Guix is distributed in the hope that it will be useful, but
14;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16;;; GNU General Public License for more details.
17;;;
18;;; You should have received a copy of the GNU General Public License
19;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21;;; Summary
22;; Tests for guix/import/go.scm
23
24(define-module (tests-import-go)
25 #:use-module (guix base32)
26 #:use-module (guix build-system go)
27 #:use-module (guix import go)
28 #:use-module (guix import utils)
29 #:use-module ((guix utils) #:select (call-with-temporary-directory))
30 #:use-module (guix tests)
31 #:use-module (ice-9 match)
32 #:use-module (srfi srfi-19)
33 #:use-module (srfi srfi-64)
34 #:use-module (web response))
35
36(define go.mod-requirements
37 (@@ (guix import go) go.mod-requirements))
38
39(define parse-go.mod
40 (@@ (guix import go) parse-go.mod))
41
42(define fixture-go-mod-simple
43 "module my/thing
44go 1.12
45require other/thing v1.0.2
46require new/thing/v2 v2.3.4
47exclude old/thing v1.2.3
48replace bad/thing v1.4.5 => good/thing v1.4.5
49")
50
51(define fixture-go-mod-with-block
52 "module M
53
54require (
55 A v1
56 B v1.0.0
57 C v1.0.0
58 D v1.2.3
59 E dev
60)
61
62exclude D v1.2.3
63")
64
65(define fixture-go-mod-complete
66 "module M
67
68go 1.13
69
70replace github.com/myname/myproject/myapi => ./api
71
72replace github.com/mymname/myproject/thissdk => ../sdk
73
74replace launchpad.net/gocheck => github.com/go-check/check v0.0.0-20140225173054-eb6ee6f84d0a
75
76require (
77 github.com/user/project v1.1.11
78 github.com/user/project/sub/directory v1.1.12
79 bitbucket.org/user/project v1.11.20
80 bitbucket.org/user/project/sub/directory v1.11.21
81 launchpad.net/project v1.1.13
82 launchpad.net/project/series v1.1.14
83 launchpad.net/project/series/sub/directory v1.1.15
84 launchpad.net/~user/project/branch v1.1.16
85 launchpad.net/~user/project/branch/sub/directory v1.1.17
86 hub.jazz.net/git/user/project v1.1.18
87 hub.jazz.net/git/user/project/sub/directory v1.1.19
88 k8s.io/kubernetes/subproject v1.1.101
89 one.example.com/abitrary/repo v1.1.111
90 two.example.com/abitrary/repo v0.0.2
91 \"quoted.example.com/abitrary/repo\" v0.0.2
92)
93
94replace two.example.com/abitrary/repo => github.com/corp/arbitrary-repo v0.0.2
95
96replace (
97 golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13
98 golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13
99)
100
101")
102
103(define fixture-go-mod-unparsable
104 "module my/thing
105go 1.12 // avoid feature X
106require other/thing v1.0.2
107// Security issue: CVE-XXXXX
108exclude old/thing v1.2.3
109new-directive another/thing yet-another/thing
110replace (
111 bad/thing v1.4.5 => good/thing v1.4.5
112 // Unparseable
113 bad/thing [v1.4.5, v1.9.7] => good/thing v2.0.0
114)
115")
116
117(define fixture-go-mod-retract
118 "retract v0.9.1
119
120retract (
121 v1.9.2
122 [v1.0.0, v1.7.9]
123)
124")
125
126(define fixture-go-mod-strings
127 "require `example.com/\"some-repo\"` v1.9.3
128require (
129 `example.com/\"another.repo\"` v1.0.0
130 \"example.com/special!repo\" v9.3.1
131)
132replace \"example.com/\\\"some-repo\\\"\" => `launchpad.net/some-repo` v1.9.3
133replace (
134 \"example.com/\\\"another.repo\\\"\" => launchpad.net/another-repo v1.0.0
135)
136")
137
138(define fixtures-go-check-test
139 (let ((version
140 "{\"Version\":\"v0.0.0-20201130134442-10cb98267c6c\",\"Time\":\"2020-11-30T13:44:42Z\"}")
141 (go.info
142 "{\"Version\":\"v0.0.0-20201130134442-10cb98267c6c\",\"Time\":\"2020-11-30T13:44:42Z\"}")
143 (go.mod
144 "module gopkg.in/check.v1
145
146go 1.11
147
148require github.com/kr/pretty v0.2.1
149")
150 (go-get
151 "<!DOCTYPE html>
152<html lang=\"en\" >
153 <head>
154 <meta charset=\"utf-8\">
155 <link rel=\"dns-prefetch\" href=\"https://github.githubassets.com\">
156 <script crossorigin=\"anonymous\" defer=\"defer\" integrity=\"sha512-aw5tciVT0IsECUmMuwp9ez60QReE2/yFNL1diLgZnOom6RhU8+0lG3RlAKto4JwbCoEP15E41Pksd7rK5BKfCQ==\" type=\"application/javascript\" src=\"https://github.githubassets.com/assets/topic-suggestions-6b0e6d72.js\"></script>
157 <meta name=\"viewport\" content=\"width=device-width\">
158
159 <title>GitHub - go-check/check: Rich testing for the Go language</title>
160 <meta name=\"description\" content=\"Rich testing for the Go language. Contribute to go-check/check development by creating an account on GitHub.\">
161 <link rel=\"search\" type=\"application/opensearchdescription+xml\" href=\"/opensearch.xml\" title=\"GitHub\">
162 <link rel=\"fluid-icon\" href=\"https://github.com/fluidicon.png\" title=\"GitHub\">
163 <!-- To prevent page flashing, the optimizely JS needs to be loaded in the
164 <head> tag before the DOM renders -->
165 <meta name=\"hostname\" content=\"github.com\">
166 <meta name=\"user-login\" content=\"\">
167 <link href=\"https://github.com/go-check/check/commits/v1.atom\" rel=\"alternate\" title=\"Recent Commits to check:v1\" type=\"application/atom+xml\">
168 <meta name=\"go-import\" content=\"github.com/go-check/check git https://github.com/go-check/check.git\">
169 </head>
170 <body class=\"logged-out env-production page-responsive\" style=\"word-wrap: break-word;\">
171 </body>
172</html>
173")
174 (pkg.go.dev "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n</head>\n<body class=\"Site Site--wide Site--redesign\">\n <div class=\"Site-content\">\n <div class=\"Container\">\n <div class=\"UnitDetails\" data-test-id=\"UnitDetails\">\n <div class=\"UnitDetails-content js-unitDetailsContent\" role=\"main\" data-test-id=\"UnitDetails-content\">\n <div class=\"UnitReadme js-readme\">\n <h2 class=\"UnitReadme-title\" id=\"section-readme\"><img height=\"25px\" width=\"20px\" src=\"/static/img/pkg-icon-readme_20x16.svg\" alt=\"\">README</h2>\n <div class=\"UnitReadme-content\" data-test-id=\"Unit-readmeContent\">\n <div class=\"Overview-readmeContent js-readmeContent\">\n <h3 class=\"h1\" id=\"readme-instructions\">Instructions</h3>\n <p>Install the package with:</p>\n <pre><code>go get gopkg.in/check.v1\n</code></pre>\n </div>\n <div class=\"UnitReadme-fadeOut\"></div>\n </div>\n </div>\n <div class=\"UnitDoc\">\n <h2 class=\"UnitDoc-title\" id=\"section-documentation\"><img height=\"25px\" width=\"20px\" src=\"/static/img/pkg-icon-doc_20x12.svg\" alt=\"\">Documentation</h2>\n <div class=\"Documentation js-documentation\">\n <div class=\"Documentation-content js-docContent\">\n <section class=\"Documentation-overview\">\n <h3 tabindex=\"-1\" id=\"pkg-overview\" class=\"Documentation-overviewHeader\">Overview <a href=\"#pkg-overview\">¶</a></h3>\n <div role=\"navigation\" aria-label=\"Table of Contents\">\n <ul class=\"Documentation-toc\"></ul>\n </div>\n <p>Package check is a rich testing extension for Go's testing package.</p>\n <p>For details about the project, see:</p>\n <pre><a href=\"http://labix.org/gocheck\">http://labix.org/gocheck</a>\n</pre>\n </section>\n <h3 tabindex=\"-1\" id=\"pkg-constants\" class=\"Documentation-constantsHeader\">Constants <a href=\"#pkg-constants\">¶</a></h3>\n </div>\n </div>\n </div>\n </div>\n </div>\n </div>\n </div>\n</body>\n</html>\n")
175 (pkg.go.dev-licence "<!DOCTYPE html>\n<html lang=\"en\">\n<meta charset=\"utf-8\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n<body class=\"Site Site--wide Site--redesign\">\n <div class=\"Unit-content\" role=\"main\">\n <section class=\"License\" id=\"lic-0\">\n <h2><div id=\"#lic-0\">BSD-2-Clause</div></h2>\n <p>This is not legal advice. <a href=\"/license-policy\">Read disclaimer.</a></p>\n <pre class=\"License-contents\">Gocheck - A rich testing framework for Go\n \nCopyright line\n\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met: \n\n1. Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer. \n2. Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation\n and/or other materials provided with the distribution. \n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &#34;AS IS&#34; AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\nON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n</pre>\n </section>\n <div class=\"License-source\">Source: github.com/go-check/check@v0.0.0-20201128035030-22ab2dfb190c/LICENSE</div>\n </div>\n </div>\n"))
176 `(("https://proxy.golang.org/github.com/go-check/check/@v/v0.0.0-20201130134442-10cb98267c6c.mod"
177 . ,go.mod)
178 ("https://proxy.golang.org/github.com/go-check/check/@latest"
179 . ,version)
180 ("https://proxy.golang.org/github.com/go-check/check/@v/v0.0.0-20201130134442-10cb98267c6c.info"
181 . ,go.info)
182 ("https://github.com/go-check/check?go-get=1"
183 . ,go-get)
184 ("https://pkg.go.dev/github.com/go-check/check"
185 . ,pkg.go.dev)
186 ("https://pkg.go.dev/github.com/go-check/check?tab=licenses"
187 . ,pkg.go.dev-licence)
188 ("https://proxy.golang.org/github.com/go-check/check/@v/list" . ""))))
189
190(test-begin "go")
191
192;;; Unit tests for go build-system
193
194(test-equal "go-version basic"
195 "v1.0.2"
196 (go-version->git-ref "v1.0.2"))
197
198(test-equal "go-version with embedded git-ref"
199 "65e3620a7ae7"
200 (go-version->git-ref "v0.0.0-20190821162956-65e3620a7ae7"))
201
202(test-equal "go-version with complex embedded git-ref"
203 "daa7c04131f5"
204 (go-version->git-ref "v1.2.4-0.20191109021931-daa7c04131f5"))
205
206(test-assert "go-pseudo-version? multi-digit version number"
207 (go-pseudo-version? "v1.23.1-0.20200526195155-81db48ad09cc"))
208
209(test-assert "go-pseudo-version? semantic version with rc"
210 (go-pseudo-version? "v1.4.0-rc.4.0.20200313231945-b860323f09d0"))
211
212;;; Unit tests for (guix import go)
213
214(test-equal "go-path-escape"
215 "github.com/!azure/!avere"
216 ((@@ (guix import go) go-path-escape) "github.com/Azure/Avere"))
217
218
219;; We define a function for all similar tests with different go.mod files
220(define (testing-parse-mod name expected input)
221 (define (inf? p1 p2)
222 (string<? (car p1) (car p2)))
223 (test-equal name
224 (sort expected inf?)
225 (sort (go.mod-requirements (parse-go.mod input)) inf?)))
226
227(testing-parse-mod "parse-go.mod-simple"
228 '(("good/thing" "v1.4.5")
229 ("new/thing/v2" "v2.3.4")
230 ("other/thing" "v1.0.2"))
231 fixture-go-mod-simple)
232
233(testing-parse-mod "parse-go.mod-with-block"
234 '(("A" "v1")
235 ("B" "v1.0.0")
236 ("C" "v1.0.0")
237 ("D" "v1.2.3")
238 ("E" "dev"))
239 fixture-go-mod-with-block)
240
241(testing-parse-mod
242 "parse-go.mod-complete"
243 '(("github.com/corp/arbitrary-repo" "v0.0.2")
244 ("quoted.example.com/abitrary/repo" "v0.0.2")
245 ("one.example.com/abitrary/repo" "v1.1.111")
246 ("hub.jazz.net/git/user/project/sub/directory" "v1.1.19")
247 ("hub.jazz.net/git/user/project" "v1.1.18")
248 ("launchpad.net/~user/project/branch/sub/directory" "v1.1.17")
249 ("launchpad.net/~user/project/branch" "v1.1.16")
250 ("launchpad.net/project/series/sub/directory" "v1.1.15")
251 ("launchpad.net/project/series" "v1.1.14")
252 ("launchpad.net/project" "v1.1.13")
253 ("bitbucket.org/user/project/sub/directory" "v1.11.21")
254 ("bitbucket.org/user/project" "v1.11.20")
255 ("k8s.io/kubernetes/subproject" "v1.1.101")
256 ("github.com/user/project/sub/directory" "v1.1.12")
257 ("github.com/user/project" "v1.1.11")
258 ("github.com/go-check/check" "v0.0.0-20140225173054-eb6ee6f84d0a"))
259 fixture-go-mod-complete)
260
261(test-equal "parse-go.mod: simple"
262 `((module (module-path "my/thing"))
263 (go (version "1.12"))
264 (require (module-path "other/thing") (version "v1.0.2"))
265 (require (module-path "new/thing/v2") (version "v2.3.4"))
266 (exclude (module-path "old/thing") (version "v1.2.3"))
267 (replace (original (module-path "bad/thing") (version "v1.4.5"))
268 (with (module-path "good/thing") (version "v1.4.5"))))
269 (parse-go.mod fixture-go-mod-simple))
270
271(test-equal "parse-go.mod: comments and unparsable lines"
272 `((module (module-path "my/thing"))
273 (go (version "1.12") (comment "avoid feature X"))
274 (require (module-path "other/thing") (version "v1.0.2"))
275 (comment "Security issue: CVE-XXXXX")
276 (exclude (module-path "old/thing") (version "v1.2.3"))
277 (unknown "new-directive another/thing yet-another/thing")
278 (replace (original (module-path "bad/thing") (version "v1.4.5"))
279 (with (module-path "good/thing") (version "v1.4.5")))
280 (comment "Unparseable")
281 (unknown "bad/thing [v1.4.5, v1.9.7] => good/thing v2.0.0"))
282 (parse-go.mod fixture-go-mod-unparsable))
283
284(test-equal "parse-go.mod: retract"
285 `((retract (version "v0.9.1"))
286 (retract (version "v1.9.2"))
287 (retract (range (version "v1.0.0") (version "v1.7.9"))))
288 (parse-go.mod fixture-go-mod-retract))
289
290(test-equal "parse-go.mod: raw strings and quoted strings"
291 `((require (module-path "example.com/\"some-repo\"") (version "v1.9.3"))
292 (require (module-path "example.com/\"another.repo\"") (version "v1.0.0"))
293 (require (module-path "example.com/special!repo") (version "v9.3.1"))
294 (replace (original (module-path "example.com/\"some-repo\""))
295 (with (module-path "launchpad.net/some-repo") (version "v1.9.3")))
296 (replace (original (module-path "example.com/\"another.repo\""))
297 (with (module-path "launchpad.net/another-repo") (version "v1.0.0"))))
298 (parse-go.mod fixture-go-mod-strings))
299
300(test-equal "parse-go.mod: complete"
301 `((module (module-path "M"))
302 (go (version "1.13"))
303 (replace (original (module-path "github.com/myname/myproject/myapi"))
304 (with (file-path "./api")))
305 (replace (original (module-path "github.com/mymname/myproject/thissdk"))
306 (with (file-path "../sdk")))
307 (replace (original (module-path "launchpad.net/gocheck"))
308 (with (module-path "github.com/go-check/check")
309 (version "v0.0.0-20140225173054-eb6ee6f84d0a")))
310 (require (module-path "github.com/user/project")
311 (version "v1.1.11"))
312 (require (module-path "github.com/user/project/sub/directory")
313 (version "v1.1.12"))
314 (require (module-path "bitbucket.org/user/project")
315 (version "v1.11.20"))
316 (require (module-path "bitbucket.org/user/project/sub/directory")
317 (version "v1.11.21"))
318 (require (module-path "launchpad.net/project")
319 (version "v1.1.13"))
320 (require (module-path "launchpad.net/project/series")
321 (version "v1.1.14"))
322 (require (module-path "launchpad.net/project/series/sub/directory")
323 (version "v1.1.15"))
324 (require (module-path "launchpad.net/~user/project/branch")
325 (version "v1.1.16"))
326 (require (module-path "launchpad.net/~user/project/branch/sub/directory")
327 (version "v1.1.17"))
328 (require (module-path "hub.jazz.net/git/user/project")
329 (version "v1.1.18"))
330 (require (module-path "hub.jazz.net/git/user/project/sub/directory")
331 (version "v1.1.19"))
332 (require (module-path "k8s.io/kubernetes/subproject")
333 (version "v1.1.101"))
334 (require (module-path "one.example.com/abitrary/repo")
335 (version "v1.1.111"))
336 (require (module-path "two.example.com/abitrary/repo")
337 (version "v0.0.2"))
338 (require (module-path "quoted.example.com/abitrary/repo")
339 (version "v0.0.2"))
340 (replace (original (module-path "two.example.com/abitrary/repo"))
341 (with (module-path "github.com/corp/arbitrary-repo")
342 (version "v0.0.2")))
343 (replace (original (module-path "golang.org/x/sys"))
344 (with (module-path "golang.org/x/sys")
345 (version "v0.0.0-20190813064441-fde4db37ae7a"))
346 (comment "pinned to release-branch.go1.13"))
347 (replace (original (module-path "golang.org/x/tools"))
348 (with (module-path "golang.org/x/tools")
349 (version "v0.0.0-20190821162956-65e3620a7ae7"))
350 (comment "pinned to release-branch.go1.13")))
351 (parse-go.mod fixture-go-mod-complete))
352
353;;; End-to-end tests for (guix import go)
354(define (mock-http-fetch testcase)
355 (lambda (url . rest)
356 (let ((body (assoc-ref testcase url)))
357 (if body
358 (open-input-string body)
359 (error "mocked http-fetch Unexpected URL: " url)))))
360
361(define (mock-http-get testcase)
362 (lambda (url . rest)
363 (let ((body (assoc-ref testcase url))
364 (response-header
365 (build-response
366 #:version '(1 . 1)
367 #:code 200
368 #:reason-phrase "Ok"
369 #:headers `(
370 (content-type text/html (charset . "utf-8"))
371 (date . ,(make-date 0 10 58 12 6 3 2021 0))
372 (transfer-encoding (chunked)))
373 #:port #f
374 #:validate-headers? #t)))
375 (if body
376 (values response-header body)
377 (error "mocked http-get Unexpected URL: " url)))))
378
379(test-equal "go-module->guix-package"
380 '(package
381 (name "go-github-com-go-check-check")
382 (version "0.0.0-20201130134442-10cb98267c6c")
383 (source
384 (origin
385 (method git-fetch)
386 (uri (git-reference
387 (url "https://github.com/go-check/check")
388 (commit (go-version->git-ref version))))
389 (file-name (git-file-name name version))
390 (sha256
391 (base32
392 "0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5"))))
393 (build-system go-build-system)
394 (arguments
395 (list #:import-path "github.com/go-check/check"))
396 (propagated-inputs
397 (list go-github-com-kr-pretty))
398 (home-page "https://github.com/go-check/check")
399 (synopsis "Instructions")
400 (description "Package check is a rich testing extension for Go's testing \
401package.")
402 (license license:bsd-2))
403
404 ;; Replace network resources with sample data.
405 (call-with-temporary-directory
406 (lambda (checkout)
407 (mock ((web client) http-get
408 (mock-http-get fixtures-go-check-test))
409 (mock ((guix http-client) http-fetch
410 (mock-http-fetch fixtures-go-check-test))
411 (mock ((guix import utils) git->origin
412 ;; Mock an empty directory by replacing hash.
413 (lambda* (url proc #:key ref #:rest args)
414 (git-origin url (peek-body proc) "\
4150sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5")))
416 (go-module->guix-package* "github.com/go-check/check")))))))
417
418(test-end "go")