| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 |
|
| 21 | (define-module (test-cpan)
|
| 22 | #:use-module (guix import cpan)
|
| 23 | #:use-module (guix base32)
|
| 24 | #:use-module (guix upstream)
|
| 25 | #:use-module ((guix download) #:select (url-fetch))
|
| 26 | #:use-module (gcrypt hash)
|
| 27 | #:use-module (guix tests)
|
| 28 | #:use-module (guix tests http)
|
| 29 | #:use-module ((guix store) #:select (%graft?))
|
| 30 | #:use-module (srfi srfi-64)
|
| 31 | #:use-module (web client)
|
| 32 | #:use-module (ice-9 match))
|
| 33 |
|
| 34 | |
| 35 | (%graft? #f)
|
| 36 |
|
| 37 | (define test-json
|
| 38 | "{
|
| 39 | \"metadata\" : {
|
| 40 | \"name\" : \"Foo-Bar\",
|
| 41 | \"version\" : \"0.1\"
|
| 42 | }
|
| 43 | \"name\" : \"Foo-Bar-0.1\",
|
| 44 | \"distribution\" : \"Foo-Bar\",
|
| 45 | \"license\" : [
|
| 46 | \"perl_5\"
|
| 47 | ],
|
| 48 | \"dependency\": [
|
| 49 | { \"relationship\": \"requires\",
|
| 50 | \"phase\": \"runtime\",
|
| 51 | \"version\": \"1.05\",
|
| 52 | \"module\": \"Test::Script\"
|
| 53 | }
|
| 54 | ],
|
| 55 | \"abstract\" : \"Fizzle Fuzz\",
|
| 56 | \"download_url\" : \"http://example.com/Foo-Bar-0.1.tar.gz\",
|
| 57 | \"author\" : \"Guix\",
|
| 58 | \"version\" : \"0.1\"
|
| 59 | }")
|
| 60 |
|
| 61 | (define test-source
|
| 62 | "foobar")
|
| 63 |
|
| 64 | |
| 65 | (%http-server-port 10400)
|
| 66 |
|
| 67 | (test-begin "cpan")
|
| 68 |
|
| 69 | (test-assert "cpan->guix-package"
|
| 70 | (with-http-server `((200 ,test-json)
|
| 71 | (200 ,test-source)
|
| 72 | (200 "{ \"distribution\" : \"Test-Script\" }"))
|
| 73 | (parameterize ((%metacpan-base-url (%local-url))
|
| 74 | (current-http-proxy (%local-url)))
|
| 75 | (match (cpan->guix-package "Foo::Bar")
|
| 76 | (`(package
|
| 77 | (name "perl-foo-bar")
|
| 78 | (version "0.1")
|
| 79 | (source (origin
|
| 80 | (method url-fetch)
|
| 81 | (uri (string-append "http://example.com/Foo-Bar-"
|
| 82 | version ".tar.gz"))
|
| 83 | (sha256
|
| 84 | (base32 ,(? string? hash)))))
|
| 85 | (build-system perl-build-system)
|
| 86 | (propagated-inputs (list perl-test-script))
|
| 87 | (home-page "https://metacpan.org/release/Foo-Bar")
|
| 88 | (synopsis "Fizzle Fuzz")
|
| 89 | (description "Fizzle Fuzz.")
|
| 90 | (license perl-license))
|
| 91 | (string=? (bytevector->nix-base32-string
|
| 92 | (call-with-input-string test-source port-sha256))
|
| 93 | hash))
|
| 94 | (x
|
| 95 | (pk 'fail x #f))))))
|
| 96 |
|
| 97 | (test-equal "package-latest-release"
|
| 98 | (list '("http://example.com/Foo-Bar-0.1.tar.gz")
|
| 99 | #f
|
| 100 | (list (upstream-input
|
| 101 | (name "Test-Script")
|
| 102 | (downstream-name "perl-test-script")
|
| 103 | (type 'propagated))))
|
| 104 | (with-http-server `((200 ,test-json)
|
| 105 | (200 "{ \"distribution\" : \"Test-Script\" }")
|
| 106 | (200 ,test-source))
|
| 107 | (parameterize ((%metacpan-base-url (%local-url))
|
| 108 | (current-http-proxy (%local-url)))
|
| 109 | (define source
|
| 110 | (package-latest-release
|
| 111 | (dummy-package "perl-test-script"
|
| 112 | (version "0.0.0")
|
| 113 | (source (dummy-origin
|
| 114 | (method url-fetch)
|
| 115 | (uri "mirror://cpan/Foo-Bar-0.0.0.tgz"))))
|
| 116 | (list %cpan-updater)))
|
| 117 |
|
| 118 | (list (upstream-source-urls source)
|
| 119 | (upstream-source-signature-urls source)
|
| 120 | (upstream-source-inputs source)))))
|
| 121 |
|
| 122 | (test-equal "metacpan-url->mirror-url, http"
|
| 123 | "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"
|
| 124 | (metacpan-url->mirror-url
|
| 125 | "http://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"))
|
| 126 |
|
| 127 | (test-equal "metacpan-url->mirror-url, https"
|
| 128 | "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"
|
| 129 | (metacpan-url->mirror-url
|
| 130 | "https://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"))
|
| 131 |
|
| 132 | (test-end "cpan")
|