From cacb1cc2d4fdb7c7bc844a4653d4947be4fee646 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 1 Feb 2016 13:17:13 +0100 Subject: [PATCH 1/5] sharness: add lib/iptb-lib.sh License: MIT Signed-off-by: Christian Couder --- test/sharness/lib/iptb-lib.sh | 18 ++++++++++++++++++ test/sharness/lib/test-lib.sh | 3 +++ test/sharness/t0101-iptb-name.sh | 13 ------------- 3 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 test/sharness/lib/iptb-lib.sh diff --git a/test/sharness/lib/iptb-lib.sh b/test/sharness/lib/iptb-lib.sh new file mode 100644 index 000000000..5f49fdef4 --- /dev/null +++ b/test/sharness/lib/iptb-lib.sh @@ -0,0 +1,18 @@ +# 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 | grep ipfs > /dev/null +} + 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..21c8987d4 100755 --- a/test/sharness/t0101-iptb-name.sh +++ b/test/sharness/t0101-iptb-name.sh @@ -8,25 +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" ' From d1f15d445b4372b7d2051e72398f4ef511c0090a Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 1 Feb 2016 13:23:51 +0100 Subject: [PATCH 2/5] iptb-lib: small cleanup License: MIT Signed-off-by: Christian Couder --- test/sharness/lib/iptb-lib.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/sharness/lib/iptb-lib.sh b/test/sharness/lib/iptb-lib.sh index 5f49fdef4..6efb4b8c7 100644 --- a/test/sharness/lib/iptb-lib.sh +++ b/test/sharness/lib/iptb-lib.sh @@ -3,16 +3,17 @@ # Copyright (c) 2014, 2016 Jeromy Johnson, Christian Couder # MIT Licensed; see the LICENSE file in this repository. -export IPTB_ROOT="`pwd`/.iptb" +export IPTB_ROOT="$(pwd)/.iptb" ipfsi() { dir="$1" shift - IPFS_PATH="$IPTB_ROOT/$dir" ipfs $@ + IPFS_PATH="$IPTB_ROOT/$dir" ipfs "$@" } check_has_connection() { - node=$1 - ipfsi $node swarm peers | grep ipfs > /dev/null + node="$1" + ipfsi "$node" swarm peers >"swarm_peers_$node" && + grep "ipfs" "swarm_peers_$node" >/dev/null } From 8b875ebe770c3093496b5a58f6003809f6fd64e9 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 1 Feb 2016 13:35:54 +0100 Subject: [PATCH 3/5] t0121, t0130, t0240: use iptb-lib.sh License: MIT Signed-off-by: Christian Couder --- test/sharness/t0121-bootstrap-iptb.sh | 13 ------------- test/sharness/t0130-multinode.sh | 13 ------------- test/sharness/t0240-republisher.sh | 7 ------- 3 files changed, 33 deletions(-) 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..b1d8578e4 100755 --- a/test/sharness/t0130-multinode.sh +++ b/test/sharness/t0130-multinode.sh @@ -8,19 +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 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 From e0a48ffcf6485c73c2cec5e7345c9cc88bfcf1af Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 1 Feb 2016 23:09:54 +0100 Subject: [PATCH 4/5] iptb-lib: add startup_cluster() While at it let's cleanup startup_cluster() too. License: MIT Signed-off-by: Christian Couder --- test/sharness/lib/iptb-lib.sh | 20 ++++++++++++++++++++ test/sharness/t0101-iptb-name.sh | 21 --------------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/test/sharness/lib/iptb-lib.sh b/test/sharness/lib/iptb-lib.sh index 6efb4b8c7..3ba09e791 100644 --- a/test/sharness/lib/iptb-lib.sh +++ b/test/sharness/lib/iptb-lib.sh @@ -17,3 +17,23 @@ check_has_connection() { 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/t0101-iptb-name.sh b/test/sharness/t0101-iptb-name.sh index 21c8987d4..3dbea47da 100755 --- a/test/sharness/t0101-iptb-name.sh +++ b/test/sharness/t0101-iptb-name.sh @@ -14,27 +14,6 @@ test_expect_success "set up an iptb cluster" ' iptb init -n $num_nodes -p 0 -f --bootstrap=none ' -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" ' From 79b6297770c710487b10785ce82adfa87041a3fd Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 1 Feb 2016 23:23:53 +0100 Subject: [PATCH 5/5] t0130: use startup_cluster() from iptb-lib.sh License: MIT Signed-off-by: Christian Couder --- test/sharness/t0130-multinode.sh | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/test/sharness/t0130-multinode.sh b/test/sharness/t0130-multinode.sh index b1d8578e4..6024d3b0e 100755 --- a/test/sharness/t0130-multinode.sh +++ b/test/sharness/t0130-multinode.sh @@ -8,24 +8,6 @@ test_description="Test multiple ipfs nodes" . lib/test-lib.sh -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 @@ -41,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 &&