提交 a99ad8a4 作者: Jeromy

add tests for and fix {set/append}-data

License: MIT
Signed-off-by: 's avatarJeromy <jeromyj@gmail.com>
上级 4dca1f24
......@@ -79,7 +79,13 @@ the limit will not be respected by the network.
return
}
data, err := ioutil.ReadAll(req.Files())
fi, err := req.Files().NextFile()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
data, err := ioutil.ReadAll(fi)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
......@@ -102,7 +108,16 @@ the limit will not be respected by the network.
}
var patchSetDataCmd = &cmds.Command{
Helptext: cmds.HelpText{},
Helptext: cmds.HelpText{
Tagline: "set data field of an ipfs object",
ShortDescription: `
Set the data of an ipfs object from stdin or with the contents of a file
EXAMPLE:
$ echo "my data" | ipfs object patch $MYHASH set-data
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("root", true, false, "the hash of the node to modify"),
cmds.FileArg("data", true, false, "data fill with").EnableStdin(),
......@@ -126,7 +141,13 @@ var patchSetDataCmd = &cmds.Command{
return
}
data, err := ioutil.ReadAll(req.Files())
fi, err := req.Files().NextFile()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
data, err := ioutil.ReadAll(fi)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
......
......@@ -241,7 +241,28 @@ test_object_cmd() {
test_patch_create_path $BLANK a $FILE
test_expect_success "create bad path fails" '
test_must_fail ipfs object patch --create $EMPTY add-link / $FILE
test_must_fail ipfs object patch $EMPTY add-link --create / $FILE
'
test_expect_success "patch set-data works" '
EMPTY=$(ipfs object new) &&
HASH=$(printf "foo" | ipfs object patch $EMPTY set-data)
'
test_expect_success "output looks good" '
echo "{\"Links\":[],\"Data\":\"foo\"}" > exp_data_set &&
ipfs object get $HASH > actual_data_set &&
test_cmp exp_data_set actual_data_set
'
test_expect_success "patch append-data works" '
HASH=$(printf "bar" | ipfs object patch $HASH append-data)
'
test_expect_success "output looks good" '
echo "{\"Links\":[],\"Data\":\"foobar\"}" > exp_data_append &&
ipfs object get $HASH > actual_data_append &&
test_cmp exp_data_append actual_data_append
'
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论