iptb-lib.sh 746 Bytes
Newer Older
1 2 3 4 5
# iptb test framework 
#
# Copyright (c) 2014, 2016 Jeromy Johnson, Christian Couder
# MIT Licensed; see the LICENSE file in this repository.

Christian Couder's avatar
Christian Couder committed
6
export IPTB_ROOT="$(pwd)/.iptb"
7 8 9 10

ipfsi() {
	dir="$1"
	shift
Christian Couder's avatar
Christian Couder committed
11
	IPFS_PATH="$IPTB_ROOT/$dir" ipfs "$@"
12 13 14
}

check_has_connection() {
Christian Couder's avatar
Christian Couder committed
15 16 17
	node="$1"
	ipfsi "$node" swarm peers >"swarm_peers_$node" &&
	grep "ipfs" "swarm_peers_$node" >/dev/null
18 19
}

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
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
}