ipfs.scm 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. (define-module (test-ipfs)
  19. #:use-module (guix ipfs)
  20. #:use-module ((guix utils) #:select (call-with-temporary-directory))
  21. #:use-module (guix tests)
  22. #:use-module (web uri)
  23. #:use-module (srfi srfi-64))
  24. ;; Test the (guix ipfs) module.
  25. (define (ipfs-gateway-running?)
  26. "Return true if the IPFS gateway is running at %IPFS-BASE-URL."
  27. (let* ((uri (string->uri (%ipfs-base-url)))
  28. (socket (socket AF_INET SOCK_STREAM 0)))
  29. (define connected?
  30. (catch 'system-error
  31. (lambda ()
  32. (format (current-error-port)
  33. "probing IPFS gateway at localhost:~a...~%"
  34. (uri-port uri))
  35. (connect socket AF_INET INADDR_LOOPBACK (uri-port uri))
  36. #t)
  37. (const #f)))
  38. (close-port socket)
  39. connected?))
  40. (unless (ipfs-gateway-running?)
  41. (test-skip 1))
  42. (test-assert "add-file-tree + restore-file-tree"
  43. (call-with-temporary-directory
  44. (lambda (directory)
  45. (let* ((source (dirname (search-path %load-path "guix/base32.scm")))
  46. (target (string-append directory "/r"))
  47. (content (pk 'content (add-file-tree source))))
  48. (restore-file-tree (content-name content) target)
  49. (file=? source target)))))