assign public IP addresses for tests that need them

This commit is contained in:
Steven Allen 2020-03-19 18:38:36 -07:00
parent 8a002250dc
commit bb08f7fe56
4 changed files with 28 additions and 18 deletions

View File

@ -65,7 +65,7 @@ func (NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int)
}
c := config.Config{}
c.Addresses.Swarm = []string{fmt.Sprintf("/ip4/127.0.%d.1/tcp/4001", i)}
c.Addresses.Swarm = []string{fmt.Sprintf("/ip4/18.0.%d.1/tcp/4001", i)}
c.Identity = ident
c.Experimental.FilestoreEnabled = true

View File

@ -2,6 +2,8 @@ package coremock
import (
"context"
"fmt"
"io/ioutil"
libp2p2 "github.com/ipfs/go-ipfs/core/node/libp2p"
@ -75,3 +77,24 @@ func MockCmdsCtx() (commands.Context, error) {
},
}, nil
}
func MockPublicNode(ctx context.Context, mn mocknet.Mocknet) (*core.IpfsNode, error) {
ds := syncds.MutexWrap(datastore.NewMapDatastore())
cfg, err := config.Init(ioutil.Discard, 2048)
if err != nil {
return nil, err
}
count := len(mn.Peers())
cfg.Addresses.Swarm = []string{
fmt.Sprintf("/ip4/18.0.%d.%d/tcp/4001", count>>16, count&0xFF),
}
cfg.Datastore = config.Datastore{}
return core.NewNode(ctx, &core.BuildCfg{
Online: true,
Repo: &repo.Mock{
C: *cfg,
D: ds,
},
Host: MockHostOption(mn),
})
}

View File

@ -29,10 +29,7 @@ func TestRepublish(t *testing.T) {
var nodes []*core.IpfsNode
for i := 0; i < 10; i++ {
nd, err := core.NewNode(ctx, &core.BuildCfg{
Online: true,
Host: mock.MockHostOption(mn),
})
nd, err := mock.MockPublicNode(ctx, mn)
if err != nil {
t.Fatal(err)
}

View File

@ -9,7 +9,6 @@ import (
"testing"
"time"
core "github.com/ipfs/go-ipfs/core"
bootstrap2 "github.com/ipfs/go-ipfs/core/bootstrap"
"github.com/ipfs/go-ipfs/core/coreapi"
mock "github.com/ipfs/go-ipfs/core/mock"
@ -76,28 +75,19 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
Bandwidth: math.MaxInt32,
})
bootstrap, err := core.NewNode(ctx, &core.BuildCfg{
Online: true,
Host: mock.MockHostOption(mn),
})
bootstrap, err := mock.MockPublicNode(ctx, mn)
if err != nil {
return err
}
defer bootstrap.Close()
adder, err := core.NewNode(ctx, &core.BuildCfg{
Online: true,
Host: mock.MockHostOption(mn),
})
adder, err := mock.MockPublicNode(ctx, mn)
if err != nil {
return err
}
defer adder.Close()
catter, err := core.NewNode(ctx, &core.BuildCfg{
Online: true,
Host: mock.MockHostOption(mn),
})
catter, err := mock.MockPublicNode(ctx, mn)
if err != nil {
return err
}