Sharness hardening:

Better error messages in test-lib init functions and ipfshttp
Cleanup functions are now called after every test file

License: MIT
Signed-off-by: Wyatt Daviau <wdaviau@cs.stanford.edu>
This commit is contained in:
Wyatt Daviau 2018-01-09 14:17:21 -05:00
parent abebe498cb
commit a99b403273
14 changed files with 41 additions and 28 deletions

View File

@ -688,7 +688,7 @@ func (ipfs *Connector) post(path string) ([]byte, error) {
res, err := http.Post(url, "", nil) res, err := http.Post(url, "", nil)
if err != nil { if err != nil {
logger.Error("error getting:", err) logger.Error("error posting:", err)
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()

View File

@ -32,7 +32,7 @@ test_ipfs_init() {
else else
docker run --name ipfs -d -p 127.0.0.1:5001:5001 ipfs/go-ipfs > /dev/null 2>&1 docker run --name ipfs -d -p 127.0.0.1:5001:5001 ipfs/go-ipfs > /dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Error running go-ipfs in docker." echo "IPFS init FAIL: Error running go-ipfs in docker."
exit 1 exit 1
fi fi
while ! curl -s "localhost:5001/api/v0/version" > /dev/null; do while ! curl -s "localhost:5001/api/v0/version" > /dev/null; do
@ -57,17 +57,17 @@ test_cluster_init() {
which ipfs-cluster-service >/dev/null 2>&1 which ipfs-cluster-service >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ipfs-cluster-service not found" echo "cluster init FAIL: ipfs-cluster-service not found"
exit 1 exit 1
fi fi
which ipfs-cluster-ctl >/dev/null 2>&1 which ipfs-cluster-ctl >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ipfs-cluster-ctl not found" echo "cluster init FAIL: ipfs-cluster-ctl not found"
exit 1 exit 1
fi fi
ipfs-cluster-service -f --config "test-config" init >"$IPFS_OUTPUT" 2>&1 ipfs-cluster-service -f --config "test-config" init >"$IPFS_OUTPUT" 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "error initializing ipfs cluster" echo "cluster init FAIL: error on ipfs cluster init"
exit 1 exit 1
fi fi
rm -rf "test-config/ipfs-cluster-data" rm -rf "test-config/ipfs-cluster-data"

View File

@ -4,9 +4,7 @@ test_description="Test service startup and init functionality"
. lib/test-lib.sh . lib/test-lib.sh
test_ipfs_init test_ipfs_init
cleanup test_clean_ipfs
test_cluster_init test_cluster_init
cleanup test_clean_cluster
test_expect_success "prerequisites" ' test_expect_success "prerequisites" '
test_have_prereq IPFS && test_have_prereq IPFS &&
@ -31,4 +29,7 @@ test_expect_success "starting a second cluster-service process fails" '
test_expect_code 1 ipfs-cluster-service --config "test-config" test_expect_code 1 ipfs-cluster-service --config "test-config"
' '
test_clean_ipfs
test_clean_cluster
test_done test_done

View File

@ -5,9 +5,7 @@ test_description="Test ctl's status reporting functionality. Test errors on inc
. lib/test-lib.sh . lib/test-lib.sh
test_ipfs_init test_ipfs_init
cleanup test_clean_ipfs
test_cluster_init test_cluster_init
cleanup test_clean_cluster
test_expect_success IPFS,CLUSTER,JQ "cluster-ctl can read id" ' test_expect_success IPFS,CLUSTER,JQ "cluster-ctl can read id" '
id=`cluster_id` id=`cluster_id`
@ -59,4 +57,7 @@ test_expect_success IPFS,CLUSTER "pin ls on invalid CID fails" '
test_must_fail ipfs-cluster-ctl pin ls XXXinvalid-CIDXXX test_must_fail ipfs-cluster-ctl pin ls XXXinvalid-CIDXXX
' '
test_clean_ipfs
test_clean_cluster
test_done test_done

View File

@ -5,9 +5,7 @@ test_description="Test cluster-ctl's pinning and unpinning functionality"
. lib/test-lib.sh . lib/test-lib.sh
test_ipfs_init test_ipfs_init
cleanup test_clean_ipfs
test_cluster_init test_cluster_init
cleanup test_clean_cluster
test_expect_success IPFS,CLUSTER "pin data to cluster with ctl" ' test_expect_success IPFS,CLUSTER "pin data to cluster with ctl" '
cid=`docker exec ipfs sh -c "echo test | ipfs add -q"` cid=`docker exec ipfs sh -c "echo test | ipfs add -q"`
@ -23,4 +21,7 @@ test_expect_success IPFS,CLUSTER "unpin data from cluster with ctl" '
ipfs-cluster-ctl status "$cid" | grep -q -i "UNPINNED" ipfs-cluster-ctl status "$cid" | grep -q -i "UNPINNED"
' '
test_clean_ipfs
test_clean_cluster
test_done test_done

View File

@ -7,7 +7,6 @@ ssl_config="`pwd`/config/ssl"
. lib/test-lib.sh . lib/test-lib.sh
test_ipfs_init test_ipfs_init
cleanup test_clean_ipfs
test_cluster_init "$ssl_config" test_cluster_init "$ssl_config"
cleanup test_clean_cluster cleanup test_clean_cluster
@ -21,4 +20,6 @@ test_expect_success "ssl interaction succeeds" '
ipfs-cluster-ctl --https --no-check-certificate id | egrep -q "$id" ipfs-cluster-ctl --https --no-check-certificate id | egrep -q "$id"
' '
test_clean_ipfs
test_done test_done

View File

@ -5,9 +5,7 @@ test_description="Test failure when server not using SSL but client requests it"
. lib/test-lib.sh . lib/test-lib.sh
test_ipfs_init test_ipfs_init
cleanup test_clean_ipfs
test_cluster_init test_cluster_init
cleanup test_clean_cluster
test_expect_success "prerequisites" ' test_expect_success "prerequisites" '
test_have_prereq IPFS && test_have_prereq CLUSTER test_have_prereq IPFS && test_have_prereq CLUSTER
@ -18,4 +16,7 @@ test_expect_success "ssl enforced by client" '
test_must_fail ipfs-cluster-ctl --https --no-check-certificate id test_must_fail ipfs-cluster-ctl --https --no-check-certificate id
' '
test_clean_ipfs
test_clean_cluster
test_done test_done

View File

@ -7,9 +7,7 @@ config="`pwd`/config/basic_auth"
. lib/test-lib.sh . lib/test-lib.sh
test_ipfs_init test_ipfs_init
cleanup test_clean_ipfs
test_cluster_init "$config" test_cluster_init "$config"
cleanup test_clean_cluster
test_expect_success "prerequisites" ' test_expect_success "prerequisites" '
test_have_prereq IPFS && test_have_prereq CLUSTER test_have_prereq IPFS && test_have_prereq CLUSTER
@ -41,4 +39,7 @@ test_expect_success "BasicAuth succeeds with env var credentials" '
ipfs-cluster-ctl --force-http id | egrep -q "$id" ipfs-cluster-ctl --force-http id | egrep -q "$id"
' '
test_clean_ipfs
test_clean_cluster
test_done test_done

View File

@ -7,9 +7,7 @@ config="`pwd`/config/ssl-basic_auth"
. lib/test-lib.sh . lib/test-lib.sh
test_ipfs_init test_ipfs_init
cleanup test_clean_ipfs
test_cluster_init "$config" test_cluster_init "$config"
cleanup test_clean_cluster
test_expect_success "prerequisites" ' test_expect_success "prerequisites" '
test_have_prereq IPFS && test_have_prereq CLUSTER test_have_prereq IPFS && test_have_prereq CLUSTER
@ -26,4 +24,7 @@ test_expect_success "ssl interaction succeeds" '
ipfs-cluster-ctl --no-check-certificate --basic-auth "testuser:testpass" id | egrep -q "$id" ipfs-cluster-ctl --no-check-certificate --basic-auth "testuser:testpass" id | egrep -q "$id"
' '
test_clean_ipfs
test_clean_cluster
test_done test_done

View File

@ -5,9 +5,7 @@ test_description="Test service state 'upgrade' from current version"
. lib/test-lib.sh . lib/test-lib.sh
test_ipfs_init test_ipfs_init
cleanup test_clean_ipfs
test_cluster_init test_cluster_init
cleanup test_clean_cluster
test_expect_success IPFS,CLUSTER "cluster-service state upgrade works" ' test_expect_success IPFS,CLUSTER "cluster-service state upgrade works" '
cid=`docker exec ipfs sh -c "echo testing | ipfs add -q"` && cid=`docker exec ipfs sh -c "echo testing | ipfs add -q"` &&
@ -28,4 +26,7 @@ test_expect_success IPFS,CLUSTER "state is preserved after migration" '
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED" ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED"
' '
test_clean_ipfs
test_clean_cluster
test_done test_done

View File

@ -5,10 +5,8 @@ test_description="Test service state upgrade v1 -> v2 and v2 -> v2"
. lib/test-lib.sh . lib/test-lib.sh
test_ipfs_init test_ipfs_init
cleanup test_clean_ipfs
test_cluster_init test_cluster_init
test_confirm_v1State test_confirm_v1State
cleanup test_clean_cluster
# Make a pin and shutdown to force a snapshot. Modify snapshot files to specify # Make a pin and shutdown to force a snapshot. Modify snapshot files to specify
# a snapshot of v1 state pinning "test" (it's easier than taking a new one each # a snapshot of v1 state pinning "test" (it's easier than taking a new one each
@ -30,4 +28,8 @@ test_expect_success IPFS,CLUSTER,V1STATE,JQ "cluster-service loads v1 state corr
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED" ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED"
' '
test_clean_ipfs
test_clean_cluster
test_done test_done

View File

@ -5,9 +5,7 @@ test_description="Test service state export"
. lib/test-lib.sh . lib/test-lib.sh
test_ipfs_init test_ipfs_init
cleanup test_clean_ipfs
test_cluster_init test_cluster_init
cleanup test_clean_cluster
test_expect_success IPFS,CLUSTER "state export fails without snapshots" ' test_expect_success IPFS,CLUSTER "state export fails without snapshots" '
@ -28,4 +26,7 @@ test_expect_success IPFS,CLUSTER,JQ "state export saves the correct state to exp
jq ".[].cid" export.json | grep -q "$cid" jq ".[].cid" export.json | grep -q "$cid"
' '
test_clean_ipfs
test_clean_cluster
test_done test_done

View File

@ -5,9 +5,7 @@ test_description="Test service state import"
. lib/test-lib.sh . lib/test-lib.sh
test_ipfs_init test_ipfs_init
cleanup test_clean_ipfs
test_cluster_init test_cluster_init
cleanup test_clean_cluster
test_confirm_importState test_confirm_importState
# Kill cluster daemon but keep data folder # Kill cluster daemon but keep data folder
@ -28,4 +26,7 @@ test_expect_success IPFS,CLUSTER,IMPORTSTATE "state import succeeds on correct f
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED" ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED"
' '
test_clean_ipfs
test_clean_cluster
test_done test_done

View File

@ -5,9 +5,7 @@ test_description="Test service state import"
. lib/test-lib.sh . lib/test-lib.sh
test_ipfs_init test_ipfs_init
cleanup test_clean_ipfs
test_cluster_init test_cluster_init
cleanup test_clean_cluster
test_expect_success IPFS,CLUSTER "state cleanup refreshes state on restart" ' test_expect_success IPFS,CLUSTER "state cleanup refreshes state on restart" '
cid=`docker exec ipfs sh -c "echo test_54 | ipfs add -q"` && cid=`docker exec ipfs sh -c "echo test_54 | ipfs add -q"` &&
@ -35,4 +33,7 @@ test_expect_success IPFS,CLUSTER "export + cleanup + import == noop" '
[ 1 -eq "$(ipfs-cluster-ctl --enc=json status | jq ". | length")" ] [ 1 -eq "$(ipfs-cluster-ctl --enc=json status | jq ". | length")" ]
' '
test_clean_ipfs
test_clean_cluster
test_done test_done