From ca43bd364112cf15ff5871e92890b4a0a201c817 Mon Sep 17 00:00:00 2001
From: Maxime Devos <maximedevos@telenet.be>
Date: Sat, 8 May 2021 21:48:20 +0200
Subject: [PATCH 2/2] tests: networking: Test whether the gateway is usable.
The IPFS daemon listens at two endpoints. One is called the gateway
and the other is called the API. There are some tests for the API, but
none yet for the gateway. Test whether data can be read from the gateway.
* gnu/tests/networking.scm
(run-ipfs-test)[test]{read-contents/gateway}: New procedure, variant
of 'read-contents'.
(run-ipfs-test)[test]{can upload and download a file to/from ipfs}:
Rename to ...
(run-ipfs-test)[test]{can upload and download a file to/from ipfs via API}
This.
(run-ipfs-test)[test]{can download a file from ipfs via gateway}:
New test.
---
gnu/tests/networking.scm | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
@@ -620,8 +620,21 @@ COMMIT
(close-port input)
all-input)
marionette))
-
- (marionette-eval '(use-modules (guix ipfs)) marionette)
+ (define (read-contents/gateway object)
+ (marionette-eval
+ `(receive (response body)
+ (http-get (string->uri
+ (string-append "http://localhost:8082/ipfs/"
+ ,object))
+ #:decode-body? #f)
+ (list (response-code response) body))
+ marionette))
+ (marionette-eval '(use-modules (guix ipfs)
+ (web client)
+ (web response)
+ (web uri)
+ (srfi srfi-8))
+ marionette)
(mkdir #$output)
(chdir #$output)
@@ -640,9 +653,15 @@ COMMIT
(wait-for-tcp-port default-port marionette)))
(define test-bv (string->utf8 "hello ipfs!"))
- (test-equal "can upload and download a file to/from ipfs"
+ (define test-object (delay (add-data test-bv)))
+
+ (test-equal "can upload and download a file to/from ipfs via API"
test-bv
- (read-contents (add-data test-bv)))
+ (read-contents (force test-object)))
+
+ (test-equal "can download a file from ipfs via gateway"
+ (list 200 test-bv)
+ (read-contents/gateway (force test-object)))
(test-end)
(exit (= (test-runner-fail-count (test-runner-current)) 0)))))
--
2.31.1