diff --git a/test/sharness/lib/iptb-lib.sh b/test/sharness/lib/iptb-lib.sh new file mode 100644 index 000000000..3ba09e791 --- /dev/null +++ b/test/sharness/lib/iptb-lib.sh @@ -0,0 +1,39 @@ +# iptb test framework +# +# Copyright (c) 2014, 2016 Jeromy Johnson, Christian Couder +# MIT Licensed; see the LICENSE file in this repository. + +export IPTB_ROOT="$(pwd)/.iptb" + +ipfsi() { + dir="$1" + shift + IPFS_PATH="$IPTB_ROOT/$dir" ipfs "$@" +} + +check_has_connection() { + node="$1" + ipfsi "$node" swarm peers >"swarm_peers_$node" && + grep "ipfs" "swarm_peers_$node" >/dev/null +} + +startup_cluster() { + num_nodes="$1" + bound=$(expr $num_nodes - 1) + + test_expect_success "start up nodes" ' + iptb start + ' + + test_expect_success "connect nodes to eachother" ' + iptb connect [1-$bound] 0 + ' + + for i in $(test_seq 1 $bound) + do + test_expect_success "node $i is connected" ' + check_has_connection "$i" || + test_fsh cat "swarm_peers_$i" + ' + done +} diff --git a/test/sharness/lib/test-lib.sh b/test/sharness/lib/test-lib.sh index ec28d6d77..9d2f40544 100644 --- a/test/sharness/lib/test-lib.sh +++ b/test/sharness/lib/test-lib.sh @@ -53,6 +53,9 @@ fi # source our generic test lib . ../../ipfs-test-lib.sh +# source iptb lib +. ../lib/iptb-lib.sh + test_cmp_repeat_10_sec() { for i in $(test_seq 1 100) do diff --git a/test/sharness/t0101-iptb-name.sh b/test/sharness/t0101-iptb-name.sh index f5534aa29..3dbea47da 100755 --- a/test/sharness/t0101-iptb-name.sh +++ b/test/sharness/t0101-iptb-name.sh @@ -8,46 +8,12 @@ test_description="Test ipfs repo operations" . lib/test-lib.sh -export IPTB_ROOT="`pwd`/.iptb" - num_nodes=4 -ipfsi() { - dir="$1" - shift - IPFS_PATH="$IPTB_ROOT/$dir" ipfs $@ -} - test_expect_success "set up an iptb cluster" ' iptb init -n $num_nodes -p 0 -f --bootstrap=none ' -check_has_connection() { - node=$1 - ipfsi $node swarm peers | grep ipfs > /dev/null -} - -startup_cluster() { - bound=`expr $num_nodes - 1` - test_expect_success "start up nodes" ' - iptb start - ' - - test_expect_success "connect nodes to eachother" ' - iptb connect [1-$bound] 0 - ' - - test_expect_success "nodes are connected" ' - for i in `seq $bound` - do - if ! check_has_connection $i; then - echo "oh shit guys" - return 1 - fi - done - ' -} - startup_cluster $num_nodes test_expect_success "add an obect on one node" ' diff --git a/test/sharness/t0121-bootstrap-iptb.sh b/test/sharness/t0121-bootstrap-iptb.sh index abf2be049..290ebe879 100755 --- a/test/sharness/t0121-bootstrap-iptb.sh +++ b/test/sharness/t0121-bootstrap-iptb.sh @@ -17,19 +17,6 @@ test_expect_success "disable mdns" ' test_launch_ipfs_daemon -export IPTB_ROOT="`pwd`/.iptb" - -ipfsi() { - dir="$1" - shift - IPFS_PATH="$IPTB_ROOT/$dir" ipfs $@ -} - -check_has_connection() { - node=$1 - ipfsi $node swarm peers | grep ipfs > /dev/null -} - test_expect_success "setup iptb nodes" ' iptb init -n 5 -f --bootstrap=none --port=0 ' diff --git a/test/sharness/t0130-multinode.sh b/test/sharness/t0130-multinode.sh index fa9b9d91c..6024d3b0e 100755 --- a/test/sharness/t0130-multinode.sh +++ b/test/sharness/t0130-multinode.sh @@ -8,37 +8,6 @@ test_description="Test multiple ipfs nodes" . lib/test-lib.sh -export IPTB_ROOT="`pwd`/.iptb" - -ipfsi() { - dir="$1" - shift - IPFS_PATH="$IPTB_ROOT/$dir" ipfs $@ -} - -check_has_connection() { - node=$1 - ipfsi $node swarm peers | grep ipfs > /dev/null -} - -startup_cluster() { - test_expect_success "start up nodes" ' - iptb start - ' - - test_expect_success "connect nodes to eachother" ' - iptb connect [1-4] 0 - ' - - test_expect_success "nodes are connected" ' - check_has_connection 0 && - check_has_connection 1 && - check_has_connection 2 && - check_has_connection 3 && - check_has_connection 4 - ' -} - check_file_fetch() { node=$1 fhash=$2 @@ -54,7 +23,7 @@ check_file_fetch() { } run_basic_test() { - startup_cluster + startup_cluster 5 test_expect_success "add a file on node1" ' random 1000000 > filea && diff --git a/test/sharness/t0240-republisher.sh b/test/sharness/t0240-republisher.sh index 71764ae96..54e26cf07 100755 --- a/test/sharness/t0240-republisher.sh +++ b/test/sharness/t0240-republisher.sh @@ -8,15 +8,8 @@ test_description="Test ipfs repo operations" . lib/test-lib.sh -export IPTB_ROOT="`pwd`/.iptb" export DEBUG=true -ipfsi() { - dir="$1" - shift - IPFS_PATH="$IPTB_ROOT/$dir" ipfs "$@" -} - setup_iptb() { test_expect_success "iptb init" ' iptb init -n4 --bootstrap none --port 0