diff --git a/.github/actions/go-check-setup/action.yml b/.github/actions/go-check-setup/action.yml new file mode 100644 index 0000000000..9567c23584 --- /dev/null +++ b/.github/actions/go-check-setup/action.yml @@ -0,0 +1,10 @@ +runs: + using: "composite" + steps: + - name: Install Protoc + uses: trail-of-forks/setup-protoc@a97892a429d98fae78d26f40334ab7eb616d08b9 # include https://github.com/arduino/setup-protoc/pull/58 + with: + version: '21.12' + - name: Install Protobuf compiler + shell: bash + run: go install google.golang.org/protobuf/cmd/protoc-gen-go diff --git a/.github/workflows/go-check-config.json b/.github/workflows/go-check-config.json new file mode 100644 index 0000000000..4b37308d50 --- /dev/null +++ b/.github/workflows/go-check-config.json @@ -0,0 +1,3 @@ +{ + "gogenerate": true +} diff --git a/core/network/mocks/network.go b/core/network/mocks/network.go index 975ba4a1f8..5408f0fc33 100644 --- a/core/network/mocks/network.go +++ b/core/network/mocks/network.go @@ -1,7 +1,7 @@ package mocknetwork -//go:generate sh -c "mockgen -package mocknetwork -destination mock_resource_manager.go github.com/libp2p/go-libp2p/core/network ResourceManager" -//go:generate sh -c "mockgen -package mocknetwork -destination mock_conn_management_scope.go github.com/libp2p/go-libp2p/core/network ConnManagementScope" -//go:generate sh -c "mockgen -package mocknetwork -destination mock_stream_management_scope.go github.com/libp2p/go-libp2p/core/network StreamManagementScope" -//go:generate sh -c "mockgen -package mocknetwork -destination mock_peer_scope.go github.com/libp2p/go-libp2p/core/network PeerScope" -//go:generate sh -c "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_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" diff --git a/go.mod b/go.mod index 0102bb77aa..68bf9a7d78 100644 --- a/go.mod +++ b/go.mod @@ -54,6 +54,7 @@ require ( golang.org/x/crypto v0.3.0 golang.org/x/sync v0.1.0 golang.org/x/sys v0.3.0 + golang.org/x/tools v0.3.0 google.golang.org/protobuf v1.28.1 ) @@ -111,7 +112,6 @@ require ( golang.org/x/mod v0.7.0 // indirect golang.org/x/net v0.3.0 // indirect golang.org/x/text v0.5.0 // indirect - golang.org/x/tools v0.3.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.1.7 // indirect ) diff --git a/p2p/host/pstoremanager/mock_peerstore_test.go b/p2p/host/pstoremanager/mock_peerstore_test.go index a15476486c..8bd6578850 100644 --- a/p2p/host/pstoremanager/mock_peerstore_test.go +++ b/p2p/host/pstoremanager/mock_peerstore_test.go @@ -411,18 +411,6 @@ func (mr *MockPeerstoreMockRecorder) SetProtocols(arg0 interface{}, arg1 ...inte return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetProtocols", reflect.TypeOf((*MockPeerstore)(nil).SetProtocols), varargs...) } -// Start mocks base method. -func (m *MockPeerstore) Start() { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Start") -} - -// Start indicates an expected call of Start. -func (mr *MockPeerstoreMockRecorder) Start() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockPeerstore)(nil).Start)) -} - // SupportsProtocols mocks base method. func (m *MockPeerstore) SupportsProtocols(arg0 peer.ID, arg1 ...string) ([]string, error) { m.ctrl.T.Helper() diff --git a/p2p/host/pstoremanager/pstoremanager_test.go b/p2p/host/pstoremanager/pstoremanager_test.go index 064e625907..8726740c39 100644 --- a/p2p/host/pstoremanager/pstoremanager_test.go +++ b/p2p/host/pstoremanager/pstoremanager_test.go @@ -14,7 +14,7 @@ import ( "github.com/stretchr/testify/require" ) -//go:generate sh -c "mockgen -package pstoremanager_test -destination mock_peerstore_test.go github.com/libp2p/go-libp2p/core/peerstore Peerstore" +//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" func TestGracePeriod(t *testing.T) { t.Parallel() diff --git a/p2p/transport/quic/conn_test.go b/p2p/transport/quic/conn_test.go index 4717acad30..6a9d5e9771 100644 --- a/p2p/transport/quic/conn_test.go +++ b/p2p/transport/quic/conn_test.go @@ -28,7 +28,7 @@ import ( "github.com/stretchr/testify/require" ) -//go:generate sh -c "mockgen -package libp2pquic -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater && goimports -w mock_connection_gater_test.go" +//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" type connTestCase struct { Name string diff --git a/p2p/transport/webtransport/transport_test.go b/p2p/transport/webtransport/transport_test.go index 2e5e045d3f..628bdf9fe0 100644 --- a/p2p/transport/webtransport/transport_test.go +++ b/p2p/transport/webtransport/transport_test.go @@ -363,7 +363,7 @@ func TestResourceManagerListening(t *testing.T) { } // TODO: unify somehow. We do the same in libp2pquic. -//go:generate sh -c "mockgen -package libp2pwebtransport_test -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater && goimports -w mock_connection_gater_test.go" +//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" func TestConnectionGaterDialing(t *testing.T) { ctrl := gomock.NewController(t) diff --git a/tools.go b/tools.go new file mode 100644 index 0000000000..9f83ded5c9 --- /dev/null +++ b/tools.go @@ -0,0 +1,10 @@ +//go:build tools +// +build tools + +package libp2p + +import ( + _ "github.com/golang/mock/mockgen" + _ "golang.org/x/tools/cmd/goimports" + _ "google.golang.org/protobuf/cmd/protoc-gen-go" +)