import: cpan: Rewrite tests to use an HTTP server instead of mocking.

* guix/import/cpan.scm (%metacpan-base-url): New variable.
(module->dist-name, cpan-fetch): Refer to it instead of the hard-coded URL.
* tests/cpan.scm ("cpan->guix-package"): Use 'with-http-server' instead
of 'mock'.
This commit is contained in:
Ludovic Courtès 2020-01-15 18:35:14 +01:00
parent 69f132554c
commit 4aea90b187
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
2 changed files with 43 additions and 50 deletions

View file

@ -61,7 +61,9 @@
cpan-fetch
cpan->guix-package
metacpan-url->mirror-url
%cpan-updater))
%cpan-updater
%metacpan-base-url))
;;; Commentary:
;;;
@ -70,6 +72,10 @@
;;;
;;; Code:
(define %metacpan-base-url
;; Base URL of the MetaCPAN API.
(make-parameter "https://fastapi.metacpan.org/v1/"))
;; Dependency of a "release".
(define-json-mapping <cpan-dependency> make-cpan-dependency cpan-dependency?
json->cpan-dependency
@ -149,7 +155,7 @@
module is distributed with 'Test::Simple', so (module->dist-name \"ok\") would
return \"Test-Simple\""
(assoc-ref (json-fetch (string-append
"https://fastapi.metacpan.org/v1/module/"
(%metacpan-base-url) "/module/"
module
"?fields=distribution"))
"distribution"))
@ -176,7 +182,7 @@ or #f on failure. MODULE should be the distribution name, such as
\"Test-Script\" for the \"Test::Script\" module."
;; This API always returns the latest release of the module.
(json->cpan-release
(json-fetch (string-append "https://fastapi.metacpan.org/v1/release/"
(json-fetch (string-append (%metacpan-base-url) "/release/"
name))))
(define (cpan-home name)