all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Maxime Devos <maximedevos@telenet.be>
To: 53389@debbugs.gnu.org
Cc: ludo@gnu.org, Maxime Devos <maximedevos@telenet.be>
Subject: [bug#53389] [PATCH 4/9] tests/import-github: Run a HTTP server instead of mocking.
Date: Thu, 20 Jan 2022 13:08:44 +0000	[thread overview]
Message-ID: <20220120130849.292178-4-maximedevos@telenet.be> (raw)
In-Reply-To: <20220120130849.292178-1-maximedevos@telenet.be>

Fixes: <https://issues.guix.gnu.org/53060#3>

* tests/import-github.scm (call-with-releases): Run a HTTP server instead of
  mocking.

Suggested-by: Ludovic Courtès <ludo@gnu.org>
---
 tests/import-github.scm | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/tests/import-github.scm b/tests/import-github.scm
index 979a0fc12b..f6985fac55 100644
--- a/tests/import-github.scm
+++ b/tests/import-github.scm
@@ -24,30 +24,28 @@
   #:use-module (guix http-client)
   #:use-module (guix import github)
   #:use-module (guix packages)
-  #:use-module (guix tests)
+  #:use-module (guix tests http)
   #:use-module (guix upstream)
+  #:use-module (web client)
+  #:use-module (web request)
+  #:use-module (web uri)
   #:use-module (ice-9 match))
 
 (test-begin "github")
 
 (define (call-with-releases thunk tags releases)
-  (mock ((guix http-client) http-fetch
-         (lambda* (uri #:key headers)
-           (unless (string-prefix? "mock://" uri)
-             (error "the URI ~a should not be used" uri))
-           (define components
-             (string-split (substring uri 8) #\/))
-           (pk 'stuff components headers)
-           (define (scm->json-port scm)
-             (open-input-string (scm->json-string scm)))
-           (match components
-             (("repos" "foo" "foomatics" "releases")
-              (scm->json-port releases))
-             (("repos" "foo" "foomatics" "tags")
-              (scm->json-port tags))
-             (rest (error "TODO ~a" rest)))))
-        (parameterize ((%github-api "mock://"))
-          (thunk))))
+  (with-http-server*
+   (lambda (request _)
+     (define resource (uri-path (request-uri request)))
+     (define components (string-split resource #\/))
+     (define json (match components
+                    (("" "repos" "foo" "foomatics" "releases") releases)
+                    (("" "repos" "foo" "foomatics" "tags") tags)
+                    (rest (error "TODO ~a" rest))))
+     (values '() (lambda (port) (scm->json json port))))
+   (parameterize ((%github-api (%local-url* ""))
+                  (current-http-proxy #false))
+     (thunk))))
 
 ;; Copied from tests/minetest.scm
 (define (upstream-source->sexp upstream-source)
-- 
2.30.2





  parent reply	other threads:[~2022-01-20 18:05 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20 12:59 [bug#53389] [PATCH 0/9] Replace some mocking with with-http-server*, avoid hardcoding ports, Maxime Devos
2022-01-20 13:08 ` [bug#53389] [PATCH 1/9] tests: Support arbitrary HTTP request handlers Maxime Devos
2022-01-20 13:08   ` [bug#53389] [PATCH 2/9] tests: Generalise %local-url Maxime Devos
2022-01-20 13:08   ` [bug#53389] [PATCH 3/9] tests/minetest: Run a HTTP server instead of mocking Maxime Devos
2022-01-20 13:08   ` Maxime Devos [this message]
2022-01-20 13:08   ` [bug#53389] [PATCH 5/9] tests/cpan: Do not hard code a HTTP port Maxime Devos
2022-01-20 13:08   ` [bug#53389] [PATCH 6/9] tests/lint: Do not assume the next port is free Maxime Devos
2022-01-20 13:08   ` [bug#53389] [PATCH 7/9] tests: Allow checking the URI of a HTTP request Maxime Devos
2022-01-20 13:08   ` [bug#53389] [PATCH 8/9] tests/cpan: Verify URIs Maxime Devos
2022-01-20 13:08   ` [bug#53389] [PATCH 9/9] tests/challenge: Do not hard code HTTP ports Maxime Devos
2022-01-22 16:48   ` [bug#53389] [PATCH 0/9] Replace some mocking with with-http-server*, avoid hardcoding ports, Ludovic Courtès
2022-01-22 18:55     ` Maxime Devos
2022-01-25  7:54       ` Ludovic Courtès
2022-01-25 13:37         ` Maxime Devos
2022-02-07  9:53       ` Ludovic Courtès
2022-02-07 10:59         ` Maxime Devos
2022-03-06 16:23           ` Ludovic Courtès
2022-03-07  7:00             ` Maxime Devos
2022-01-22 19:21     ` Maxime Devos
2022-01-22 19:57     ` Maxime Devos
2022-01-22 20:42     ` Maxime Devos
2022-01-22 18:08   ` [bug#53389] [PATCH 1/9] tests: Support arbitrary HTTP request handlers Maxime Devos
2022-01-20 15:11 ` [bug#53389] [PATCH 0/9] Replace some mocking with with-http-server*, avoid hardcoding ports, Ludovic Courtès
2022-04-12 19:46 ` [bug#53389] [PATCH 0/9] Replace some mocking with with-http-server Maxime Devos
2022-04-21 15:20 ` [bug#53389] [PATCH v2 0/25] Replace some mocking with with-http-server*, avoid harcoding ports Maxime Devos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220120130849.292178-4-maximedevos@telenet.be \
    --to=maximedevos@telenet.be \
    --cc=53389@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.