diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2018-12-28 01:07:58 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2021-04-12 18:42:22 +0200 |
| commit | b18f45c21f5d697d384a7bd5c9d3ee314bba9e35 (patch) | |
| tree | b9db10db65e6015461f44439c36659f6f7f61b99 /tests/ipfs.scm | |
| parent | 2978832b9264b89325605fe2525bc3992d753135 (diff) | |
Add (guix ipfs).
This module allows for communicating with the IPFS
gateway over the HTTP interface. The commit has been
cherry-picked from <https://issues.guix.gnu.org/33899>.
The procedures for adding and restoring file trees have
been removed as according to a reply issue 33899, a different
format will be used. The procedure 'add-data' has been
exported as it will be used in the system test for IPFS.
* guix/ipfs.scm: New file.
* Makefile.am (MODULES): Add it.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'tests/ipfs.scm')
| -rw-r--r-- | tests/ipfs.scm | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/ipfs.scm b/tests/ipfs.scm new file mode 100644 index 00000000000..3b662b22bd9 --- /dev/null +++ b/tests/ipfs.scm | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | ||
| 2 | ;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | ;;; | ||
| 4 | ;;; This file is part of GNU Guix. | ||
| 5 | ;;; | ||
| 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | ;;; under the terms of the GNU General Public License as published by | ||
| 8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | ;;; your option) any later version. | ||
| 10 | ;;; | ||
| 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | ;;; GNU General Public License for more details. | ||
| 15 | ;;; | ||
| 16 | ;;; You should have received a copy of the GNU General Public License | ||
| 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | |||
| 19 | (define-module (test-ipfs) | ||
| 20 | #:use-module (guix ipfs) | ||
| 21 | #:use-module ((guix utils) #:select (call-with-temporary-directory)) | ||
| 22 | #:use-module (guix tests) | ||
| 23 | #:use-module (web uri) | ||
| 24 | #:use-module (srfi srfi-64)) | ||
| 25 | |||
| 26 | ;; Test the (guix ipfs) module. | ||
| 27 | |||
| 28 | (define (ipfs-gateway-running?) | ||
| 29 | "Return true if the IPFS gateway is running at %IPFS-BASE-URL." | ||
| 30 | (let* ((uri (string->uri (%ipfs-base-url))) | ||
| 31 | (socket (socket AF_INET SOCK_STREAM 0))) | ||
| 32 | (define connected? | ||
| 33 | (catch 'system-error | ||
| 34 | (lambda () | ||
| 35 | (format (current-error-port) | ||
| 36 | "probing IPFS gateway at localhost:~a...~%" | ||
| 37 | (uri-port uri)) | ||
| 38 | (connect socket AF_INET INADDR_LOOPBACK (uri-port uri)) | ||
| 39 | #t) | ||
| 40 | (const #f))) | ||
| 41 | |||
| 42 | (close-port socket) | ||
| 43 | connected?)) | ||
| 44 | |||
| 45 | (unless (ipfs-gateway-running?) | ||
| 46 | (test-skip 1)) | ||
| 47 | |||
| 48 | (test-assert "add-file-tree + restore-file-tree" | ||
| 49 | (call-with-temporary-directory | ||
| 50 | (lambda (directory) | ||
| 51 | (let* ((source (dirname (search-path %load-path "guix/base32.scm"))) | ||
| 52 | (target (string-append directory "/r")) | ||
| 53 | (content (pk 'content (add-file-tree source)))) | ||
| 54 | (restore-file-tree (content-name content) target) | ||
| 55 | (file=? source target))))) | ||
