test and fix bugs in getaddednodeinfo

This commit is contained in:
Owain G. Ainsworth 2013-10-25 18:23:28 +01:00
parent 77316a003a
commit b3b8b37855
2 changed files with 45 additions and 21 deletions

View file

@ -1253,7 +1253,7 @@ func NewGetAddedNodeInfoCmd(id interface{}, dns bool, optArgs ...string) (*GetAd
if len(optArgs) > 1 {
return nil, ErrTooManyOptArgs
}
node = optArgs[1]
node = optArgs[0]
}
return &GetAddedNodeInfoCmd{
id: id,
@ -1275,26 +1275,18 @@ func (cmd *GetAddedNodeInfoCmd) Method() string {
// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface.
func (cmd *GetAddedNodeInfoCmd) MarshalJSON() ([]byte, error) {
// Fill and marshal a RawCmd.
var raw RawCmd
if cmd.Node == "" {
raw = RawCmd{
Jsonrpc: "1.0",
Method: "getaddednodeinfo",
Id: cmd.id,
Params: []interface{}{
cmd.Dns,
},
}
} else {
raw = RawCmd{
Jsonrpc: "1.0",
Method: "getaddednodeinfo",
Id: cmd.id,
Params: []interface{}{
cmd.Dns,
cmd.Node,
},
}
raw := RawCmd{
Jsonrpc: "1.0",
Method: "getaddednodeinfo",
Id: cmd.id,
Params: []interface{}{
cmd.Dns,
},
}
if cmd.Node != "" {
raw.Params = append(raw.Params, cmd.Node)
}
return json.Marshal(raw)

View file

@ -190,6 +190,38 @@ var jsoncmdtests = []struct {
Account: "account",
},
},
{
name: "basic getaddednodeinfo true",
f: func() (Cmd, error) {
return NewGetAddedNodeInfoCmd(float64(1), true)
},
result: &GetAddedNodeInfoCmd{
id: float64(1),
Dns: true,
},
},
{
name: "basic getaddednodeinfo false",
f: func() (Cmd, error) {
return NewGetAddedNodeInfoCmd(float64(1), false)
},
result: &GetAddedNodeInfoCmd{
id: float64(1),
Dns: false,
},
},
{
name: "basic getaddednodeinfo withnode",
f: func() (Cmd, error) {
return NewGetAddedNodeInfoCmd(float64(1), true,
"thisisanode")
},
result: &GetAddedNodeInfoCmd{
id: float64(1),
Dns: true,
Node: "thisisanode",
},
},
{
name: "basic ping",
f: func() (Cmd, error) {