From 194eb7c0dc36aff31ed0f66dcf3b32bd1c982d8c Mon Sep 17 00:00:00 2001 From: Jeromy Date: Wed, 22 Jul 2015 09:46:06 -0700 Subject: [PATCH] more tests and better path handling in object License: MIT Signed-off-by: Jeromy --- core/commands/object.go | 12 ++++++++++-- test/sharness/t0051-object.sh | 27 +++++++++++++++++++++------ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/core/commands/object.go b/core/commands/object.go index d123083bb..277c9616e 100644 --- a/core/commands/object.go +++ b/core/commands/object.go @@ -469,9 +469,13 @@ resulting object hash. return } - rhash := key.B58KeyDecode(req.Arguments()[0]) + rootarg := req.Arguments()[0] + if strings.HasPrefix(rootarg, "/ipfs/") { + rootarg = rootarg[6:] + } + rhash := key.B58KeyDecode(rootarg) if rhash == "" { - res.SetError(fmt.Errorf("incorrectly formatted root hash"), cmds.ErrNormal) + res.SetError(fmt.Errorf("incorrectly formatted root hash: %s", req.Arguments()[0]), cmds.ErrNormal) return } @@ -665,6 +669,10 @@ func addLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) { } func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname string, childk key.Key) (*dag.Node, error) { + if childname == "" { + return nil, errors.New("cannot create link with no name!") + } + ctx, cancel := context.WithTimeout(ctx, time.Second*30) defer cancel() childnd, err := ds.Get(ctx, childk) diff --git a/test/sharness/t0051-object.sh b/test/sharness/t0051-object.sh index 2e1d442d5..0b984f783 100755 --- a/test/sharness/t0051-object.sh +++ b/test/sharness/t0051-object.sh @@ -10,6 +10,22 @@ test_description="Test object command" test_init_ipfs +test_patch_create_path() { + root=$1 + name=$2 + target=$3 + + test_expect_success "object patch --create works" ' + PCOUT=$(ipfs object patch --create $root add-link $name $target) + ' + + test_expect_success "output looks good" ' + ipfs cat $PCOUT/$name > tpcp_out && + ipfs cat $target > tpcp_exp && + test_cmp tpcp_out tpcp_exp + ' +} + test_object_cmd() { test_expect_success "'ipfs add testData' succeeds" ' @@ -155,13 +171,12 @@ test_object_cmd() { test_cmp multi_link_rm_out multi_link_rm_exp ' - test_expect_success "object patch --create works" ' - OUT=$(ipfs object patch --create $EMPTY add-link a/b/c $FILE) - ' + test_patch_create_path $EMPTY a/b/c $FILE + test_patch_create_path $EMPTY a $FILE + test_patch_create_path $EMPTY a/b/b/b/b $FILE - test_expect_success "result looks good" ' - ipfs cat $OUT/a/b/c > p2_hwfile && - test_cmp hwfile p2_hwfile + test_expect_success "create bad path fails" ' + test_must_fail ipfs object patch --create $EMPTY add-link / $FILE ' }