more tests and better path handling in object
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Jul 22, 2015 at 09:46 UTC
194eb7c0dc36aff31ed0f66dcf3b32bd1c982d8c
2 files changed
+31
-8
core/commands/object.go
+10
-2
@@ -469,9 +469,13 @@ resulting object hash.
469
return
470
}
471
472
- rhash := key.B58KeyDecode(req.Arguments()[0])
472
+ rootarg := req.Arguments()[0]
473
+ if strings.HasPrefix(rootarg, "/ipfs/") {
474
+ rootarg = rootarg[6:]
475
+ }
476
+ rhash := key.B58KeyDecode(rootarg)
477
if rhash == "" {
474
- res.SetError(fmt.Errorf("incorrectly formatted root hash"), cmds.ErrNormal)
478
+ res.SetError(fmt.Errorf("incorrectly formatted root hash: %s", req.Arguments()[0]), cmds.ErrNormal)
479
return
480
}
481
@@ -665,6 +669,10 @@ func addLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
669
}
670
671
func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname string, childk key.Key) (*dag.Node, error) {
672
+ if childname == "" {
673
+ return nil, errors.New("cannot create link with no name!")
674
+ }
675
+
676
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
677
defer cancel()
678
childnd, err := ds.Get(ctx, childk)
test/sharness/t0051-object.sh
+21
-6
@@ -10,6 +10,22 @@ test_description="Test object command"
10
11
test_init_ipfs
12
13
+test_patch_create_path() {
14
+ root=$1
15
+ name=$2
16
+ target=$3
17
+
18
+ test_expect_success "object patch --create works" '
19
+ PCOUT=$(ipfs object patch --create $root add-link $name $target)
20
+ '
21
+
22
+ test_expect_success "output looks good" '
23
+ ipfs cat $PCOUT/$name > tpcp_out &&
24
+ ipfs cat $target > tpcp_exp &&
25
+ test_cmp tpcp_out tpcp_exp
26
+ '
27
+}
28
+
29
test_object_cmd() {
30
31
test_expect_success "'ipfs add testData' succeeds" '
@@ -155,13 +171,12 @@ test_object_cmd() {
171
test_cmp multi_link_rm_out multi_link_rm_exp
172
'
173
158
- test_expect_success "object patch --create works" '
159
- OUT=$(ipfs object patch --create $EMPTY add-link a/b/c $FILE)
160
- '
174
+ test_patch_create_path $EMPTY a/b/c $FILE
175
+ test_patch_create_path $EMPTY a $FILE
176
+ test_patch_create_path $EMPTY a/b/b/b/b $FILE
177
162
- test_expect_success "result looks good" '
163
- ipfs cat $OUT/a/b/c > p2_hwfile &&
164
- test_cmp hwfile p2_hwfile
178
+ test_expect_success "create bad path fails" '
179
+ test_must_fail ipfs object patch --create $EMPTY add-link / $FILE
180
'
181
}
182