Merge pull request #2275 from ipfs/refactor-iptb-tests

Refactor iptb tests
This commit is contained in:
Jeromy Johnson 2016-02-02 08:44:57 -08:00
commit 585ef2b957
6 changed files with 43 additions and 86 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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" '

View File

@ -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
'

View File

@ -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 &&

View File

@ -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