Skip to content

Commit

Permalink
Merge pull request #2160 from ipfs/fix/patch-data-tests
Browse files Browse the repository at this point in the history
add tests for and fix {set/append}-data
  • Loading branch information
whyrusleeping committed Jan 10, 2016
2 parents 3a60c0f + a90e5cc commit f2e4208
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
27 changes: 24 additions & 3 deletions core/commands/object/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand All @@ -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
Expand Down
23 changes: 22 additions & 1 deletion test/sharness/t0051-object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
'
}

Expand Down

0 comments on commit f2e4208

Please sign in to comment.