1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-17 16:37:59 +08:00

more tests and better path handling in object

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
Jeromy
2015-07-22 09:46:06 -07:00
parent bfe4e4be4f
commit 194eb7c0dc
2 changed files with 31 additions and 8 deletions

View File

@ -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)

View File

@ -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
'
}