aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-http-client)
  #:use-module (guix http-client)
  #:use-module (guix tests http)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-34)
  #:use-module (srfi srfi-64)
  #:use-module (rnrs bytevectors)
  #:use-module (rnrs io ports)
  #:use-module (web response)
  #:use-module (web uri))

(test-begin "http-client")

(test-equal "http-fetch, one request, binary"
  (string->utf8 "Hello, world.")
  (with-http-server `((200 "Hello, world."))
    (let* ((port (http-fetch (%local-url)))
           (bv   (get-bytevector-all port)))
      (close-port port)
      bv)))

(test-equal "http-fetch, one request, text"
  "Hello, world."
  (with-http-server `((200 "Hello, world."))
    (let* ((port (http-fetch (%local-url) #:text? #t))
           (data (get-string-all port)))
      (close-port port)
      data)))

(test-equal "http-fetch, redirect"
  "Hello, world."
  (with-http-server `((,(build-response
                         #:code 301
                         #:headers
                         `((location
                            . ,(string->uri-reference "/elsewhere")))
                         #:reason-phrase "Moved")
                       "Redirect!")
                      (200 "Hello, world."))
    (let* ((port (http-fetch (%local-url)))
           (data (get-string-all port)))
      (close-port port)
      data)))

(test-equal "http-fetch, error"
  404
  (with-http-server `((404 "Ne trovita."))
    (guard (c ((http-get-error? c) (http-get-error-code c)))
      (http-fetch (%local-url))
      #f)))

(test-equal "http-fetch, redirect + error"
  403
  (with-http-server `((,(build-response
                         #:code 302
                         #:headers
                         `((location
                            . ,(string->uri-reference "/elsewhere")))
                         #:reason-phrase "Moved")
                       "Redirect!")
                      (403 "Verboten."))
    (guard (c ((http-get-error? c) (http-get-error-code c)))
      (http-fetch (%local-url))
      #f)))

(test-end "http-client")
ests. Nicolas Goaziou 2023-07-18guix: texlive importer ignores dependencies unnecessary in Guix....* guix/import/texlive.scm (translate-depends): New function. (tlpdb->package): Use new function. * tests/texlive.scm (%fake-tlpdb): Add test data. ("texlive->guix-package, translate dependencies"): ("texlive->guix-package, lonely `hyphen-base' dependency and ARCH"): New tests. Nicolas Goaziou 2023-07-18guix: Let texlive importer suggest format creation....* guix/import/texlive.scm (tlpdb): Store "execute" entries. (tlpdb->package): Add #:CREATE-FORMATS argument when there is an AddFormat execute action. * tests/texlive.scm (%fake-tlpdb): Add test data. ("texlive->guix-package, with TeX format"): ("texlive->guix-package, execute but no TeX format"): New tests. Nicolas Goaziou 2023-07-18guix: import: Improve importing texlive meta packages....* guix/import/texlive.scm (tlpdb->package): Generate more appropriate source, home page and license fields when importing meta packages, i.e., TeX Live collections and schemes. * tests/texlive.scm (%fake-tlpdb): Add test data. ("texlive->guix-package, meta-package"): New test. Nicolas Goaziou 2023-07-18guix: import: Handle native inputs in texlive importer....* guix/import/texlive.scm (tlpdb->package): Add TEXLIVE-METAFONT as a native input whenever font metrics are to be generated. * tests/texlive.scm (%fake-tlpdb): Add test data. ("texlive->guix-package, with METAFONT files"): New test. Nicolas Goaziou 2023-07-18guix: import: Fix multiple licenses output in texlive importer....* guix/import/texlive.scm (string->license): Add missing case and try first to split license strings before giving up. * tests/texlive.scm (%fake-tlpdb): Add test data. ("texlive->guix-package, multiple licenses"): New test. Nicolas Goaziou 2023-07-18guix: import: Improve home-page generation in texlive importer....* guix/import/texlive.scm (tlpdb): Also register `catalogue' key. (tlpdb->package): First try to use catalogue for the home-page, then the name. * tests/texlive.scm (%fake-tlpdb): Add tests data. ("texlive->guix-package, with catalogue entry, no inputs"): New test. Nicolas Goaziou 2023-07-18guix: import: Update texlive importer according to new build system....* guix/import/texlive.scm (tlpdb->package): Generate a package that doesn't need SIMPLE-TEXLIVE-PACKAGE. * guix/import/utils.scm (package->definition): Remove special case for `simple-texlive-package'. * tests/texlive.scm (%fake-tlpdb): Add test data. ("texlive->guix-package"): Update test. ("texlive->guix-package, no docfiles"): New test. Nicolas Goaziou 2023-05-31tests: Use quasiquoted 'match' patterns for package sexps....Turns out it's easier to read. * tests/cpan.scm ("cpan->guix-package"): Use a quasiquoted pattern. * tests/elpa.scm (eval-test-with-elpa): Likewise. * tests/gem.scm ("gem->guix-package") ("gem->guix-package with a specific version") ("gem-recursive-import") ("gem-recursive-import with a specific version"): Likewise. * tests/hexpm.scm ("hexpm-recursive-import"): Likewise. * tests/opam.scm ("opam->guix-package"): Likewise. * tests/pypi.scm ("pypi->guix-package, no wheel") ("pypi->guix-package, wheels") ("pypi->guix-package, no usable requirement file.") ("pypi->guix-package, package name contains \"-\" followed by digits"): Likewise. * tests/texlive.scm ("texlive->guix-package"): Likewise. Ludovic Courtès 2023-04-19tests: Fix texlive->guix-package test....The home page for the package had changed. * tests/texlive.scm ("texlive->guix-package"): Match the home-page and synopsis inexactly to avoid future similar breakages. Maxim Cournoyer 2022-07-22tests: Adjust texlive importer tests....This is a follow-up to commit be7b314f3fe22273e935accac22f313e44d3d970. * tests/texlive.scm: Add version field to expected output. Ricardo Wurmus 2022-01-13import: texlive: Remove labels from 'propagated-inputs' field....* guix/import/texlive.scm (tlpdb->package): Remove labels from 'propagated-inputs' field. * tests/texlive.scm ("texlive->guix-package"): Adjust accordingly. Ludovic Courtès 2022-01-11tests: Fix texlive test by sorting locations....* tests/texlive.scm ("texlive->guix-package"): Correct order of locations. Ricardo Wurmus 2021-11-18tests: Replace texlive importer tests....* tests/texlive.scm (xml, sxml): Remove variables. ("fetch-sxml: returns SXML for valid XML", "sxml->package"): Remove tests. ("texlive->guix-package"): Add new test. Ricardo Wurmus