From df90b725005e11e732f0e2dc2b5cceb8b23acd89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 12 Jul 2019 19:12:51 +0200 Subject: [PATCH] jsonrpc: update tests --- lib/jsonrpc/rpc_test.go | 42 ++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/jsonrpc/rpc_test.go b/lib/jsonrpc/rpc_test.go index d496e25c5..307050061 100644 --- a/lib/jsonrpc/rpc_test.go +++ b/lib/jsonrpc/rpc_test.go @@ -70,7 +70,10 @@ func TestRPC(t *testing.T) { AddGet func(int) int 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() // Add(int) error @@ -83,7 +86,7 @@ func TestRPC(t *testing.T) { t.Error("expected 2") } - err := client.Add(-3546) + err = client.Add(-3546) if err == nil { t.Fatal("expected error") } @@ -130,7 +133,10 @@ func TestRPC(t *testing.T) { var noret struct { 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 noret.Add(4) @@ -142,7 +148,10 @@ func TestRPC(t *testing.T) { var noparam struct { Add func() } - closer = NewClient(testServ.URL, "SimpleServerHandler", &noparam) + closer, err = NewClient(testServ.URL, "SimpleServerHandler", &noparam) + if err != nil { + t.Fatal(err) + } // shouldn't panic noparam.Add() @@ -151,7 +160,10 @@ func TestRPC(t *testing.T) { var erronly struct { 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() if err == nil || err.Error() != "RPC error (-32602): wrong param count" { @@ -162,7 +174,10 @@ func TestRPC(t *testing.T) { var wrongtype struct { 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") 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 { 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?") 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 { 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) defer cancel() @@ -239,7 +260,10 @@ func TestCtx(t *testing.T) { var noCtxClient struct { Test func() } - closer = NewClient(testServ.URL, "CtxHandler", &noCtxClient) + closer, err = NewClient(testServ.URL, "CtxHandler", &noCtxClient) + if err != nil { + t.Fatal(err) + } noCtxClient.Test()