From 4ac8eba59e210ef7177bd6d355bfbc2340aca33a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 9 Jul 2019 18:36:40 +0200 Subject: [PATCH] Test API through jsonrpc --- node/builder.go | 3 ++- node/node_test.go | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/node/builder.go b/node/builder.go index d74a936df..236703023 100644 --- a/node/builder.go +++ b/node/builder.go @@ -3,10 +3,11 @@ package node import ( "context" "errors" - mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" "reflect" "time" + mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" + "github.com/ipfs/go-datastore" blockstore "github.com/ipfs/go-ipfs-blockstore" exchange "github.com/ipfs/go-ipfs-exchange-interface" diff --git a/node/node_test.go b/node/node_test.go index 2becf65a1..d8671cba5 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -2,10 +2,14 @@ package node import ( "context" - "github.com/filecoin-project/go-lotus/api/test" + "net/http/httptest" "testing" "github.com/filecoin-project/go-lotus/api" + "github.com/filecoin-project/go-lotus/api/client" + "github.com/filecoin-project/go-lotus/api/test" + "github.com/filecoin-project/go-lotus/lib/jsonrpc" + mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" ) @@ -32,3 +36,22 @@ func builder(t *testing.T, n int) []api.API { func TestAPI(t *testing.T) { test.TestApis(t, builder) } + +var nextApi int + +func rpcBuilder(t *testing.T, n int) []api.API { + nodeApis := builder(t, n) + out := make([]api.API, n) + + for i, a := range nodeApis { + rpcServer := jsonrpc.NewServer() + rpcServer.Register("Filecoin", a) + testServ := httptest.NewServer(rpcServer) // todo: close + out[i] = client.NewRPC(testServ.URL) + } + return out +} + +func TestAPIRPC(t *testing.T) { + test.TestApis(t, rpcBuilder) +}