Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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