2014-01-09 06:49:06 +01:00
|
|
|
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
2013-05-10 22:16:18 +02:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package btcjson
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
This test file is part of the btcjson package rather than than the
|
|
|
|
btcjson_test package so it can bridge access to the internals to properly test
|
|
|
|
cases which are either not possible or can't reliably be tested via the public
|
|
|
|
interface. The functions are only exported while the tests are being run.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TestJsonWIthArgs tests jsonWithArgs to ensure that it can generate a json
|
|
|
|
// command as well as sending it something that cannot be marshalled to json
|
|
|
|
// (a channel) to test the failure paths.
|
|
|
|
func TestJsonWithArgs(t *testing.T) {
|
|
|
|
cmd := "list"
|
|
|
|
var args interface{}
|
2013-08-13 20:05:08 +02:00
|
|
|
_, err := jsonWithArgs(cmd, "test", args)
|
2013-05-10 22:16:18 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Could not make json with no args. %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
channel := make(chan int)
|
2013-08-13 20:05:08 +02:00
|
|
|
_, err = jsonWithArgs(cmd, "test", channel)
|
2013-05-10 22:16:18 +02:00
|
|
|
if _, ok := err.(*json.UnsupportedTypeError); !ok {
|
|
|
|
t.Errorf("Message with channel should fail. %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var comp complex128
|
2013-08-13 20:05:08 +02:00
|
|
|
_, err = jsonWithArgs(cmd, "test", comp)
|
2013-05-10 22:16:18 +02:00
|
|
|
if _, ok := err.(*json.UnsupportedTypeError); !ok {
|
|
|
|
t.Errorf("Message with complex part should fail. %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-09-05 19:44:04 +02:00
|
|
|
// TestJsonRPCSend tests jsonRPCSend which actually send the rpc command.
|
2013-05-10 22:16:18 +02:00
|
|
|
// This currently a negative test only until we setup a fake http server to
|
|
|
|
// test the actually connection code.
|
2014-09-05 19:44:04 +02:00
|
|
|
func TestJsonRPCSend(t *testing.T) {
|
2013-05-10 22:16:18 +02:00
|
|
|
// Just negative test right now.
|
|
|
|
user := "something"
|
|
|
|
password := "something"
|
|
|
|
server := "invalid"
|
|
|
|
var message []byte
|
2014-09-05 19:44:04 +02:00
|
|
|
_, err := jsonRPCSend(user, password, server, message, false, nil, false)
|
2013-05-10 22:16:18 +02:00
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Should fail when it cannot connect.")
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|