@cryptotaxi247 / kubo / commits / 04482cbe4

Consolidated 'resolve' tests

License: MIT Signed-off-by: Matt Bell <mappum@gmail.com>

Matt Bell committed Sep 7, 2015 at 14:14 UTC 04482cbe41b440676230f1c20482496ae6c5c59e
2 files changed +45 -67
test/sharness/t0101-resolve.sh deleted
-55
@@ -1,55 +0,0 @@
1 -#!/bin/sh
2 -#
3 -# Copyright (c) 2015 Matt Bell
4 -# MIT Licensed; see the LICENSE file in this repository.
5 -#
6 -
7 -test_description="Test ipfs resolve operations"
8 -
9 -. lib/test-lib.sh
10 -
11 -test_init_ipfs
12 -
13 -# setup
14 -
15 -test_expect_success "setup: add files" '
16 - mkdir mountdir/foodir &&
17 - echo "Hello Mars!" >mountdir/foodir/mars.txt &&
18 - echo "/ipfs/`ipfs add -q mountdir/foodir/mars.txt`" >filehash &&
19 - ipfs add -q -r mountdir/foodir | tail -n 1 >dirhash
20 -'
21 -
22 -test_expect_success "setup: get IPFS ID" '
23 - ID=`ipfs id --format="<id>\n"`
24 -'
25 -
26 -# resolve an IPNS name to a simple /ipfs/ path
27 -
28 -test_expect_success "setup: publish file to IPNS name" '
29 - ipfs name publish `cat filehash`
30 -'
31 -
32 -test_expect_success "'ipfs resolve' succeeds with IPNS->path" '
33 - echo `ipfs resolve "/ipns/$ID"` >actual
34 -'
35 -
36 -test_expect_success "'ipfs resolve' output looks good" '
37 - test_cmp filehash actual
38 -'
39 -
40 -# resolve an IPNS name to a /ipfs/HASH/link/name path
41 -
42 -test_expect_success "setup: publish link path to IPNS name" '
43 - ipfs name publish "`cat dirhash`/mars.txt"
44 -'
45 -
46 -test_expect_success "'ipfs resolve' succeeds with IPNS->link path" '
47 - echo `ipfs resolve "/ipns/$ID"` >actual
48 -'
49 -
50 -test_expect_success "'ipfs resolve' output looks good" '
51 - test_cmp filehash actual
52 -'
53 -
54 -
55 -test_done
test/sharness/t0160-resolve.sh
+45 -12
@@ -14,20 +14,36 @@ test_expect_success "resolve: prepare files" '
14 c_hash=$(ipfs add -q -r a/b/c | tail -n1)
15 '
16
17 -test_expect_success "resolve: prepare name" '
18 - id_hash=$(ipfs id -f="<id>") &&
19 - ipfs name publish "$a_hash" &&
20 - printf "/ipfs/$a_hash" >expected_nameval &&
21 - ipfs name resolve >actual_nameval &&
22 - test_cmp expected_nameval actual_nameval
23 -'
17 +test_resolve_setup_name() {
18 + ref=$1
19 +
20 + test_expect_success "resolve: prepare name" '
21 + id_hash=$(ipfs id -f="<id>") &&
22 + ipfs name publish "$ref" &&
23 + printf "$ref" >expected_nameval &&
24 + ipfs name resolve >actual_nameval &&
25 + test_cmp expected_nameval actual_nameval
26 + '
27 +}
28 +
29 +test_resolve_setup_name_fail() {
30 + ref=$1
31 +
32 + test_expect_failure "resolve: prepare name" '
33 + id_hash=$(ipfs id -f="<id>") &&
34 + ipfs name publish "$ref" &&
35 + printf "$ref" >expected_nameval &&
36 + ipfs name resolve >actual_nameval &&
37 + test_cmp expected_nameval actual_nameval
38 + '
39 +}
40
41 test_resolve() {
42 src=$1
43 dst=$2
44
45 test_expect_success "resolve succeeds: $src" '
30 - ipfs resolve "$src" >actual
46 + ipfs resolve -r "$src" >actual
47 '
48
49 test_expect_success "resolved correctly: $src -> $dst" '
@@ -41,10 +57,19 @@ test_resolve_cmd() {
57 test_resolve "/ipfs/$a_hash" "/ipfs/$a_hash"
58 test_resolve "/ipfs/$a_hash/b" "/ipfs/$b_hash"
59 test_resolve "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
60 + test_resolve "/ipfs/$b_hash/c" "/ipfs/$c_hash"
61
62 + test_resolve_setup_name "/ipfs/$a_hash"
63 test_resolve "/ipns/$id_hash" "/ipfs/$a_hash"
64 test_resolve "/ipns/$id_hash/b" "/ipfs/$b_hash"
65 test_resolve "/ipns/$id_hash/b/c" "/ipfs/$c_hash"
66 +
67 + test_resolve_setup_name "/ipfs/$b_hash"
68 + test_resolve "/ipns/$id_hash" "/ipfs/$b_hash"
69 + test_resolve "/ipns/$id_hash/c" "/ipfs/$c_hash"
70 +
71 + test_resolve_setup_name "/ipfs/$c_hash"
72 + test_resolve "/ipns/$id_hash" "/ipfs/$c_hash"
73 }
74
75 #todo remove this once the online resolve is fixed
@@ -63,14 +88,22 @@ test_resolve_fail() {
88 }
89
90 test_resolve_cmd_fail() {
91 + test_resolve "/ipfs/$a_hash" "/ipfs/$a_hash"
92 + test_resolve "/ipfs/$a_hash/b" "/ipfs/$b_hash"
93 + test_resolve "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
94 + test_resolve "/ipfs/$b_hash/c" "/ipfs/$c_hash"
95
67 - test_resolve_fail "/ipfs/$a_hash" "/ipfs/$a_hash"
68 - test_resolve_fail "/ipfs/$a_hash/b" "/ipfs/$b_hash"
69 - test_resolve_fail "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
70 -
96 + test_resolve_setup_name_fail "/ipfs/$a_hash"
97 test_resolve_fail "/ipns/$id_hash" "/ipfs/$a_hash"
98 test_resolve_fail "/ipns/$id_hash/b" "/ipfs/$b_hash"
99 test_resolve_fail "/ipns/$id_hash/b/c" "/ipfs/$c_hash"
100 +
101 + test_resolve_setup_name_fail "/ipfs/$b_hash"
102 + test_resolve_fail "/ipns/$id_hash" "/ipfs/$b_hash"
103 + test_resolve_fail "/ipns/$id_hash/c" "/ipfs/$c_hash"
104 +
105 + test_resolve_setup_name_fail "/ipfs/$c_hash"
106 + test_resolve_fail "/ipns/$id_hash" "/ipfs/$c_hash"
107 }
108
109 # should work offline