Browse Source

mock: use go.uber.org/mock (#2540)

pull/2571/head
Sukun 1 year ago
committed by GitHub
parent
commit
d08bcd9c0f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      core/network/mocks/mock_conn_management_scope.go
  2. 2
      core/network/mocks/mock_peer_scope.go
  3. 2
      core/network/mocks/mock_protocol_scope.go
  4. 2
      core/network/mocks/mock_resource_manager.go
  5. 2
      core/network/mocks/mock_resource_scope_span.go
  6. 2
      core/network/mocks/mock_stream_management_scope.go
  7. 12
      core/network/mocks/network.go
  8. 3
      go.mod
  9. 2
      go.sum
  10. 2
      p2p/host/basic/mock_nat_test.go
  11. 2
      p2p/host/basic/mocks.go
  12. 2
      p2p/host/basic/natmgr_test.go
  13. 2
      p2p/host/pstoremanager/mock_peerstore_test.go
  14. 4
      p2p/host/pstoremanager/pstoremanager_test.go
  15. 2
      p2p/net/nat/mock_nat_test.go
  16. 4
      p2p/net/nat/nat_test.go
  17. 2
      p2p/net/swarm/swarm_test.go
  18. 2
      p2p/net/upgrader/listener_test.go
  19. 2
      p2p/net/upgrader/upgrader_test.go
  20. 4
      p2p/test/transport/gating_test.go
  21. 2
      p2p/test/transport/mock_connection_gater_test.go
  22. 2
      p2p/test/transport/rcmgr_test.go
  23. 4
      p2p/transport/quic/conn_test.go
  24. 2
      p2p/transport/quic/mock_connection_gater_test.go
  25. 2
      p2p/transport/tcp/tcp_test.go
  26. 2
      p2p/transport/webtransport/mock_connection_gater_test.go
  27. 4
      p2p/transport/webtransport/transport_test.go
  28. 1
      test-plans/go.mod
  29. 2
      test-plans/go.sum
  30. 2
      tools.go

2
core/network/mocks/mock_conn_management_scope.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.

2
core/network/mocks/mock_peer_scope.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"
)
// MockPeerScope is a mock of PeerScope interface.

2
core/network/mocks/mock_protocol_scope.go

@ -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.

2
core/network/mocks/mock_resource_manager.go

@ -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.

2
core/network/mocks/mock_resource_scope_span.go

@ -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.

2
core/network/mocks/mock_stream_management_scope.go

@ -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.

12
core/network/mocks/network.go

@ -1,8 +1,8 @@
package mocknetwork
//go:generate sh -c "go run github.com/golang/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/golang/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/golang/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/golang/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/golang/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/golang/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.org/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.org/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.org/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.org/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.org/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.org/mock/mockgen -package mocknetwork -destination mock_resource_scope_span.go github.com/libp2p/go-libp2p/core/network ResourceScopeSpan"

3
go.mod

@ -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-52ccab3ef572 // 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-2e65f85255db // indirect
github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b // indirect

2
go.sum

@ -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=

2
p2p/host/basic/mock_nat_test.go

@ -9,7 +9,7 @@ import (
netip "net/netip"
reflect "reflect"
gomock "github.com/golang/mock/gomock"
gomock "go.uber.org/mock/gomock"
)
// MockNAT is a mock of NAT interface.

2
p2p/host/basic/mocks.go

@ -2,5 +2,5 @@
package basichost
//go:generate sh -c "go run github.com/golang/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.org/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

2
p2p/host/basic/natmgr_test.go

@ -12,7 +12,7 @@ import (
swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
"github.com/golang/mock/gomock"
"go.uber.org/mock/gomock"
)
func setupMockNAT(t *testing.T) (mockNAT *MockNAT, reset func()) {

2
p2p/host/pstoremanager/mock_peerstore_test.go

@ -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.

4
p2p/host/pstoremanager/pstoremanager_test.go

@ -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/golang/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.org/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()

2
p2p/net/nat/mock_nat_test.go

@ -10,7 +10,7 @@ import (
reflect "reflect"
time "time"
gomock "github.com/golang/mock/gomock"
gomock "go.uber.org/mock/gomock"
)
// MockNAT is a mock of NAT interface.

4
p2p/net/nat/nat_test.go

@ -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/golang/mock/mockgen -package nat -destination mock_nat_test.go github.com/libp2p/go-nat NAT"
//go:generate sh -c "go run go.uber.org/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()

2
p2p/net/swarm/swarm_test.go

@ -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")

2
p2p/net/upgrader/listener_test.go

@ -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 {

2
p2p/net/upgrader/upgrader_test.go

@ -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) {

4
p2p/test/transport/gating_test.go

@ -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/golang/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.org/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 {

2
p2p/test/transport/mock_connection_gater_test.go

@ -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.

2
p2p/test/transport/rcmgr_test.go

@ -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) {

4
p2p/transport/quic/conn_test.go

@ -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/golang/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.org/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

2
p2p/transport/quic/mock_connection_gater_test.go

@ -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.

2
p2p/transport/tcp/tcp_test.go

@ -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}}

2
p2p/transport/webtransport/mock_connection_gater_test.go

@ -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.

4
p2p/transport/webtransport/transport_test.go

@ -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/golang/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.org/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)

1
test-plans/go.mod

@ -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

2
test-plans/go.sum

@ -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=

2
tools.go

@ -3,7 +3,7 @@
package libp2p
import (
_ "github.com/golang/mock/mockgen"
_ "go.uber.org/mock/mockgen"
_ "golang.org/x/tools/cmd/goimports"
_ "google.golang.org/protobuf/cmd/protoc-gen-go"
)

Loading…
Cancel
Save