add tests for and fix {set/append}-data
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Jan 5, 2016 at 03:59 UTC
a99ad8a411a9b4ee7b7017c1ac0f2cc087126200
2 files changed
+46
-4
core/commands/object/patch.go
+24
-3
@@ -79,7 +79,13 @@ the limit will not be respected by the network.
79
return
80
}
81
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)
89
if err != nil {
90
res.SetError(err, cmds.ErrNormal)
91
return
@@ -102,7 +108,16 @@ the limit will not be respected by the network.
108
}
109
110
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
+ },
121
Arguments: []cmds.Argument{
122
cmds.StringArg("root", true, false, "the hash of the node to modify"),
123
cmds.FileArg("data", true, false, "data fill with").EnableStdin(),
@@ -126,7 +141,13 @@ var patchSetDataCmd = &cmds.Command{
141
return
142
}
143
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)
151
if err != nil {
152
res.SetError(err, cmds.ErrNormal)
153
return
test/sharness/t0051-object.sh
+22
-1
@@ -241,7 +241,28 @@ test_object_cmd() {
241
test_patch_create_path $BLANK a $FILE
242
243
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
266
'
267
}
268