Commit 04482cbe authored by Matt Bell's avatar Matt Bell Committed by rht

Consolidated 'resolve' tests

License: MIT
Signed-off-by: default avatarMatt Bell <mappum@gmail.com>
parent dd8267b9
#!/bin/sh
#
# Copyright (c) 2015 Matt Bell
# MIT Licensed; see the LICENSE file in this repository.
#
test_description="Test ipfs resolve operations"
. lib/test-lib.sh
test_init_ipfs
# setup
test_expect_success "setup: add files" '
mkdir mountdir/foodir &&
echo "Hello Mars!" >mountdir/foodir/mars.txt &&
echo "/ipfs/`ipfs add -q mountdir/foodir/mars.txt`" >filehash &&
ipfs add -q -r mountdir/foodir | tail -n 1 >dirhash
'
test_expect_success "setup: get IPFS ID" '
ID=`ipfs id --format="<id>\n"`
'
# resolve an IPNS name to a simple /ipfs/ path
test_expect_success "setup: publish file to IPNS name" '
ipfs name publish `cat filehash`
'
test_expect_success "'ipfs resolve' succeeds with IPNS->path" '
echo `ipfs resolve "/ipns/$ID"` >actual
'
test_expect_success "'ipfs resolve' output looks good" '
test_cmp filehash actual
'
# resolve an IPNS name to a /ipfs/HASH/link/name path
test_expect_success "setup: publish link path to IPNS name" '
ipfs name publish "`cat dirhash`/mars.txt"
'
test_expect_success "'ipfs resolve' succeeds with IPNS->link path" '
echo `ipfs resolve "/ipns/$ID"` >actual
'
test_expect_success "'ipfs resolve' output looks good" '
test_cmp filehash actual
'
test_done
......@@ -14,20 +14,36 @@ test_expect_success "resolve: prepare files" '
c_hash=$(ipfs add -q -r a/b/c | tail -n1)
'
test_expect_success "resolve: prepare name" '
id_hash=$(ipfs id -f="<id>") &&
ipfs name publish "$a_hash" &&
printf "/ipfs/$a_hash" >expected_nameval &&
ipfs name resolve >actual_nameval &&
test_cmp expected_nameval actual_nameval
'
test_resolve_setup_name() {
ref=$1
test_expect_success "resolve: prepare name" '
id_hash=$(ipfs id -f="<id>") &&
ipfs name publish "$ref" &&
printf "$ref" >expected_nameval &&
ipfs name resolve >actual_nameval &&
test_cmp expected_nameval actual_nameval
'
}
test_resolve_setup_name_fail() {
ref=$1
test_expect_failure "resolve: prepare name" '
id_hash=$(ipfs id -f="<id>") &&
ipfs name publish "$ref" &&
printf "$ref" >expected_nameval &&
ipfs name resolve >actual_nameval &&
test_cmp expected_nameval actual_nameval
'
}
test_resolve() {
src=$1
dst=$2
test_expect_success "resolve succeeds: $src" '
ipfs resolve "$src" >actual
ipfs resolve -r "$src" >actual
'
test_expect_success "resolved correctly: $src -> $dst" '
......@@ -41,10 +57,19 @@ test_resolve_cmd() {
test_resolve "/ipfs/$a_hash" "/ipfs/$a_hash"
test_resolve "/ipfs/$a_hash/b" "/ipfs/$b_hash"
test_resolve "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
test_resolve "/ipfs/$b_hash/c" "/ipfs/$c_hash"
test_resolve_setup_name "/ipfs/$a_hash"
test_resolve "/ipns/$id_hash" "/ipfs/$a_hash"
test_resolve "/ipns/$id_hash/b" "/ipfs/$b_hash"
test_resolve "/ipns/$id_hash/b/c" "/ipfs/$c_hash"
test_resolve_setup_name "/ipfs/$b_hash"
test_resolve "/ipns/$id_hash" "/ipfs/$b_hash"
test_resolve "/ipns/$id_hash/c" "/ipfs/$c_hash"
test_resolve_setup_name "/ipfs/$c_hash"
test_resolve "/ipns/$id_hash" "/ipfs/$c_hash"
}
#todo remove this once the online resolve is fixed
......@@ -63,14 +88,22 @@ test_resolve_fail() {
}
test_resolve_cmd_fail() {
test_resolve "/ipfs/$a_hash" "/ipfs/$a_hash"
test_resolve "/ipfs/$a_hash/b" "/ipfs/$b_hash"
test_resolve "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
test_resolve "/ipfs/$b_hash/c" "/ipfs/$c_hash"
test_resolve_fail "/ipfs/$a_hash" "/ipfs/$a_hash"
test_resolve_fail "/ipfs/$a_hash/b" "/ipfs/$b_hash"
test_resolve_fail "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
test_resolve_setup_name_fail "/ipfs/$a_hash"
test_resolve_fail "/ipns/$id_hash" "/ipfs/$a_hash"
test_resolve_fail "/ipns/$id_hash/b" "/ipfs/$b_hash"
test_resolve_fail "/ipns/$id_hash/b/c" "/ipfs/$c_hash"
test_resolve_setup_name_fail "/ipfs/$b_hash"
test_resolve_fail "/ipns/$id_hash" "/ipfs/$b_hash"
test_resolve_fail "/ipns/$id_hash/c" "/ipfs/$c_hash"
test_resolve_setup_name_fail "/ipfs/$c_hash"
test_resolve_fail "/ipns/$id_hash" "/ipfs/$c_hash"
}
# should work offline
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment