Skip to content

Commit

Permalink
Merge pull request #12 from obsidiansystems/cn-test-suite-automatization
Browse files Browse the repository at this point in the history
Ipfs test suite
  • Loading branch information
Ericson2314 authored Jun 13, 2020
2 parents efd8790 + 953ceba commit 913d1c5
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 3 deletions.
3 changes: 2 additions & 1 deletion release-common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ rec {
sha256 = "1pij0v449p166f9l29x7ppzk8j7g9k9mp15ilh5qxp29c7fnvxy2";
}) ];
*/
}));
}))
++ lib.optional (stdenv.isLinux || stdenv.isDarwin) ipfs;

propagatedDeps =
[ (boehmgc.override { enableLargeConfig = true; })
Expand Down
2 changes: 1 addition & 1 deletion tests/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ source common.sh

test -n "$TEST_ROOT"
if test -d "$TEST_ROOT"; then
chmod -R u+w "$TEST_ROOT"
chmod -R u+rw "$TEST_ROOT"
rm -rf "$TEST_ROOT"
fi
mkdir "$TEST_ROOT"
Expand Down
117 changes: 117 additions & 0 deletions tests/ipfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
source common.sh

# This are for ./fixed.nix
export IMPURE_VAR1=foo
export IMPURE_VAR2=bar

################################################################################
## Check that the ipfs daemon is present and enabled in your environment
################################################################################

if [[ -z $(type -p ipfs) ]]; then
echo "Ipfs not installed; skipping ipfs tests"
exit 99
fi

# To see if ipfs is connected to the network, we check if we can see some peers
# other than ourselves.
if (! (ipfs log ls));
then
echo "Ipfs daemon not detected; initializing.."
ipfs init
ipfs daemon --offline &
pidIpfsDaemon=$!
trap "kill -9 $pidIpfsDaemon" EXIT
fi

clearStore

################################################################################
## Create the folders for the source and destination stores
################################################################################

IPFS_TESTS=$TEST_ROOT/ipfs_tests
mkdir $IPFS_TESTS

# Here we define some store locations, one for the initial store we upload, and
# the other three for the destination stores to which we'll copy (one for each
# method)
IPFS_SRC_STORE=$IPFS_TESTS/ipfs_source_store

IPFS_DST_HTTP_STORE=$IPFS_TESTS/ipfs_dest_http_store
IPFS_DST_HTTP_LOCAL_STORE=$IPFS_TESTS/ipfs_dest_http_local_store
IPFS_DST_IPFS_STORE=$IPFS_TESTS/ipfs_dest_ipfs_store
IPFS_DST_IPNS_STORE=$IPFS_TESTS/ipfs_dest_ipns_store

################################################################################
## Generate the keys to sign the store
################################################################################

SIGNING_KEY_NAME=nixcache.for.ipfs-1
SIGNING_KEY_PRI_FILE=$IPFS_TESTS/nix-cache-key.sec
SIGNING_KEY_PUB_FILE=$IPFS_TESTS/nix-cache-key.pub

nix-store --generate-binary-cache-key $SIGNING_KEY_NAME $SIGNING_KEY_PRI_FILE $SIGNING_KEY_PUB_FILE

################################################################################
## Create, sign and upload the source store
################################################################################

mkdir -p $IPFS_SRC_STORE
storePaths=$(nix-build ./fixed.nix -A good | sort | uniq)

# Hack around https://github.com/NixOS/nix/issues/3695
for path in $storePaths; do
nix copy --to file://$IPFS_SRC_STORE $path
done
unset path

nix sign-paths --store file://$IPFS_SRC_STORE \
-k $SIGNING_KEY_PRI_FILE $storePaths

IPFS_HASH=$(ipfs add -r $IPFS_SRC_STORE 2>/dev/null | tail -n 1 | awk '{print $2}')

################################################################################
## Create the local http store and download the derivation there
################################################################################

mkdir $IPFS_DST_HTTP_LOCAL_STORE

IPFS_HTTP_LOCAL_PREFIX='http://localhost:8080/ipfs'

DOWNLOAD_LOCATION=$(nix-build ./fixed.nix -A good \
--option substituters $IPFS_HTTP_LOCAL_PREFIX/$IPFS_HASH \
--store $IPFS_DST_HTTP_LOCAL_STORE \
--no-out-link \
-j0 \
--option trusted-public-keys $(cat $SIGNING_KEY_PUB_FILE))

################################################################################
## Create the ipfs store and download the derivation there
################################################################################

mkdir $IPFS_DST_IPFS_STORE

DOWNLOAD_LOCATION=$(nix-build ./fixed.nix -A good \
--option substituters 'ipfs://'$IPFS_HASH \
--store $IPFS_DST_IPFS_STORE \
--no-out-link \
-j0 \
--option trusted-public-keys $(cat $SIGNING_KEY_PUB_FILE))


################################################################################
## Create the ipns store and download the derivation there
################################################################################

# First I have to publish:
IPNS_ID=$(ipfs name publish $IPFS_HASH --allow-offline | awk '{print substr($3,1,length($3)-1)}')

mkdir $IPFS_DST_IPNS_STORE

DOWNLOAD_LOCATION=$(nix-build ./fixed.nix -A good \
--option substituters 'ipns://'$IPNS_ID \
--store $IPFS_DST_IPNS_STORE \
--no-out-link \
-j0 \
--option trusted-public-keys $(cat $SIGNING_KEY_PUB_FILE))
3 changes: 2 additions & 1 deletion tests/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ nix_tests = \
nix-copy-ssh.sh \
post-hook.sh \
function-trace.sh \
recursive.sh
recursive.sh \
ipfs.sh
# parallel.sh

install-tests += $(foreach x, $(nix_tests), tests/$(x))
Expand Down

0 comments on commit 913d1c5

Please sign in to comment.