From 889b7b8828abf49096d9ddf7fa418242b58d3635 Mon Sep 17 00:00:00 2001 From: William Banfield <4561443+williambanfield@users.noreply.github.com> Date: Tue, 9 Aug 2022 11:12:31 -0400 Subject: [PATCH] tools: remove mockery from tools.go (#9196) The `mockery` project recommends against using a binary of `mockery` that has been created using `go install`. https://github.com/vektra/mockery/pull/456. Developers of Tendermint wishing to generate mocks should avoid having a version of `mockery` on their path that does not match the version listed in [mockery_generate.sh](https://github.com/tendermint/tendermint/blob/10e1ac8feabd8ce7fd560ebecb11b929376fcb9c/scripts/mockery_generate.sh#L11). To make this easier for developers, the `mockery_generate.sh` script uses a containerized copy of `mockery` if `mockery` is not present on the developer's `PATH`. This containerized version of `mockery` uses the same version of mockery as our CI pipelines and allows all developers to automatically use the same version without having to manage it themselves. #### PR checklist - [ ] Tests written/updated, or no tests needed - [ ] `CHANGELOG_PENDING.md` updated, or no changelog entry needed - [ ] Updated relevant documentation (`docs/`) and code comments, or no documentation updates needed --- .github/workflows/check-generated.yml | 2 -- evidence/mocks/block_store.go | 4 ++-- go.mod | 8 +++++--- go.sum | 3 ++- light/rpc/mocks/light_client.go | 4 ++-- p2p/mocks/peer.go | 4 ++-- proxy/mocks/app_conn_consensus.go | 4 ++-- proxy/mocks/app_conn_mempool.go | 4 ++-- proxy/mocks/app_conn_query.go | 4 ++-- proxy/mocks/app_conn_snapshot.go | 4 ++-- proxy/mocks/client_creator.go | 4 ++-- scripts/mockery_generate.sh | 13 ++----------- state/indexer/mocks/block_indexer.go | 4 ++-- state/mocks/block_store.go | 4 ++-- state/mocks/evidence_pool.go | 4 ++-- state/mocks/store.go | 4 ++-- state/txindex/mocks/tx_indexer.go | 4 ++-- statesync/mocks/state_provider.go | 4 ++-- 18 files changed, 37 insertions(+), 45 deletions(-) diff --git a/.github/workflows/check-generated.yml b/.github/workflows/check-generated.yml index 3055ba43c89..5e4f0b04753 100644 --- a/.github/workflows/check-generated.yml +++ b/.github/workflows/check-generated.yml @@ -26,8 +26,6 @@ jobs: run: | set -euo pipefail - readonly MOCKERY=2.12.3 # N.B. no leading "v" - curl -sL "https://github.com/vektra/mockery/releases/download/v${MOCKERY}/mockery_${MOCKERY}_Linux_x86_64.tar.gz" | tar -C /usr/local/bin -xzf - make mockery 2>/dev/null if ! git diff --stat --exit-code ; then diff --git a/evidence/mocks/block_store.go b/evidence/mocks/block_store.go index b0c67ff8740..e61c4e0aeb7 100644 --- a/evidence/mocks/block_store.go +++ b/evidence/mocks/block_store.go @@ -58,13 +58,13 @@ func (_m *BlockStore) LoadBlockMeta(height int64) *types.BlockMeta { return r0 } -type NewBlockStoreT interface { +type mockConstructorTestingTNewBlockStore interface { mock.TestingT Cleanup(func()) } // NewBlockStore creates a new instance of BlockStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewBlockStore(t NewBlockStoreT) *BlockStore { +func NewBlockStore(t mockConstructorTestingTNewBlockStore) *BlockStore { mock := &BlockStore{} mock.Mock.Test(t) diff --git a/go.mod b/go.mod index 74c26459202..7bab4a30bd9 100644 --- a/go.mod +++ b/go.mod @@ -47,10 +47,12 @@ require ( github.com/pointlander/peg v1.0.1 github.com/prometheus/common v0.37.0 github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca - github.com/vektra/mockery/v2 v2.14.0 ) -require github.com/prometheus/client_model v0.2.0 +require ( + github.com/prometheus/client_model v0.2.0 + github.com/vektra/mockery/v2 v2.14.0 +) require ( 4d63.com/gochecknoglobals v0.1.0 // indirect @@ -111,7 +113,7 @@ require ( github.com/gofrs/flock v0.8.1 // indirect github.com/gofrs/uuid v4.2.0+incompatible // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/golang/snappy v0.0.1 // indirect + github.com/golang/snappy v0.0.3 // indirect github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 // indirect github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a // indirect github.com/golangci/go-misc v0.0.0-20220329215616-d24fe342adfe // indirect diff --git a/go.sum b/go.sum index 5ea33f935ba..fe87df822eb 100644 --- a/go.sum +++ b/go.sum @@ -384,8 +384,9 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= +github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 h1:23T5iq8rbUYlhpt5DB4XJkc6BU31uODLD1o1gKvZmD0= github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2/go.mod h1:k9Qvh+8juN+UKMCS/3jFtGICgW8O96FVaZsaxdzDkR4= github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a h1:w8hkcTqaFpzKqonE9uMCefW1WDie15eSP/4MssdenaM= diff --git a/light/rpc/mocks/light_client.go b/light/rpc/mocks/light_client.go index 25e101c86cc..fabf73b01e8 100644 --- a/light/rpc/mocks/light_client.go +++ b/light/rpc/mocks/light_client.go @@ -100,13 +100,13 @@ func (_m *LightClient) VerifyLightBlockAtHeight(ctx context.Context, height int6 return r0, r1 } -type NewLightClientT interface { +type mockConstructorTestingTNewLightClient interface { mock.TestingT Cleanup(func()) } // NewLightClient creates a new instance of LightClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewLightClient(t NewLightClientT) *LightClient { +func NewLightClient(t mockConstructorTestingTNewLightClient) *LightClient { mock := &LightClient{} mock.Mock.Test(t) diff --git a/p2p/mocks/peer.go b/p2p/mocks/peer.go index f739a0b2126..e195c78bb1f 100644 --- a/p2p/mocks/peer.go +++ b/p2p/mocks/peer.go @@ -330,13 +330,13 @@ func (_m *Peer) TrySend(_a0 byte, _a1 []byte) bool { return r0 } -type NewPeerT interface { +type mockConstructorTestingTNewPeer interface { mock.TestingT Cleanup(func()) } // NewPeer creates a new instance of Peer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewPeer(t NewPeerT) *Peer { +func NewPeer(t mockConstructorTestingTNewPeer) *Peer { mock := &Peer{} mock.Mock.Test(t) diff --git a/proxy/mocks/app_conn_consensus.go b/proxy/mocks/app_conn_consensus.go index 5acd8cac93f..d70cd7cc1eb 100644 --- a/proxy/mocks/app_conn_consensus.go +++ b/proxy/mocks/app_conn_consensus.go @@ -141,13 +141,13 @@ func (_m *AppConnConsensus) SetResponseCallback(_a0 abcicli.Callback) { _m.Called(_a0) } -type NewAppConnConsensusT interface { +type mockConstructorTestingTNewAppConnConsensus interface { mock.TestingT Cleanup(func()) } // NewAppConnConsensus creates a new instance of AppConnConsensus. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewAppConnConsensus(t NewAppConnConsensusT) *AppConnConsensus { +func NewAppConnConsensus(t mockConstructorTestingTNewAppConnConsensus) *AppConnConsensus { mock := &AppConnConsensus{} mock.Mock.Test(t) diff --git a/proxy/mocks/app_conn_mempool.go b/proxy/mocks/app_conn_mempool.go index 87128ce85f9..05e23dd4337 100644 --- a/proxy/mocks/app_conn_mempool.go +++ b/proxy/mocks/app_conn_mempool.go @@ -102,13 +102,13 @@ func (_m *AppConnMempool) SetResponseCallback(_a0 abcicli.Callback) { _m.Called(_a0) } -type NewAppConnMempoolT interface { +type mockConstructorTestingTNewAppConnMempool interface { mock.TestingT Cleanup(func()) } // NewAppConnMempool creates a new instance of AppConnMempool. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewAppConnMempool(t NewAppConnMempoolT) *AppConnMempool { +func NewAppConnMempool(t mockConstructorTestingTNewAppConnMempool) *AppConnMempool { mock := &AppConnMempool{} mock.Mock.Test(t) diff --git a/proxy/mocks/app_conn_query.go b/proxy/mocks/app_conn_query.go index 6560ca0b5be..544ab765ef7 100644 --- a/proxy/mocks/app_conn_query.go +++ b/proxy/mocks/app_conn_query.go @@ -96,13 +96,13 @@ func (_m *AppConnQuery) QuerySync(_a0 types.RequestQuery) (*types.ResponseQuery, return r0, r1 } -type NewAppConnQueryT interface { +type mockConstructorTestingTNewAppConnQuery interface { mock.TestingT Cleanup(func()) } // NewAppConnQuery creates a new instance of AppConnQuery. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewAppConnQuery(t NewAppConnQueryT) *AppConnQuery { +func NewAppConnQuery(t mockConstructorTestingTNewAppConnQuery) *AppConnQuery { mock := &AppConnQuery{} mock.Mock.Test(t) diff --git a/proxy/mocks/app_conn_snapshot.go b/proxy/mocks/app_conn_snapshot.go index a90cd798a32..e3d5cb6cdaa 100644 --- a/proxy/mocks/app_conn_snapshot.go +++ b/proxy/mocks/app_conn_snapshot.go @@ -119,13 +119,13 @@ func (_m *AppConnSnapshot) OfferSnapshotSync(_a0 types.RequestOfferSnapshot) (*t return r0, r1 } -type NewAppConnSnapshotT interface { +type mockConstructorTestingTNewAppConnSnapshot interface { mock.TestingT Cleanup(func()) } // NewAppConnSnapshot creates a new instance of AppConnSnapshot. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewAppConnSnapshot(t NewAppConnSnapshotT) *AppConnSnapshot { +func NewAppConnSnapshot(t mockConstructorTestingTNewAppConnSnapshot) *AppConnSnapshot { mock := &AppConnSnapshot{} mock.Mock.Test(t) diff --git a/proxy/mocks/client_creator.go b/proxy/mocks/client_creator.go index 759b17957ef..eced0aeff60 100644 --- a/proxy/mocks/client_creator.go +++ b/proxy/mocks/client_creator.go @@ -35,13 +35,13 @@ func (_m *ClientCreator) NewABCIClient() (abcicli.Client, error) { return r0, r1 } -type NewClientCreatorT interface { +type mockConstructorTestingTNewClientCreator interface { mock.TestingT Cleanup(func()) } // NewClientCreator creates a new instance of ClientCreator. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewClientCreator(t NewClientCreatorT) *ClientCreator { +func NewClientCreator(t mockConstructorTestingTNewClientCreator) *ClientCreator { mock := &ClientCreator{} mock.Mock.Test(t) diff --git a/scripts/mockery_generate.sh b/scripts/mockery_generate.sh index 2d6f40e6389..2509e0cdbeb 100755 --- a/scripts/mockery_generate.sh +++ b/scripts/mockery_generate.sh @@ -1,15 +1,6 @@ #!/bin/sh # # Invoke Mockery v2 to update generated mocks for the given type. -# -# This script runs a locally-installed "mockery" if available, otherwise it -# runs the published Docker container. This legerdemain is so that the CI build -# and a local build can work off the same script. -# -if ! which mockery ; then - mockery() { - docker run --rm -v "$PWD":/w --workdir=/w vektra/mockery:v2.12.3 - } -fi -mockery --disable-version-string --case underscore --name "$@" +go run github.com/vektra/mockery/v2 --disable-version-string --case underscore --name "$*" + diff --git a/state/indexer/mocks/block_indexer.go b/state/indexer/mocks/block_indexer.go index 583e64d3a17..2c0f0ecb073 100644 --- a/state/indexer/mocks/block_indexer.go +++ b/state/indexer/mocks/block_indexer.go @@ -75,13 +75,13 @@ func (_m *BlockIndexer) Search(ctx context.Context, q *query.Query) ([]int64, er return r0, r1 } -type NewBlockIndexerT interface { +type mockConstructorTestingTNewBlockIndexer interface { mock.TestingT Cleanup(func()) } // NewBlockIndexer creates a new instance of BlockIndexer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewBlockIndexer(t NewBlockIndexerT) *BlockIndexer { +func NewBlockIndexer(t mockConstructorTestingTNewBlockIndexer) *BlockIndexer { mock := &BlockIndexer{} mock.Mock.Test(t) diff --git a/state/mocks/block_store.go b/state/mocks/block_store.go index 20e6a9b1607..4493a6e3f2c 100644 --- a/state/mocks/block_store.go +++ b/state/mocks/block_store.go @@ -193,13 +193,13 @@ func (_m *BlockStore) Size() int64 { return r0 } -type NewBlockStoreT interface { +type mockConstructorTestingTNewBlockStore interface { mock.TestingT Cleanup(func()) } // NewBlockStore creates a new instance of BlockStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewBlockStore(t NewBlockStoreT) *BlockStore { +func NewBlockStore(t mockConstructorTestingTNewBlockStore) *BlockStore { mock := &BlockStore{} mock.Mock.Test(t) diff --git a/state/mocks/evidence_pool.go b/state/mocks/evidence_pool.go index b4d57d04d7d..7279d36f710 100644 --- a/state/mocks/evidence_pool.go +++ b/state/mocks/evidence_pool.go @@ -70,13 +70,13 @@ func (_m *EvidencePool) Update(_a0 state.State, _a1 types.EvidenceList) { _m.Called(_a0, _a1) } -type NewEvidencePoolT interface { +type mockConstructorTestingTNewEvidencePool interface { mock.TestingT Cleanup(func()) } // NewEvidencePool creates a new instance of EvidencePool. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewEvidencePool(t NewEvidencePoolT) *EvidencePool { +func NewEvidencePool(t mockConstructorTestingTNewEvidencePool) *EvidencePool { mock := &EvidencePool{} mock.Mock.Test(t) diff --git a/state/mocks/store.go b/state/mocks/store.go index d02eedb6d1d..13474c023db 100644 --- a/state/mocks/store.go +++ b/state/mocks/store.go @@ -218,13 +218,13 @@ func (_m *Store) SaveABCIResponses(_a0 int64, _a1 *tendermintstate.ABCIResponses return r0 } -type NewStoreT interface { +type mockConstructorTestingTNewStore interface { mock.TestingT Cleanup(func()) } // NewStore creates a new instance of Store. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewStore(t NewStoreT) *Store { +func NewStore(t mockConstructorTestingTNewStore) *Store { mock := &Store{} mock.Mock.Test(t) diff --git a/state/txindex/mocks/tx_indexer.go b/state/txindex/mocks/tx_indexer.go index 210942e2e24..93d0eb9c257 100644 --- a/state/txindex/mocks/tx_indexer.go +++ b/state/txindex/mocks/tx_indexer.go @@ -92,13 +92,13 @@ func (_m *TxIndexer) Search(ctx context.Context, q *query.Query) ([]*types.TxRes return r0, r1 } -type NewTxIndexerT interface { +type mockConstructorTestingTNewTxIndexer interface { mock.TestingT Cleanup(func()) } // NewTxIndexer creates a new instance of TxIndexer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewTxIndexer(t NewTxIndexerT) *TxIndexer { +func NewTxIndexer(t mockConstructorTestingTNewTxIndexer) *TxIndexer { mock := &TxIndexer{} mock.Mock.Test(t) diff --git a/statesync/mocks/state_provider.go b/statesync/mocks/state_provider.go index 5029f615e44..f52b9e33d2d 100644 --- a/statesync/mocks/state_provider.go +++ b/statesync/mocks/state_provider.go @@ -83,13 +83,13 @@ func (_m *StateProvider) State(ctx context.Context, height uint64) (state.State, return r0, r1 } -type NewStateProviderT interface { +type mockConstructorTestingTNewStateProvider interface { mock.TestingT Cleanup(func()) } // NewStateProvider creates a new instance of StateProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewStateProvider(t NewStateProviderT) *StateProvider { +func NewStateProvider(t mockConstructorTestingTNewStateProvider) *StateProvider { mock := &StateProvider{} mock.Mock.Test(t)