mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-06 23:28:44 +08:00
more tests and better path handling in object
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
@ -469,9 +469,13 @@ resulting object hash.
|
|||||||
return
|
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 == "" {
|
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
|
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) {
|
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)
|
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
childnd, err := ds.Get(ctx, childk)
|
childnd, err := ds.Get(ctx, childk)
|
||||||
|
@ -10,6 +10,22 @@ test_description="Test object command"
|
|||||||
|
|
||||||
test_init_ipfs
|
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_object_cmd() {
|
||||||
|
|
||||||
test_expect_success "'ipfs add testData' succeeds" '
|
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_cmp multi_link_rm_out multi_link_rm_exp
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success "object patch --create works" '
|
test_patch_create_path $EMPTY a/b/c $FILE
|
||||||
OUT=$(ipfs object patch --create $EMPTY add-link 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" '
|
test_expect_success "create bad path fails" '
|
||||||
ipfs cat $OUT/a/b/c > p2_hwfile &&
|
test_must_fail ipfs object patch --create $EMPTY add-link / $FILE
|
||||||
test_cmp hwfile p2_hwfile
|
|
||||||
'
|
'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user