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

'key' objects dont marshal to json well #1334

Merged
merged 2 commits into from
Jun 8, 2015
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
14 changes: 7 additions & 7 deletions core/commands/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ resulting object hash.
cmds.StringArg("command", true, false, "the operation to perform"),
cmds.StringArg("args", true, true, "extra arguments").EnableStdin(),
},
Type: key.Key(""),
Type: Object{},
Run: func(req cmds.Request, res cmds.Response) {
nd, err := req.Context().GetNode()
if err != nil {
Expand Down Expand Up @@ -468,41 +468,41 @@ resulting object hash.
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput(k)
res.SetOutput(&Object{Hash: k.B58String()})
case "rm-link":
k, err := rmLinkCaller(req, rnode)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput(k)
res.SetOutput(&Object{Hash: k.B58String()})
case "set-data":
k, err := setDataCaller(req, rnode)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput(k)
res.SetOutput(&Object{Hash: k.B58String()})
case "append-data":
k, err := appendDataCaller(req, rnode)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput(k)
res.SetOutput(&Object{Hash: k.B58String()})
default:
res.SetError(fmt.Errorf("unrecognized subcommand"), cmds.ErrNormal)
return
}
},
Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) {
k, ok := res.Output().(key.Key)
o, ok := res.Output().(*Object)
if !ok {
return nil, u.ErrCast()
}

return strings.NewReader(k.B58String() + "\n"), nil
return strings.NewReader(o.Hash + "\n"), nil
},
},
}
Expand Down
23 changes: 23 additions & 0 deletions test/sharness/t0051-object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@ test_object_cmd() {
test_cmp expected_putBroken actual_putBroken &&
test_cmp expected_putBrokenErr actual_putBrokenErr
'

test_expect_success "'ipfs object patch' should work" '
EMPTY_DIR=$(ipfs object new unixfs-dir) &&
OUTPUT=$(ipfs object patch $EMPTY_DIR add-link foo $EMPTY_DIR)
'

test_expect_success "should have created dir within a dir" '
ipfs ls $OUTPUT > patched_output
'

test_expect_success "output looks good" '
echo "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn 4 foo/ " > patched_exp &&
test_cmp patched_exp patched_output
'

test_expect_success "can remove the directory" '
ipfs object patch $OUTPUT rm-link foo > rmlink_output
'

test_expect_success "output should be empty" '
echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn > rmlink_exp &&
test_cmp rmlink_exp rmlink_output
'
}

# should work offline
Expand Down