Skip to content

Commit

Permalink
assign public IP addresses for tests that need them
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Apr 9, 2020
1 parent 5e1559f commit 7f97c7f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion core/coreapi/test/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 23 additions & 0 deletions core/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package coremock

import (
"context"
"fmt"
"io/ioutil"

libp2p2 "github.com/ipfs/go-ipfs/core/node/libp2p"

Expand Down Expand Up @@ -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),
})
}
5 changes: 1 addition & 4 deletions namesys/republisher/repub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
16 changes: 3 additions & 13 deletions test/integration/three_legged_cat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 7f97c7f

Please sign in to comment.