Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a90e5cc

Browse files
committedJan 5, 2016
add tests for and fix {set/append}-data
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent 1c1f9c6 commit a90e5cc

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed
 

‎core/commands/object/patch.go

+24-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ the limit will not be respected by the network.
7979
return
8080
}
8181

82-
data, err := ioutil.ReadAll(req.Files())
82+
fi, err := req.Files().NextFile()
83+
if err != nil {
84+
res.SetError(err, cmds.ErrNormal)
85+
return
86+
}
87+
88+
data, err := ioutil.ReadAll(fi)
8389
if err != nil {
8490
res.SetError(err, cmds.ErrNormal)
8591
return
@@ -102,7 +108,16 @@ the limit will not be respected by the network.
102108
}
103109

104110
var patchSetDataCmd = &cmds.Command{
105-
Helptext: cmds.HelpText{},
111+
Helptext: cmds.HelpText{
112+
Tagline: "set data field of an ipfs object",
113+
ShortDescription: `
114+
Set the data of an ipfs object from stdin or with the contents of a file
115+
116+
EXAMPLE:
117+
118+
$ echo "my data" | ipfs object patch $MYHASH set-data
119+
`,
120+
},
106121
Arguments: []cmds.Argument{
107122
cmds.StringArg("root", true, false, "the hash of the node to modify"),
108123
cmds.FileArg("data", true, false, "data fill with").EnableStdin(),
@@ -126,7 +141,13 @@ var patchSetDataCmd = &cmds.Command{
126141
return
127142
}
128143

129-
data, err := ioutil.ReadAll(req.Files())
144+
fi, err := req.Files().NextFile()
145+
if err != nil {
146+
res.SetError(err, cmds.ErrNormal)
147+
return
148+
}
149+
150+
data, err := ioutil.ReadAll(fi)
130151
if err != nil {
131152
res.SetError(err, cmds.ErrNormal)
132153
return

‎test/sharness/t0051-object.sh

+22-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,28 @@ test_object_cmd() {
241241
test_patch_create_path $BLANK a $FILE
242242

243243
test_expect_success "create bad path fails" '
244-
test_must_fail ipfs object patch --create $EMPTY add-link / $FILE
244+
test_must_fail ipfs object patch $EMPTY add-link --create / $FILE
245+
'
246+
247+
test_expect_success "patch set-data works" '
248+
EMPTY=$(ipfs object new) &&
249+
HASH=$(printf "foo" | ipfs object patch $EMPTY set-data)
250+
'
251+
252+
test_expect_success "output looks good" '
253+
echo "{\"Links\":[],\"Data\":\"foo\"}" > exp_data_set &&
254+
ipfs object get $HASH > actual_data_set &&
255+
test_cmp exp_data_set actual_data_set
256+
'
257+
258+
test_expect_success "patch append-data works" '
259+
HASH=$(printf "bar" | ipfs object patch $HASH append-data)
260+
'
261+
262+
test_expect_success "output looks good" '
263+
echo "{\"Links\":[],\"Data\":\"foobar\"}" > exp_data_append &&
264+
ipfs object get $HASH > actual_data_append &&
265+
test_cmp exp_data_append actual_data_append
245266
'
246267
}
247268

0 commit comments

Comments
 (0)
Please sign in to comment.