From a45461c3647d643ddaa0cf76bac334d603581cf6 Mon Sep 17 00:00:00 2001 From: c0llab0rat0r <78339685+c0llab0rat0r@users.noreply.github.com> Date: Sat, 10 Apr 2021 13:56:51 -0500 Subject: [PATCH] Add configuration scripts for local IPFS server --- README.md | 11 ++++++++--- test/functional/conftest.py | 2 +- test/functional/test_pin.py | 6 +++--- tools/ipfs/README.md | 27 +++++++++++++++++++++++++++ tools/ipfs/configure.sh | 12 ++++++++++++ tools/ipfs/run.sh | 5 +++++ 6 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 tools/ipfs/README.md create mode 100755 tools/ipfs/configure.sh create mode 100755 tools/ipfs/run.sh diff --git a/README.md b/README.md index 80b6f55f..0d720378 100644 --- a/README.md +++ b/README.md @@ -208,8 +208,7 @@ You can submit bug reports using the ### Setting up a local development environment - 1. Follow the instructions in the IPFS documentation to install go-IPFS into your `${PATH}`: - https://docs.ipfs.io/install/command-line/ + 1. [Install and configure a local IPFS server](tools/ipfs/README.md): 2. Follow the instructions in the (Python) tox documentation to install the `tox` Python environment runner: https://tox.readthedocs.io/en/latest/install.html 3. Clone the GIT repository if you haven't already: @@ -235,7 +234,13 @@ make sure that your code passes both the $ tox -e styleck -e typeck -As well as the unit tests: +As well as the tests: + +1. Start IPFS server (do this once in a separate terminal): + + $ ./tools/ipfs/run.sh + +2. Execute unit and functional tests: $ tox -e py3 -e py3-httpx diff --git a/test/functional/conftest.py b/test/functional/conftest.py index 086f28dd..61c8e175 100644 --- a/test/functional/conftest.py +++ b/test/functional/conftest.py @@ -1,7 +1,7 @@ # Note that this file is special in that py.test will automatically import this file and gather # its list of fixtures even if it is not directly imported into the corresponding test case. -import pathlib +import pathlib import pytest import ipfshttpclient diff --git a/test/functional/test_pin.py b/test/functional/test_pin.py index 3546d319..d70c46a6 100644 --- a/test/functional/test_pin.py +++ b/test/functional/test_pin.py @@ -1,4 +1,4 @@ -import pathlib +from pathlib import Path import pytest @@ -6,10 +6,10 @@ class Resources: - def __init__(self, client, source_folder: pathlib.Path) -> None: + def __init__(self, client, source_folder: Path) -> None: self.msg = client.add_str("Mary had a little lamb") self.msg2 = client.add_str("Mary had a little alpaca") - resp_add = client.add(source_folder, recursive=True) + resp_add = client.add(str(source_folder), recursive=True) self.fake_dir_hashes = [el["Hash"] for el in resp_add if "Hash" in el] for resp in resp_add: if resp["Name"] == "fake_dir": diff --git a/tools/ipfs/README.md b/tools/ipfs/README.md new file mode 100644 index 00000000..9ddf6d61 --- /dev/null +++ b/tools/ipfs/README.md @@ -0,0 +1,27 @@ + +# Local IPFS Server + +`py-ipfs-httpclient` requires a live local server to run its +functional tests. + +## Installation + +To install it, follow the [official instructions](https://docs.ipfs.io/install/command-line/), +then finish with some [local configuration](configure.sh): + + $ ./configure.sh + +The above script is run once after installing. + +## Running Tests + +You can run unit tests without a live server; `pytest` will skip +over the functional tests when our fixtures detect the server +isn't running. + +In a separate terminal, start IPFS with: + + $ ./run.sh + +Stop it with Ctrl+C. You can keep it running across multiple +executions of the functional test suite. diff --git a/tools/ipfs/configure.sh b/tools/ipfs/configure.sh new file mode 100755 index 00000000..849976d8 --- /dev/null +++ b/tools/ipfs/configure.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Configures, but does not start, the IPFS daemon. Run once in your environment. +# +# Description of experimental features: +# https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#ipfs-filestore + +set -e + +ipfs init +ipfs config --json Experimental.FilestoreEnabled true +ipfs config --json Experimental.UrlstoreEnabled true diff --git a/tools/ipfs/run.sh b/tools/ipfs/run.sh new file mode 100755 index 00000000..4dc91c86 --- /dev/null +++ b/tools/ipfs/run.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# Run the IPFS server. To stop it, press Ctrl+C. + +ipfs daemon --enable-namesys-pubsub