Wire up node API to tests

This commit is contained in:
Łukasz Magiera
2019-07-09 18:27:07 +02:00
parent b843dcb590
commit ba846e9bfb
4 changed files with 51 additions and 4 deletions
+12
View File
@@ -3,6 +3,7 @@ package node
import (
"context"
"errors"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
"reflect"
"time"
@@ -236,6 +237,17 @@ func New(ctx context.Context, opts ...Option) (api.API, error) {
// In-memory / testing
func MockHost(mn mocknet.Mocknet) Option {
return Options(
applyIf(func(s *settings) bool { return !s.online },
Error(errors.New("MockHost must be specified after Online")),
),
Override(new(lp2p.RawHost), lp2p.MockHost),
Override(new(mocknet.Mocknet), mn),
)
}
func randomIdentity() Option {
sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
if err != nil {
+34
View File
@@ -0,0 +1,34 @@
package node
import (
"context"
"github.com/filecoin-project/go-lotus/api/test"
"testing"
"github.com/filecoin-project/go-lotus/api"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
)
func builder(t *testing.T, n int) []api.API {
ctx := context.Background()
mn := mocknet.New(ctx)
out := make([]api.API, n)
for i := 0; i < n; i++ {
var err error
out[i], err = New(ctx,
Online(),
MockHost(mn),
)
if err != nil {
t.Fatal(err)
}
}
return out
}
func TestAPI(t *testing.T) {
test.TestApis(t, builder)
}