iptb-lib.sh 917 Bytes
Newer Older
Stephen Whitmore's avatar
Stephen Whitmore committed
1
# iptb test framework
2 3 4 5
#
# 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
startup_cluster() {
	num_nodes="$1"
22 23
	shift
	other_args="$@"
24
	bound=$(expr "$num_nodes" - 1)
25

26 27 28
	if test -n "$other_args"; then
		test_expect_success "start up nodes with additional args" '
			iptb start --args $other_args
Jan Winkelmann's avatar
Jan Winkelmann committed
29 30 31 32 33 34
		'
	else
		test_expect_success "start up nodes" '
			iptb start
		'
	fi
35 36 37 38 39

	test_expect_success "connect nodes to eachother" '
		iptb connect [1-$bound] 0
	'

40
	for i in $(test_seq 0 "$bound")
41 42 43 44 45 46 47
	do
		test_expect_success "node $i is connected" '
			check_has_connection "$i" ||
			test_fsh cat "swarm_peers_$i"
		'
	done
}