diff --git a/test/sharness/lib/test-lib.sh b/test/sharness/lib/test-lib.sh index 1d6866c48..b9a25ae87 100644 --- a/test/sharness/lib/test-lib.sh +++ b/test/sharness/lib/test-lib.sh @@ -344,3 +344,12 @@ generic_stat() { esac $_STAT "$1" } + +test_check_peerid() { + peeridlen=$(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") && + test "$peeridlen" = "46" || { + echo "Bad peerid '$1' with len '$peeridlen'" + return 1 + } +} + diff --git a/test/sharness/t0020-init.sh b/test/sharness/t0020-init.sh index 2a930ea9e..8416502b3 100755 --- a/test/sharness/t0020-init.sh +++ b/test/sharness/t0020-init.sh @@ -58,10 +58,6 @@ test_expect_success "ipfs config succeeds" ' test_cmp expected_config actual_config ' -test_check_peerid() { - test $(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") = "46" -} - test_expect_success "ipfs peer id looks good" ' PEERID=$(ipfs config Identity.PeerID) && test_check_peerid "$PEERID" diff --git a/test/sharness/t0060-daemon.sh b/test/sharness/t0060-daemon.sh index db063d22d..44bb87515 100755 --- a/test/sharness/t0060-daemon.sh +++ b/test/sharness/t0060-daemon.sh @@ -33,20 +33,15 @@ test_expect_success "initialization ended" ' # this errors if daemon didnt --init $IPFS_PATH correctly test_expect_success "'ipfs config Identity.PeerID' works" ' - ipfs config Identity.PeerID >config_peerId + PEERID=$(ipfs config Identity.PeerID) ' test_expect_success "'ipfs swarm addrs local' works" ' ipfs swarm addrs local >local_addrs ' - -# this is lifted straight from t0020-init.sh test_expect_success "ipfs peer id looks good" ' - PEERID=$(cat config_peerId) && - echo $PEERID | tr -dC "[:alnum:]" | wc -c | tr -d " " >actual_id && - echo "46" >expected_id && - test_cmp_repeat_10_sec expected_id actual_id + test_check_peerid "$PEERID" ' # This is like t0020-init.sh "ipfs init output looks good" diff --git a/test/sharness/t0062-daemon-api.sh b/test/sharness/t0062-daemon-api.sh index 9efba6302..db6ca1c27 100755 --- a/test/sharness/t0062-daemon-api.sh +++ b/test/sharness/t0062-daemon-api.sh @@ -15,7 +15,8 @@ api_unreachable="/ip4/127.0.0.1/tcp/1" test_expect_success "config setup" ' api_fromcfg=$(ipfs config Addresses.API) && - peerid=$(ipfs config Identity.PeerID) + peerid=$(ipfs config Identity.PeerID) && + test_check_peerid "$peerid" ' test_client() { diff --git a/test/sharness/t0100-name.sh b/test/sharness/t0100-name.sh index b2ea8f4bc..d782729ca 100755 --- a/test/sharness/t0100-name.sh +++ b/test/sharness/t0100-name.sh @@ -14,6 +14,7 @@ test_init_ipfs test_expect_success "'ipfs name publish' succeeds" ' PEERID=`ipfs id --format=""` && + test_check_peerid "${PEERID}" && ipfs name publish "/ipfs/$HASH_WELCOME_DOCS" >publish_out ' @@ -35,6 +36,7 @@ test_expect_success "resolve output looks good" ' test_expect_success "'ipfs name publish' succeeds" ' PEERID=`ipfs id --format=""` && + test_check_peerid "${PEERID}" && ipfs name publish "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out ' @@ -56,6 +58,7 @@ test_expect_success "resolve output looks good" ' test_expect_success "'ipfs name publish ' succeeds" ' PEERID=`ipfs id --format=""` && + test_check_peerid "${PEERID}" && ipfs name publish "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish ' diff --git a/test/sharness/t0110-gateway.sh b/test/sharness/t0110-gateway.sh index 944137668..c15832088 100755 --- a/test/sharness/t0110-gateway.sh +++ b/test/sharness/t0110-gateway.sh @@ -59,8 +59,9 @@ test_expect_success "GET IPFS non existent file returns code expected (404)" ' test_expect_failure "GET IPNS path succeeds" ' ipfs name publish "$HASH" && - NAME=$(ipfs config Identity.PeerID) && - curl -sfo actual "http://127.0.0.1:$port/ipns/$NAME" + PEERID=$(ipfs config Identity.PeerID) && + test_check_peerid "$PEERID" && + curl -sfo actual "http://127.0.0.1:$port/ipns/$PEERID" ' test_expect_failure "GET IPNS path output looks good" '