Skip to content

Commit

Permalink
Merge pull request #1692 from ipfs/generalize-peerid-check
Browse files Browse the repository at this point in the history
Generalize peerid check
  • Loading branch information
jbenet committed Sep 13, 2015
2 parents 65507cb + 6e59b39 commit a8dc708
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
9 changes: 9 additions & 0 deletions test/sharness/lib/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

4 changes: 0 additions & 4 deletions test/sharness/t0020-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 2 additions & 7 deletions test/sharness/t0060-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion test/sharness/t0062-daemon-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 3 additions & 0 deletions test/sharness/t0100-name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ test_init_ipfs

test_expect_success "'ipfs name publish' succeeds" '
PEERID=`ipfs id --format="<id>"` &&
test_check_peerid "${PEERID}" &&
ipfs name publish "/ipfs/$HASH_WELCOME_DOCS" >publish_out
'

Expand All @@ -35,6 +36,7 @@ test_expect_success "resolve output looks good" '

test_expect_success "'ipfs name publish' succeeds" '
PEERID=`ipfs id --format="<id>"` &&
test_check_peerid "${PEERID}" &&
ipfs name publish "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out
'

Expand All @@ -56,6 +58,7 @@ test_expect_success "resolve output looks good" '

test_expect_success "'ipfs name publish <local-id> <hash>' succeeds" '
PEERID=`ipfs id --format="<id>"` &&
test_check_peerid "${PEERID}" &&
ipfs name publish "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish
'

Expand Down
5 changes: 3 additions & 2 deletions test/sharness/t0110-gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" '
Expand Down

0 comments on commit a8dc708

Please sign in to comment.