2017-04-18 22:22:05 +00:00
|
|
|
# Sharness test framework for ipfs-cluster
|
|
|
|
#
|
|
|
|
# We are using sharness (https://github.com/mlafeldt/sharness)
|
|
|
|
# which was extracted from the Git test framework.
|
|
|
|
|
|
|
|
SHARNESS_LIB="lib/sharness/sharness.sh"
|
|
|
|
|
2017-07-03 18:02:27 +00:00
|
|
|
# Daemons output will be redirected to...
|
|
|
|
IPFS_OUTPUT="/dev/null" # change for debugging
|
|
|
|
# IPFS_OUTPUT="/dev/stderr" # change for debugging
|
|
|
|
|
2017-04-18 22:22:05 +00:00
|
|
|
. "$SHARNESS_LIB" || {
|
|
|
|
echo >&2 "Cannot source: $SHARNESS_LIB"
|
|
|
|
echo >&2 "Please check Sharness installation."
|
|
|
|
exit 1
|
|
|
|
}
|
2017-04-28 18:01:48 +00:00
|
|
|
|
2017-07-03 18:02:27 +00:00
|
|
|
which jq >/dev/null 2>&1
|
|
|
|
if [ $? -eq 0 ]; then
|
2017-05-02 23:34:06 +00:00
|
|
|
test_set_prereq JQ
|
|
|
|
fi
|
|
|
|
|
2017-05-05 16:09:36 +00:00
|
|
|
# Set prereqs
|
2017-05-02 20:32:42 +00:00
|
|
|
test_ipfs_init() {
|
2017-07-03 18:02:27 +00:00
|
|
|
which docker >/dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Docker not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if docker ps --format '{{.Names}}' | egrep -q '^ipfs$'; then
|
|
|
|
echo "ipfs container already running"
|
|
|
|
else
|
|
|
|
docker run --name ipfs -d -p 127.0.0.1:5001:5001 ipfs/go-ipfs > /dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error running go-ipfs in docker."
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-08-01 11:50:32 +00:00
|
|
|
sleep 10
|
2017-07-03 18:02:27 +00:00
|
|
|
fi
|
2017-05-04 22:33:12 +00:00
|
|
|
test_set_prereq IPFS
|
2017-05-02 20:32:42 +00:00
|
|
|
}
|
|
|
|
|
2017-07-03 18:02:27 +00:00
|
|
|
test_ipfs_running() {
|
|
|
|
if curl -s "localhost:5001/api/v0/version" > /dev/null; then
|
|
|
|
test_set_prereq IPFS
|
|
|
|
else
|
|
|
|
echo "IPFS is not running"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-05-02 20:32:42 +00:00
|
|
|
test_cluster_init() {
|
2017-07-28 18:30:10 +00:00
|
|
|
custom_config_files="$1"
|
|
|
|
|
2017-07-03 18:02:27 +00:00
|
|
|
which ipfs-cluster-service >/dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ipfs-cluster-service not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
which ipfs-cluster-ctl >/dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ipfs-cluster-ctl not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-08-01 11:50:32 +00:00
|
|
|
ipfs-cluster-service -f --config "test-config" init >"$IPFS_OUTPUT" 2>&1
|
2017-07-03 18:02:27 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "error initializing ipfs cluster"
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-07-29 16:54:38 +00:00
|
|
|
if [ -n "$custom_config_files" ]; then
|
2017-08-01 11:50:32 +00:00
|
|
|
cp -f ${custom_config_files}/* "test-config"
|
2017-07-28 18:30:10 +00:00
|
|
|
fi
|
2017-08-01 11:50:32 +00:00
|
|
|
ipfs-cluster-service --config "test-config" >"$IPFS_OUTPUT" 2>&1 &
|
2017-07-03 18:02:27 +00:00
|
|
|
export CLUSTER_D_PID=$!
|
|
|
|
sleep 5
|
2017-05-04 22:33:12 +00:00
|
|
|
test_set_prereq CLUSTER
|
2017-05-02 20:32:42 +00:00
|
|
|
}
|
|
|
|
|
2017-05-02 23:34:06 +00:00
|
|
|
test_cluster_config() {
|
2017-08-01 11:50:32 +00:00
|
|
|
export CLUSTER_CONFIG_PATH="test-config/service.json"
|
2017-07-03 18:02:27 +00:00
|
|
|
export CLUSTER_CONFIG_ID=`jq --raw-output ".id" $CLUSTER_CONFIG_PATH`
|
|
|
|
export CLUSTER_CONFIG_PK=`jq --raw-output ".private_key" $CLUSTER_CONFIG_PATH`
|
|
|
|
[ "$CLUSTER_CONFIG_ID" != "null" ] && [ "$CLUSTER_CONFIG_PK" != "null" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
cluster_id() {
|
2017-08-01 12:25:20 +00:00
|
|
|
jq --raw-output ".id" test-config/service.json
|
2017-05-02 23:34:06 +00:00
|
|
|
}
|
2017-05-02 20:32:42 +00:00
|
|
|
|
|
|
|
# Cleanup functions
|
|
|
|
test_clean_ipfs(){
|
2017-07-03 18:02:27 +00:00
|
|
|
docker kill ipfs
|
|
|
|
docker rm ipfs
|
|
|
|
sleep 1
|
2017-05-02 20:32:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_clean_cluster(){
|
2017-07-03 18:02:27 +00:00
|
|
|
kill -1 "$CLUSTER_D_PID"
|
2017-08-01 11:50:32 +00:00
|
|
|
rm -rf test-config
|
2017-08-01 12:25:20 +00:00
|
|
|
sleep 2
|
2017-05-02 20:32:42 +00:00
|
|
|
}
|