Commit | Line | Data |
---|---|---|
b18f45c2 LC |
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))))) |