jsonrpc: update tests
This commit is contained in:
parent
6a20d0dafe
commit
df90b72500
@ -70,7 +70,10 @@ func TestRPC(t *testing.T) {
|
|||||||
AddGet func(int) int
|
AddGet func(int) int
|
||||||
StringMatch func(t TestType, i2 int64) (out TestOut, err error)
|
StringMatch func(t TestType, i2 int64) (out TestOut, err error)
|
||||||
}
|
}
|
||||||
closer := NewClient(testServ.URL, "SimpleServerHandler", &client)
|
closer, err := NewClient(testServ.URL, "SimpleServerHandler", &client)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
defer closer()
|
defer closer()
|
||||||
|
|
||||||
// Add(int) error
|
// Add(int) error
|
||||||
@ -83,7 +86,7 @@ func TestRPC(t *testing.T) {
|
|||||||
t.Error("expected 2")
|
t.Error("expected 2")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.Add(-3546)
|
err = client.Add(-3546)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected error")
|
t.Fatal("expected error")
|
||||||
}
|
}
|
||||||
@ -130,7 +133,10 @@ func TestRPC(t *testing.T) {
|
|||||||
var noret struct {
|
var noret struct {
|
||||||
Add func(int)
|
Add func(int)
|
||||||
}
|
}
|
||||||
closer = NewClient(testServ.URL, "SimpleServerHandler", &noret)
|
closer, err = NewClient(testServ.URL, "SimpleServerHandler", &noret)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
// this one should actually work
|
// this one should actually work
|
||||||
noret.Add(4)
|
noret.Add(4)
|
||||||
@ -142,7 +148,10 @@ func TestRPC(t *testing.T) {
|
|||||||
var noparam struct {
|
var noparam struct {
|
||||||
Add func()
|
Add func()
|
||||||
}
|
}
|
||||||
closer = NewClient(testServ.URL, "SimpleServerHandler", &noparam)
|
closer, err = NewClient(testServ.URL, "SimpleServerHandler", &noparam)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
// shouldn't panic
|
// shouldn't panic
|
||||||
noparam.Add()
|
noparam.Add()
|
||||||
@ -151,7 +160,10 @@ func TestRPC(t *testing.T) {
|
|||||||
var erronly struct {
|
var erronly struct {
|
||||||
AddGet func() (int, error)
|
AddGet func() (int, error)
|
||||||
}
|
}
|
||||||
closer = NewClient(testServ.URL, "SimpleServerHandler", &erronly)
|
closer, err = NewClient(testServ.URL, "SimpleServerHandler", &erronly)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
_, err = erronly.AddGet()
|
_, err = erronly.AddGet()
|
||||||
if err == nil || err.Error() != "RPC error (-32602): wrong param count" {
|
if err == nil || err.Error() != "RPC error (-32602): wrong param count" {
|
||||||
@ -162,7 +174,10 @@ func TestRPC(t *testing.T) {
|
|||||||
var wrongtype struct {
|
var wrongtype struct {
|
||||||
Add func(string) error
|
Add func(string) error
|
||||||
}
|
}
|
||||||
closer = NewClient(testServ.URL, "SimpleServerHandler", &wrongtype)
|
closer, err = NewClient(testServ.URL, "SimpleServerHandler", &wrongtype)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
err = wrongtype.Add("not an int")
|
err = wrongtype.Add("not an int")
|
||||||
if err == nil || err.Error() != "RPC error (-32700): json: cannot unmarshal string into Go value of type int" {
|
if err == nil || err.Error() != "RPC error (-32700): json: cannot unmarshal string into Go value of type int" {
|
||||||
@ -173,7 +188,10 @@ func TestRPC(t *testing.T) {
|
|||||||
var notfound struct {
|
var notfound struct {
|
||||||
NotThere func(string) error
|
NotThere func(string) error
|
||||||
}
|
}
|
||||||
closer = NewClient(testServ.URL, "SimpleServerHandler", ¬found)
|
closer, err = NewClient(testServ.URL, "SimpleServerHandler", ¬found)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
err = notfound.NotThere("hello?")
|
err = notfound.NotThere("hello?")
|
||||||
if err == nil || err.Error() != "RPC error (-32601): method 'SimpleServerHandler.NotThere' not found" {
|
if err == nil || err.Error() != "RPC error (-32601): method 'SimpleServerHandler.NotThere' not found" {
|
||||||
@ -219,7 +237,10 @@ func TestCtx(t *testing.T) {
|
|||||||
var client struct {
|
var client struct {
|
||||||
Test func(ctx context.Context)
|
Test func(ctx context.Context)
|
||||||
}
|
}
|
||||||
closer := NewClient(testServ.URL, "CtxHandler", &client)
|
closer, err := NewClient(testServ.URL, "CtxHandler", &client)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@ -239,7 +260,10 @@ func TestCtx(t *testing.T) {
|
|||||||
var noCtxClient struct {
|
var noCtxClient struct {
|
||||||
Test func()
|
Test func()
|
||||||
}
|
}
|
||||||
closer = NewClient(testServ.URL, "CtxHandler", &noCtxClient)
|
closer, err = NewClient(testServ.URL, "CtxHandler", &noCtxClient)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
noCtxClient.Test()
|
noCtxClient.Test()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user