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 { if len(optArgs) > 1 {
return nil, ErrTooManyOptArgs return nil, ErrTooManyOptArgs
} }
node = optArgs[1] node = optArgs[0]
} }
return &GetAddedNodeInfoCmd{ return &GetAddedNodeInfoCmd{
id: id, id: id,
@ -1275,9 +1275,8 @@ func (cmd *GetAddedNodeInfoCmd) Method() string {
// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface.
func (cmd *GetAddedNodeInfoCmd) MarshalJSON() ([]byte, error) { func (cmd *GetAddedNodeInfoCmd) MarshalJSON() ([]byte, error) {
// Fill and marshal a RawCmd. // Fill and marshal a RawCmd.
var raw RawCmd
if cmd.Node == "" { raw := RawCmd{
raw = RawCmd{
Jsonrpc: "1.0", Jsonrpc: "1.0",
Method: "getaddednodeinfo", Method: "getaddednodeinfo",
Id: cmd.id, Id: cmd.id,
@ -1285,16 +1284,9 @@ func (cmd *GetAddedNodeInfoCmd) MarshalJSON() ([]byte, error) {
cmd.Dns, cmd.Dns,
}, },
} }
} else {
raw = RawCmd{ if cmd.Node != "" {
Jsonrpc: "1.0", raw.Params = append(raw.Params, cmd.Node)
Method: "getaddednodeinfo",
Id: cmd.id,
Params: []interface{}{
cmd.Dns,
cmd.Node,
},
}
} }
return json.Marshal(raw) return json.Marshal(raw)

View file

@ -190,6 +190,38 @@ var jsoncmdtests = []struct {
Account: "account", 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", name: "basic ping",
f: func() (Cmd, error) { f: func() (Cmd, error) {