Sukun
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with
43 additions and
37 deletions
core/network/mocks/mock_conn_management_scope.go
core/network/mocks/mock_peer_scope.go
core/network/mocks/mock_protocol_scope.go
core/network/mocks/mock_resource_manager.go
core/network/mocks/mock_resource_scope_span.go
core/network/mocks/mock_stream_management_scope.go
core/network/mocks/network.go
go.mod
go.sum
p2p/host/basic/mock_nat_test.go
p2p/host/basic/mocks.go
p2p/host/basic/natmgr_test.go
p2p/host/pstoremanager/mock_peerstore_test.go
p2p/host/pstoremanager/pstoremanager_test.go
p2p/net/nat/mock_nat_test.go
p2p/net/nat/nat_test.go
p2p/net/swarm/swarm_test.go
p2p/net/upgrader/listener_test.go
p2p/net/upgrader/upgrader_test.go
p2p/test/transport/gating_test.go
p2p/test/transport/mock_connection_gater_test.go
p2p/test/transport/rcmgr_test.go
p2p/transport/quic/conn_test.go
p2p/transport/quic/mock_connection_gater_test.go
p2p/transport/tcp/tcp_test.go
p2p/transport/webtransport/mock_connection_gater_test.go
p2p/transport/webtransport/transport_test.go
test-plans/go.mod
test-plans/go.sum
tools.go
@ -7,9 +7,9 @@ package mocknetwork
import (
reflect "reflect"
gomock "github.com/golang/mock/gomock"
network "github.com/libp2p/go-libp2p/core/network"
peer "github.com/libp2p/go-libp2p/core/peer"
gomock "go.uber.org/mock/gomock"
)
// MockConnManagementScope is a mock of ConnManagementScope interface.
@ -7,9 +7,9 @@ package mocknetwork
import (
reflect "reflect"
gomock "github.com/golang/mock/gomock"
network "github.com/libp2p/go-libp2p/core/network"
peer "github.com/libp2p/go-libp2p/core/peer"
gomock "go.uber.org/mock/gomock"
)
// MockPeerScope is a mock of PeerScope interface.
@ -7,9 +7,9 @@ package mocknetwork
import (
reflect "reflect"
gomock "github.com/golang/mock/gomock"
network "github.com/libp2p/go-libp2p/core/network"
protocol "github.com/libp2p/go-libp2p/core/protocol"
gomock "go.uber.org/mock/gomock"
)
// MockProtocolScope is a mock of ProtocolScope interface.
@ -7,11 +7,11 @@ package mocknetwork
import (
reflect "reflect"
gomock "github.com/golang/mock/gomock"
network "github.com/libp2p/go-libp2p/core/network"
peer "github.com/libp2p/go-libp2p/core/peer"
protocol "github.com/libp2p/go-libp2p/core/protocol"
multiaddr "github.com/multiformats/go-multiaddr"
gomock "go.uber.org/mock/gomock"
)
// MockResourceManager is a mock of ResourceManager interface.
@ -7,8 +7,8 @@ package mocknetwork
import (
reflect "reflect"
gomock "github.com/golang/mock/gomock"
network "github.com/libp2p/go-libp2p/core/network"
gomock "go.uber.org/mock/gomock"
)
// MockResourceScopeSpan is a mock of ResourceScopeSpan interface.
@ -7,9 +7,9 @@ package mocknetwork
import (
reflect "reflect"
gomock "github.com/golang/mock/gomock"
network "github.com/libp2p/go-libp2p/core/network"
protocol "github.com/libp2p/go-libp2p/core/protocol"
gomock "go.uber.org/mock/gomock"
)
// MockStreamManagementScope is a mock of StreamManagementScope interface.
@ -1,8 +1,8 @@
package mocknetwork
//go:generate sh -c "go run github.com/golan g/mock/mockgen -package mocknetwork -destination mock_resource_manager.go github.com/libp2p/go-libp2p/core/network ResourceManager"
//go:generate sh -c "go run github.com/golan g/mock/mockgen -package mocknetwork -destination mock_conn_management_scope.go github.com/libp2p/go-libp2p/core/network ConnManagementScope"
//go:generate sh -c "go run github.com/golan g/mock/mockgen -package mocknetwork -destination mock_stream_management_scope.go github.com/libp2p/go-libp2p/core/network StreamManagementScope"
//go:generate sh -c "go run github.com/golan g/mock/mockgen -package mocknetwork -destination mock_peer_scope.go github.com/libp2p/go-libp2p/core/network PeerScope"
//go:generate sh -c "go run github.com/golan g/mock/mockgen -package mocknetwork -destination mock_protocol_scope.go github.com/libp2p/go-libp2p/core/network ProtocolScope"
//go:generate sh -c "go run github.com/golan g/mock/mockgen -package mocknetwork -destination mock_resource_scope_span.go github.com/libp2p/go-libp2p/core/network ResourceScopeSpan"
//go:generate sh -c "go run go.uber.or g/mock/mockgen -package mocknetwork -destination mock_resource_manager.go github.com/libp2p/go-libp2p/core/network ResourceManager"
//go:generate sh -c "go run go.uber.or g/mock/mockgen -package mocknetwork -destination mock_conn_management_scope.go github.com/libp2p/go-libp2p/core/network ConnManagementScope"
//go:generate sh -c "go run go.uber.or g/mock/mockgen -package mocknetwork -destination mock_stream_management_scope.go github.com/libp2p/go-libp2p/core/network StreamManagementScope"
//go:generate sh -c "go run go.uber.or g/mock/mockgen -package mocknetwork -destination mock_peer_scope.go github.com/libp2p/go-libp2p/core/network PeerScope"
//go:generate sh -c "go run go.uber.or g/mock/mockgen -package mocknetwork -destination mock_protocol_scope.go github.com/libp2p/go-libp2p/core/network ProtocolScope"
//go:generate sh -c "go run go.uber.or g/mock/mockgen -package mocknetwork -destination mock_resource_scope_span.go github.com/libp2p/go-libp2p/core/network ResourceScopeSpan"
@ -9,7 +9,6 @@ require (
github . com / davidlazar / go - crypto v0 . 0.0 - 20200604182044 - b73af7476f6c
github . com / decred / dcrd / dcrec / secp256k1 / v4 v4 . 2.0
github . com / flynn / noise v1 . 0.0
github . com / golang / mock v1 . 6.0
github . com / google / gopacket v1 . 1.19
github . com / gorilla / websocket v1 . 5.0
github . com / hashicorp / golang - lru / arc / v2 v2 . 0.5
@ -58,6 +57,7 @@ require (
github . com / stretchr / testify v1 . 8.4
go . uber . org / fx v1 . 20.0
go . uber . org / goleak v1 . 2.0
go . uber . org / mock v0 . 2.0
go . uber . org / zap v1 . 25.0
golang . org / x / crypto v0 . 12.0
golang . org / x / exp v0 . 0.0 - 20230817173708 - d852ddb80c63
@ -85,6 +85,7 @@ require (
github . com / go - task / slim - sprig v0 . 0.0 - 20230315185526 - 52 ccab3ef572 / / indirect
github . com / godbus / dbus / v5 v5 . 1.0 / / indirect
github . com / gogo / protobuf v1 . 3.2 / / indirect
github . com / golang / mock v1 . 6.0 / / indirect
github . com / golang / protobuf v1 . 5.3 / / indirect
github . com / golang / snappy v0 . 0.0 - 20180518054509 - 2 e65f85255db / / indirect
github . com / google / pprof v0 . 0.0 - 20230817174616 - 7 a8ec2ada47b / / indirect
@ -573,6 +573,8 @@ go.uber.org/fx v1.20.0/go.mod h1:qCUj0btiR3/JnanEr1TYEePfSw6o/4qYJscgvzQ5Ub0=
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
go.uber.org/mock v0.2.0 h1:TaP3xedm7JaAgScZO7tlvlKrqT0p7I6OsdGB5YNSMDU=
go.uber.org/mock v0.2.0/go.mod h1:J0y0rp9L3xiff1+ZBfKxlC1fz2+aO16tw0tsDOixfuM=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
@ -9,7 +9,7 @@ import (
netip "net/netip"
reflect "reflect"
gomock "github.com/golan g/mock/gomock"
gomock "go.uber.or g/mock/gomock"
)
// MockNAT is a mock of NAT interface.
@ -2,5 +2,5 @@
package basichost
//go:generate sh -c "go run github.com/golan g/mock/mockgen -build_flags=\"-tags=gomock\" -package basichost -destination mock_nat_test.go github.com/libp2p/go-libp2p/p2p/host/basic NAT"
//go:generate sh -c "go run go.uber.or g/mock/mockgen -build_flags=\"-tags=gomock\" -package basichost -destination mock_nat_test.go github.com/libp2p/go-libp2p/p2p/host/basic NAT"
type NAT nat
@ -12,7 +12,7 @@ import (
swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
"github.com/golan g/mock/gomock"
"go.uber.or g/mock/gomock"
)
func setupMockNAT ( t * testing . T ) ( mockNAT * MockNAT , reset func ( ) ) {
@ -9,11 +9,11 @@ import (
reflect "reflect"
time "time"
gomock "github.com/golang/mock/gomock"
crypto "github.com/libp2p/go-libp2p/core/crypto"
peer "github.com/libp2p/go-libp2p/core/peer"
protocol "github.com/libp2p/go-libp2p/core/protocol"
multiaddr "github.com/multiformats/go-multiaddr"
gomock "go.uber.org/mock/gomock"
)
// MockPeerstore is a mock of Peerstore interface.
@ -10,11 +10,11 @@ import (
"github.com/libp2p/go-libp2p/p2p/host/eventbus"
"github.com/libp2p/go-libp2p/p2p/host/pstoremanager"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
//go:generate sh -c "go run github.com/golan g/mock/mockgen -package pstoremanager_test -destination mock_peerstore_test.go github.com/libp2p/go-libp2p/core/peerstore Peerstore"
//go:generate sh -c "go run go.uber.or g/mock/mockgen -package pstoremanager_test -destination mock_peerstore_test.go github.com/libp2p/go-libp2p/core/peerstore Peerstore"
func TestGracePeriod ( t * testing . T ) {
t . Parallel ( )
@ -10,7 +10,7 @@ import (
reflect "reflect"
time "time"
gomock "github.com/golan g/mock/gomock"
gomock "go.uber.or g/mock/gomock"
)
// MockNAT is a mock of NAT interface.
@ -9,11 +9,11 @@ import (
"github.com/libp2p/go-nat"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
//go:generate sh -c "go run github.com/golan g/mock/mockgen -package nat -destination mock_nat_test.go github.com/libp2p/go-nat NAT"
//go:generate sh -c "go run go.uber.or g/mock/mockgen -package nat -destination mock_nat_test.go github.com/libp2p/go-nat NAT"
func setupMockNAT ( t * testing . T ) ( mockNAT * MockNAT , reset func ( ) ) {
t . Helper ( )
@ -21,11 +21,11 @@ import (
"github.com/libp2p/go-libp2p/p2p/net/swarm"
. "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
"github.com/golang/mock/gomock"
logging "github.com/ipfs/go-log/v2"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr/net"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
var log = logging . Logger ( "swarm_test" )
@ -18,10 +18,10 @@ import (
"github.com/libp2p/go-libp2p/core/transport"
"github.com/libp2p/go-libp2p/p2p/net/upgrader"
"github.com/golang/mock/gomock"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr/net"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
func createListener ( t * testing . T , u transport . Upgrader ) transport . Listener {
@ -18,10 +18,10 @@ import (
"github.com/libp2p/go-libp2p/p2p/muxer/yamux"
"github.com/libp2p/go-libp2p/p2p/net/upgrader"
"github.com/golang/mock/gomock"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr/net"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
func createUpgrader ( t * testing . T ) ( peer . ID , transport . Upgrader ) {
@ -13,12 +13,12 @@ import (
"github.com/libp2p/go-libp2p-testing/race"
"github.com/golang/mock/gomock"
ma "github.com/multiformats/go-multiaddr"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
//go:generate go run github.com/golan g/mock/mockgen -package transport_integration -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater
//go:generate go run go.uber.or g/mock/mockgen -package transport_integration -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater
func stripCertHash ( addr ma . Multiaddr ) ma . Multiaddr {
for {
@ -7,11 +7,11 @@ package transport_integration
import (
reflect "reflect"
gomock "github.com/golang/mock/gomock"
control "github.com/libp2p/go-libp2p/core/control"
network "github.com/libp2p/go-libp2p/core/network"
peer "github.com/libp2p/go-libp2p/core/peer"
multiaddr "github.com/multiformats/go-multiaddr"
gomock "go.uber.org/mock/gomock"
)
// MockConnectionGater is a mock of ConnectionGater interface.
@ -9,7 +9,6 @@ import (
"testing"
"time"
"github.com/golang/mock/gomock"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/network"
mocknetwork "github.com/libp2p/go-libp2p/core/network/mocks"
@ -17,6 +16,7 @@ import (
"github.com/libp2p/go-libp2p/p2p/protocol/identify"
"github.com/libp2p/go-libp2p/p2p/protocol/ping"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
func TestResourceManagerIsUsed ( t * testing . T ) {
@ -20,14 +20,14 @@ import (
tpt "github.com/libp2p/go-libp2p/core/transport"
"github.com/libp2p/go-libp2p/p2p/transport/quicreuse"
"github.com/golang/mock/gomock"
ma "github.com/multiformats/go-multiaddr"
"github.com/quic-go/quic-go"
quicproxy "github.com/quic-go/quic-go/integrationtests/tools/proxy"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
//go:generate sh -c "go run github.com/golan g/mock/mockgen -package libp2pquic -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater && go run golang.org/x/tools/cmd/goimports -w mock_connection_gater_test.go"
//go:generate sh -c "go run go.uber.or g/mock/mockgen -package libp2pquic -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater && go run golang.org/x/tools/cmd/goimports -w mock_connection_gater_test.go"
type connTestCase struct {
Name string
@ -7,11 +7,11 @@ package libp2pquic
import (
reflect "reflect"
gomock "github.com/golang/mock/gomock"
control "github.com/libp2p/go-libp2p/core/control"
network "github.com/libp2p/go-libp2p/core/network"
peer "github.com/libp2p/go-libp2p/core/peer"
multiaddr "github.com/multiformats/go-multiaddr"
gomock "go.uber.org/mock/gomock"
)
// MockConnectionGater is a mock of ConnectionGater interface.
@ -16,9 +16,9 @@ import (
tptu "github.com/libp2p/go-libp2p/p2p/net/upgrader"
ttransport "github.com/libp2p/go-libp2p/p2p/transport/testsuite"
"github.com/golang/mock/gomock"
ma "github.com/multiformats/go-multiaddr"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
var muxers = [ ] tptu . StreamMuxer { { ID : "/yamux" , Muxer : yamux . DefaultTransport } }
@ -7,11 +7,11 @@ package libp2pwebtransport_test
import (
reflect "reflect"
gomock "github.com/golang/mock/gomock"
control "github.com/libp2p/go-libp2p/core/control"
network "github.com/libp2p/go-libp2p/core/network"
peer "github.com/libp2p/go-libp2p/core/peer"
multiaddr "github.com/multiformats/go-multiaddr"
gomock "go.uber.org/mock/gomock"
)
// MockConnectionGater is a mock of ConnectionGater interface.
@ -28,7 +28,6 @@ import (
libp2pwebtransport "github.com/libp2p/go-libp2p/p2p/transport/webtransport"
"github.com/benbjohnson/clock"
"github.com/golang/mock/gomock"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr/net"
"github.com/multiformats/go-multibase"
@ -37,6 +36,7 @@ import (
"github.com/quic-go/quic-go/http3"
quicproxy "github.com/quic-go/quic-go/integrationtests/tools/proxy"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
const clockSkewAllowance = time . Hour
@ -360,7 +360,7 @@ func TestResourceManagerListening(t *testing.T) {
}
// TODO: unify somehow. We do the same in libp2pquic.
//go:generate sh -c "go run github.com/golan g/mock/mockgen -package libp2pwebtransport_test -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater && go run golang.org/x/tools/cmd/goimports -w mock_connection_gater_test.go"
//go:generate sh -c "go run go.uber.or g/mock/mockgen -package libp2pwebtransport_test -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater && go run golang.org/x/tools/cmd/goimports -w mock_connection_gater_test.go"
func TestConnectionGaterDialing ( t * testing . T ) {
ctrl := gomock . NewController ( t )
@ -111,6 +111,7 @@ require (
github . com / stretchr / testify v1 . 8.4 / / indirect
go . uber . org / dig v1 . 17.0 / / indirect
go . uber . org / fx v1 . 20.0 / / indirect
go . uber . org / mock v0 . 2.0 / / indirect
go . uber . org / multierr v1 . 11.0 / / indirect
go . uber . org / zap v1 . 25.0 / / indirect
gopkg . in / yaml . v3 v3 . 0.1 / / indirect
@ -374,6 +374,8 @@ go.uber.org/fx v1.20.0 h1:ZMC/pnRvhsthOZh9MZjMq5U8Or3mA9zBSPaLnzs3ihQ=
go.uber.org/fx v1.20.0/go.mod h1:qCUj0btiR3/JnanEr1TYEePfSw6o/4qYJscgvzQ5Ub0=
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
go.uber.org/mock v0.2.0 h1:TaP3xedm7JaAgScZO7tlvlKrqT0p7I6OsdGB5YNSMDU=
go.uber.org/mock v0.2.0/go.mod h1:J0y0rp9L3xiff1+ZBfKxlC1fz2+aO16tw0tsDOixfuM=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
@ -3,7 +3,7 @@
package libp2p
import (
_ "github.com/golan g/mock/mockgen"
_ "go.uber.or g/mock/mockgen"
_ "golang.org/x/tools/cmd/goimports"
_ "google.golang.org/protobuf/cmd/protoc-gen-go"
)