From 5eeba536ea459d971cb36b86d07f298976b6915c Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sun, 2 Jan 2022 14:47:58 +0400 Subject: [PATCH] don't use a separate Go module for the autonat tests --- p2p/host/autonat/test/autonat_test.go | 39 +++++++++------------------ p2p/host/autonat/test/dummy.go | 2 +- p2p/host/autonat/test/go.mod | 5 ---- p2p/host/autonat/test/go.sum | 0 4 files changed, 14 insertions(+), 32 deletions(-) delete mode 100644 p2p/host/autonat/test/go.mod delete mode 100644 p2p/host/autonat/test/go.sum diff --git a/p2p/host/autonat/test/autonat_test.go b/p2p/host/autonat/test/autonat_test.go index 2ed9358c..46a592e7 100644 --- a/p2p/host/autonat/test/autonat_test.go +++ b/p2p/host/autonat/test/autonat_test.go @@ -1,53 +1,40 @@ -//go:build ignore -// +build ignore - // This separate testing package helps to resolve a circular dependency potentially // being created between libp2p and libp2p-autonat -package autonat_test +package autonattest import ( "context" "testing" "time" + "github.com/libp2p/go-libp2p-core/event" + "github.com/libp2p/go-libp2p-core/network" + "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/p2p/host/autonat" - "github.com/libp2p/go-libp2p-core/event" - "github.com/libp2p/go-libp2p-core/network" + "github.com/stretchr/testify/require" ) func TestAutonatRoundtrip(t *testing.T) { t.Skip("this test doesn't work") - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() // 3 hosts are used: [client] and [service + dialback dialer] - client, err := libp2p.New(ctx, libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0"), libp2p.EnableNATService()) - if err != nil { - t.Fatal(err) - } - service, err := libp2p.New(ctx, libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0")) - if err != nil { - t.Fatal(err) - } - dialback, err := libp2p.New(ctx, libp2p.NoListenAddrs) - if err != nil { - t.Fatal(err) - } + client, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0"), libp2p.EnableNATService()) + require.NoError(t, err) + service, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0")) + require.NoError(t, err) + dialback, err := libp2p.New(libp2p.NoListenAddrs) + require.NoError(t, err) if _, err := autonat.New(service, autonat.EnableService(dialback.Network())); err != nil { t.Fatal(err) } client.Peerstore().AddAddrs(service.ID(), service.Addrs(), time.Hour) - if err := client.Connect(ctx, service.Peerstore().PeerInfo(service.ID())); err != nil { - t.Fatal(err) - } + require.NoError(t, client.Connect(context.Background(), service.Peerstore().PeerInfo(service.ID()))) cSub, err := client.EventBus().Subscribe(new(event.EvtLocalReachabilityChanged)) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) defer cSub.Close() select { diff --git a/p2p/host/autonat/test/dummy.go b/p2p/host/autonat/test/dummy.go index c33883a6..c3597f81 100644 --- a/p2p/host/autonat/test/dummy.go +++ b/p2p/host/autonat/test/dummy.go @@ -1,3 +1,3 @@ -package autonat_test +package autonattest // needed so that go test ./... doesn't error diff --git a/p2p/host/autonat/test/go.mod b/p2p/host/autonat/test/go.mod deleted file mode 100644 index 3c68e2d7..00000000 --- a/p2p/host/autonat/test/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module github.com/libp2p/go-libp2p-autonat/test - -go 1.16 - -replace github.com/libp2p/go-libp2p-autonat => ../ diff --git a/p2p/host/autonat/test/go.sum b/p2p/host/autonat/test/go.sum deleted file mode 100644 index e69de29b..00000000