aboutsummaryrefslogtreecommitdiff
path: root/tests/http-client.scm
blob: 649fa1bfacb90bf3be1ad1120b784b816f9939a4 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
;;; 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")
es - improve performance & quality via `console.log()` insertionsAlex Lam S.L 2020-03-01avoid reducing setter argument (#3737)Alex Lam S.L 2020-02-29detect `toplevel` option properly (#3735)...fixes #3730Alex Lam S.L 2020-02-17improve `--reduce-test` (#3727)...- print out Node.js and OS informationAlex Lam S.L 2020-02-17speed up `--reduce-test` (#3726)...- avoid pathological test case branches via adaptive time-out - use initial test case elapsed time to adjust maximum time-out - index output cache using hash instead of raw sourceAlex Lam S.L 2020-02-15speed up `--reduce-test` via result caching (#3725)Alex Lam S.L 2020-02-15improve `--reduce-test` (#3722)...- hoist body of functions and IIFEs - simplify var declarationskzc 2020-02-14improve `--reduce-test` (#3719)...- cover missing cases when eliminating unreferenced labels - format multi-line outputs correctlyAlex Lam S.L 2020-02-09improve test reduction (#3711)...- scan `AST_SymbolFunarg` - scan `console.log(...)`Alex Lam S.L 2020-02-09improve `test/reduce` (#3710)...- suppress several instances of malformed AST generation - improve resilience & reporting against malformed ASTsAlex Lam S.L 2020-02-07fix corner cases in `test/reduce` (#3709)Alex Lam S.L 2020-02-06improve reduction of `AST_BlockStatement` (#3708)Alex Lam S.L 2020-02-06export missing API for AST manipulation (#3707)Alex Lam S.L 2020-02-06implement CLI `--reduce-test` and reduce tests in ufuzz (#3705)kzc