From 04482cbe41b440676230f1c20482496ae6c5c59e Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Mon, 7 Sep 2015 14:14:50 -0700 Subject: [PATCH] Consolidated 'resolve' tests License: MIT Signed-off-by: Matt Bell --- test/sharness/t0101-resolve.sh | 55 -------------------------------- test/sharness/t0160-resolve.sh | 57 +++++++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 67 deletions(-) delete mode 100755 test/sharness/t0101-resolve.sh diff --git a/test/sharness/t0101-resolve.sh b/test/sharness/t0101-resolve.sh deleted file mode 100755 index d4f51ab2b..000000000 --- a/test/sharness/t0101-resolve.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/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="\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 diff --git a/test/sharness/t0160-resolve.sh b/test/sharness/t0160-resolve.sh index 56df66a5d..02b457c54 100755 --- a/test/sharness/t0160-resolve.sh +++ b/test/sharness/t0160-resolve.sh @@ -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="") && - 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="") && + 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="") && + 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