From ad081eed714217f9678dad715677da71b6647a75 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Tue, 7 Nov 2023 21:13:53 +0100 Subject: [PATCH] [Testing, Docs] refactor: move /internal/... to /testutil/... for godocs (#153) * refactor: move /internal pkgs to /testutil * chore: cleanup --- internal/mocks/mocks.go | 10 ---------- pkg/client/block/client_integration_test.go | 2 +- pkg/client/block/client_test.go | 4 ++-- pkg/client/events_query/client_integration_test.go | 2 +- pkg/client/events_query/client_test.go | 9 +++++---- pkg/client/interface.go | 12 ++++++------ pkg/client/supplier/client_integration_test.go | 2 +- pkg/client/supplier/client_test.go | 7 ++++--- pkg/client/tx/client_integration_test.go | 8 ++++---- pkg/client/tx/client_test.go | 13 +++++++------ pkg/observable/channel/observable_test.go | 4 ++-- pkg/observable/channel/replay_test.go | 2 +- {internal/mocks => testutil}/mockclient/mocks.go | 0 {internal => testutil}/testchannel/drain.go | 0 {internal => testutil}/testclient/keyring.go | 0 {internal => testutil}/testclient/localnet.go | 0 .../testclient/testblock/client.go | 7 ++++--- .../testclient/testblock/godoc.go | 0 .../testclient/testeventsquery/client.go | 5 +++-- .../testclient/testeventsquery/connection.go | 2 +- .../testclient/testeventsquery/godoc.go | 0 .../testclient/testkeyring/keyring.go | 2 +- .../testclient/testsupplier/client.go | 2 +- {internal => testutil}/testclient/testtx/client.go | 7 ++++--- {internal => testutil}/testclient/testtx/context.go | 5 +++-- {internal => testutil}/testerrors/require.go | 0 26 files changed, 51 insertions(+), 54 deletions(-) delete mode 100644 internal/mocks/mocks.go rename {internal/mocks => testutil}/mockclient/mocks.go (100%) rename {internal => testutil}/testchannel/drain.go (100%) rename {internal => testutil}/testclient/keyring.go (100%) rename {internal => testutil}/testclient/localnet.go (100%) rename {internal => testutil}/testclient/testblock/client.go (95%) rename {internal => testutil}/testclient/testblock/godoc.go (100%) rename {internal => testutil}/testclient/testeventsquery/client.go (97%) rename {internal => testutil}/testclient/testeventsquery/connection.go (95%) rename {internal => testutil}/testclient/testeventsquery/godoc.go (100%) rename {internal => testutil}/testclient/testkeyring/keyring.go (88%) rename {internal => testutil}/testclient/testsupplier/client.go (93%) rename {internal => testutil}/testclient/testtx/client.go (93%) rename {internal => testutil}/testclient/testtx/context.go (98%) rename {internal => testutil}/testerrors/require.go (100%) diff --git a/internal/mocks/mocks.go b/internal/mocks/mocks.go deleted file mode 100644 index 423f63d3e..000000000 --- a/internal/mocks/mocks.go +++ /dev/null @@ -1,10 +0,0 @@ -package mocks - -// This file is in place to declare the package for dynamically generated structs. -// -// Note that this does not follow the Cosmos SDK pattern of committing Mocks to main. -// For example, they commit auto-generate code to main: https://github.com/cosmos/cosmos-sdk/blob/main/x/gov/testutil/expected_keepers_mocks.go -// Documentation on how Cosmos uses mockgen can be found here: https://docs.cosmos.network/main/build/building-modules/testing#unit-tests -// -// IMPORTANT: We have attempted to use `.gitkeep` files instead, but it causes a circular dependency issue with protobuf and mock generation -// since we are leveraging `ignite` to compile `.proto` files which requires `.go` files to compile. diff --git a/pkg/client/block/client_integration_test.go b/pkg/client/block/client_integration_test.go index fd7e633ab..c242d7474 100644 --- a/pkg/client/block/client_integration_test.go +++ b/pkg/client/block/client_integration_test.go @@ -12,8 +12,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/internal/testclient/testblock" "github.com/pokt-network/poktroll/pkg/client" + "github.com/pokt-network/poktroll/testutil/testclient/testblock" ) const blockIntegrationSubTimeout = 5 * time.Second diff --git a/pkg/client/block/client_test.go b/pkg/client/block/client_test.go index b2a5515b3..768fa59f9 100644 --- a/pkg/client/block/client_test.go +++ b/pkg/client/block/client_test.go @@ -10,10 +10,10 @@ import ( comettypes "github.com/cometbft/cometbft/types" "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/internal/testclient" - "github.com/pokt-network/poktroll/internal/testclient/testeventsquery" "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/block" + "github.com/pokt-network/poktroll/testutil/testclient" + "github.com/pokt-network/poktroll/testutil/testclient/testeventsquery" ) const ( diff --git a/pkg/client/events_query/client_integration_test.go b/pkg/client/events_query/client_integration_test.go index 05bf09c1a..a6a0e3bcd 100644 --- a/pkg/client/events_query/client_integration_test.go +++ b/pkg/client/events_query/client_integration_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/internal/testclient/testeventsquery" + "github.com/pokt-network/poktroll/testutil/testclient/testeventsquery" ) // The query use to subscribe for new block events on the websocket endpoint exposed by CometBFT nodes diff --git a/pkg/client/events_query/client_test.go b/pkg/client/events_query/client_test.go index 0ba52ec88..aae5f72d2 100644 --- a/pkg/client/events_query/client_test.go +++ b/pkg/client/events_query/client_test.go @@ -13,14 +13,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/internal/mocks/mockclient" - "github.com/pokt-network/poktroll/internal/testchannel" - "github.com/pokt-network/poktroll/internal/testclient/testeventsquery" - "github.com/pokt-network/poktroll/internal/testerrors" + "github.com/pokt-network/poktroll/testutil/mockclient" + eventsquery "github.com/pokt-network/poktroll/pkg/client/events_query" "github.com/pokt-network/poktroll/pkg/client/events_query/websocket" "github.com/pokt-network/poktroll/pkg/either" "github.com/pokt-network/poktroll/pkg/observable" + "github.com/pokt-network/poktroll/testutil/testchannel" + "github.com/pokt-network/poktroll/testutil/testclient/testeventsquery" + "github.com/pokt-network/poktroll/testutil/testerrors" ) func TestEventsQueryClient_Subscribe_Succeeds(t *testing.T) { diff --git a/pkg/client/interface.go b/pkg/client/interface.go index c088df35c..1a9bcb500 100644 --- a/pkg/client/interface.go +++ b/pkg/client/interface.go @@ -1,9 +1,9 @@ -//go:generate mockgen -destination=../../internal/mocks/mockclient/events_query_client_mock.go -package=mockclient . Dialer,Connection,EventsQueryClient -//go:generate mockgen -destination=../../internal/mocks/mockclient/block_client_mock.go -package=mockclient . Block,BlockClient -//go:generate mockgen -destination=../../internal/mocks/mockclient/tx_client_mock.go -package=mockclient . TxContext,TxClient -//go:generate mockgen -destination=../../internal/mocks/mockclient/cosmos_tx_builder_mock.go -package=mockclient github.com/cosmos/cosmos-sdk/client TxBuilder -//go:generate mockgen -destination=../../internal/mocks/mockclient/cosmos_keyring_mock.go -package=mockclient github.com/cosmos/cosmos-sdk/crypto/keyring Keyring -//go:generate mockgen -destination=../../internal/mocks/mockclient/cosmos_client_mock.go -package=mockclient github.com/cosmos/cosmos-sdk/client AccountRetriever +//go:generate mockgen -destination=../../testutil/mockclient/events_query_client_mock.go -package=mockclient . Dialer,Connection,EventsQueryClient +//go:generate mockgen -destination=../../testutil/mockclient/block_client_mock.go -package=mockclient . Block,BlockClient +//go:generate mockgen -destination=../../testutil/mockclient/tx_client_mock.go -package=mockclient . TxContext,TxClient +//go:generate mockgen -destination=../../testutil/mockclient/cosmos_tx_builder_mock.go -package=mockclient github.com/cosmos/cosmos-sdk/client TxBuilder +//go:generate mockgen -destination=../../testutil/mockclient/cosmos_keyring_mock.go -package=mockclient github.com/cosmos/cosmos-sdk/crypto/keyring Keyring +//go:generate mockgen -destination=../../testutil/mockclient/cosmos_client_mock.go -package=mockclient github.com/cosmos/cosmos-sdk/client AccountRetriever package client diff --git a/pkg/client/supplier/client_integration_test.go b/pkg/client/supplier/client_integration_test.go index 8af759186..f7ea11f56 100644 --- a/pkg/client/supplier/client_integration_test.go +++ b/pkg/client/supplier/client_integration_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/internal/testclient/testsupplier" + "github.com/pokt-network/poktroll/testutil/testclient/testsupplier" sessiontypes "github.com/pokt-network/poktroll/x/session/types" ) diff --git a/pkg/client/supplier/client_test.go b/pkg/client/supplier/client_test.go index 9cb6e85c6..830426946 100644 --- a/pkg/client/supplier/client_test.go +++ b/pkg/client/supplier/client_test.go @@ -11,11 +11,12 @@ import ( "github.com/pokt-network/smt" "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/internal/mocks/mockclient" - "github.com/pokt-network/poktroll/internal/testclient/testkeyring" - "github.com/pokt-network/poktroll/internal/testclient/testtx" + "github.com/pokt-network/poktroll/testutil/mockclient" + "github.com/pokt-network/poktroll/pkg/client/keyring" "github.com/pokt-network/poktroll/pkg/client/supplier" + "github.com/pokt-network/poktroll/testutil/testclient/testkeyring" + "github.com/pokt-network/poktroll/testutil/testclient/testtx" sessiontypes "github.com/pokt-network/poktroll/x/session/types" ) diff --git a/pkg/client/tx/client_integration_test.go b/pkg/client/tx/client_integration_test.go index 737c8a628..2716e9f64 100644 --- a/pkg/client/tx/client_integration_test.go +++ b/pkg/client/tx/client_integration_test.go @@ -10,12 +10,12 @@ import ( "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/internal/testclient/testkeyring" "github.com/pokt-network/poktroll/pkg/client/tx" + "github.com/pokt-network/poktroll/testutil/testclient/testblock" + "github.com/pokt-network/poktroll/testutil/testclient/testeventsquery" + "github.com/pokt-network/poktroll/testutil/testclient/testkeyring" + "github.com/pokt-network/poktroll/testutil/testclient/testtx" - "github.com/pokt-network/poktroll/internal/testclient/testblock" - "github.com/pokt-network/poktroll/internal/testclient/testeventsquery" - "github.com/pokt-network/poktroll/internal/testclient/testtx" "github.com/pokt-network/poktroll/pkg/client" apptypes "github.com/pokt-network/poktroll/x/application/types" ) diff --git a/pkg/client/tx/client_test.go b/pkg/client/tx/client_test.go index f6f1d08a9..bb4f78f6b 100644 --- a/pkg/client/tx/client_test.go +++ b/pkg/client/tx/client_test.go @@ -13,16 +13,17 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/internal/mocks/mockclient" - "github.com/pokt-network/poktroll/internal/testclient" - "github.com/pokt-network/poktroll/internal/testclient/testblock" - "github.com/pokt-network/poktroll/internal/testclient/testeventsquery" - "github.com/pokt-network/poktroll/internal/testclient/testkeyring" - "github.com/pokt-network/poktroll/internal/testclient/testtx" + "github.com/pokt-network/poktroll/testutil/mockclient" + "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/keyring" "github.com/pokt-network/poktroll/pkg/client/tx" "github.com/pokt-network/poktroll/pkg/either" + "github.com/pokt-network/poktroll/testutil/testclient" + "github.com/pokt-network/poktroll/testutil/testclient/testblock" + "github.com/pokt-network/poktroll/testutil/testclient/testeventsquery" + "github.com/pokt-network/poktroll/testutil/testclient/testkeyring" + "github.com/pokt-network/poktroll/testutil/testclient/testtx" apptypes "github.com/pokt-network/poktroll/x/application/types" ) diff --git a/pkg/observable/channel/observable_test.go b/pkg/observable/channel/observable_test.go index cb89c79d8..b278546fc 100644 --- a/pkg/observable/channel/observable_test.go +++ b/pkg/observable/channel/observable_test.go @@ -10,10 +10,10 @@ import ( "github.com/stretchr/testify/require" "golang.org/x/sync/errgroup" - "github.com/pokt-network/poktroll/internal/testchannel" - "github.com/pokt-network/poktroll/internal/testerrors" "github.com/pokt-network/poktroll/pkg/observable" "github.com/pokt-network/poktroll/pkg/observable/channel" + "github.com/pokt-network/poktroll/testutil/testchannel" + "github.com/pokt-network/poktroll/testutil/testerrors" ) const ( diff --git a/pkg/observable/channel/replay_test.go b/pkg/observable/channel/replay_test.go index 0f9b3e9ac..6e01f123e 100644 --- a/pkg/observable/channel/replay_test.go +++ b/pkg/observable/channel/replay_test.go @@ -8,8 +8,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/internal/testerrors" "github.com/pokt-network/poktroll/pkg/observable/channel" + "github.com/pokt-network/poktroll/testutil/testerrors" ) func TestReplayObservable(t *testing.T) { diff --git a/internal/mocks/mockclient/mocks.go b/testutil/mockclient/mocks.go similarity index 100% rename from internal/mocks/mockclient/mocks.go rename to testutil/mockclient/mocks.go diff --git a/internal/testchannel/drain.go b/testutil/testchannel/drain.go similarity index 100% rename from internal/testchannel/drain.go rename to testutil/testchannel/drain.go diff --git a/internal/testclient/keyring.go b/testutil/testclient/keyring.go similarity index 100% rename from internal/testclient/keyring.go rename to testutil/testclient/keyring.go diff --git a/internal/testclient/localnet.go b/testutil/testclient/localnet.go similarity index 100% rename from internal/testclient/localnet.go rename to testutil/testclient/localnet.go diff --git a/internal/testclient/testblock/client.go b/testutil/testclient/testblock/client.go similarity index 95% rename from internal/testclient/testblock/client.go rename to testutil/testclient/testblock/client.go index ebd2ebcd7..7fc1a0341 100644 --- a/internal/testclient/testblock/client.go +++ b/testutil/testclient/testblock/client.go @@ -8,12 +8,13 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/internal/mocks/mockclient" - "github.com/pokt-network/poktroll/internal/testclient" - "github.com/pokt-network/poktroll/internal/testclient/testeventsquery" + "github.com/pokt-network/poktroll/testutil/mockclient" + "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/block" "github.com/pokt-network/poktroll/pkg/observable/channel" + "github.com/pokt-network/poktroll/testutil/testclient" + "github.com/pokt-network/poktroll/testutil/testclient/testeventsquery" ) // NewLocalnetClient creates and returns a new BlockClient that's configured for diff --git a/internal/testclient/testblock/godoc.go b/testutil/testclient/testblock/godoc.go similarity index 100% rename from internal/testclient/testblock/godoc.go rename to testutil/testclient/testblock/godoc.go diff --git a/internal/testclient/testeventsquery/client.go b/testutil/testclient/testeventsquery/client.go similarity index 97% rename from internal/testclient/testeventsquery/client.go rename to testutil/testclient/testeventsquery/client.go index fbf7daeb1..3ce867fde 100644 --- a/internal/testclient/testeventsquery/client.go +++ b/testutil/testclient/testeventsquery/client.go @@ -10,12 +10,13 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/internal/mocks/mockclient" - "github.com/pokt-network/poktroll/internal/testclient" + "github.com/pokt-network/poktroll/testutil/mockclient" + "github.com/pokt-network/poktroll/pkg/client" eventsquery "github.com/pokt-network/poktroll/pkg/client/events_query" "github.com/pokt-network/poktroll/pkg/either" "github.com/pokt-network/poktroll/pkg/observable/channel" + "github.com/pokt-network/poktroll/testutil/testclient" ) // NewLocalnetClient creates and returns a new events query client that's configured diff --git a/internal/testclient/testeventsquery/connection.go b/testutil/testclient/testeventsquery/connection.go similarity index 95% rename from internal/testclient/testeventsquery/connection.go rename to testutil/testclient/testeventsquery/connection.go index 27a38f2ae..c8af4e6ad 100644 --- a/internal/testclient/testeventsquery/connection.go +++ b/testutil/testclient/testeventsquery/connection.go @@ -5,8 +5,8 @@ import ( "github.com/golang/mock/gomock" - "github.com/pokt-network/poktroll/internal/mocks/mockclient" "github.com/pokt-network/poktroll/pkg/either" + "github.com/pokt-network/poktroll/testutil/mockclient" ) // NewOneTimeMockConnAndDialer returns a new mock connection and mock dialer that diff --git a/internal/testclient/testeventsquery/godoc.go b/testutil/testclient/testeventsquery/godoc.go similarity index 100% rename from internal/testclient/testeventsquery/godoc.go rename to testutil/testclient/testeventsquery/godoc.go diff --git a/internal/testclient/testkeyring/keyring.go b/testutil/testclient/testkeyring/keyring.go similarity index 88% rename from internal/testclient/testkeyring/keyring.go rename to testutil/testclient/testkeyring/keyring.go index 40fbc64c8..bb83baf88 100644 --- a/internal/testclient/testkeyring/keyring.go +++ b/testutil/testclient/testkeyring/keyring.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/pokt-network/poktroll/internal/testclient" + "github.com/pokt-network/poktroll/testutil/testclient" ) // NewTestKeyringWithKey creates a new in-memory keyring with a test key diff --git a/internal/testclient/testsupplier/client.go b/testutil/testclient/testsupplier/client.go similarity index 93% rename from internal/testclient/testsupplier/client.go rename to testutil/testclient/testsupplier/client.go index be5df6507..f5ee73969 100644 --- a/internal/testclient/testsupplier/client.go +++ b/testutil/testclient/testsupplier/client.go @@ -6,10 +6,10 @@ import ( "cosmossdk.io/depinject" "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/internal/testclient/testtx" "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/supplier" "github.com/pokt-network/poktroll/pkg/client/tx" + "github.com/pokt-network/poktroll/testutil/testclient/testtx" ) // NewLocalnetClient creates and returns a new supplier client that connects to diff --git a/internal/testclient/testtx/client.go b/testutil/testclient/testtx/client.go similarity index 93% rename from internal/testclient/testtx/client.go rename to testutil/testclient/testtx/client.go index 3e843dd91..496c99023 100644 --- a/internal/testclient/testtx/client.go +++ b/testutil/testclient/testtx/client.go @@ -10,12 +10,13 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/internal/mocks/mockclient" - "github.com/pokt-network/poktroll/internal/testclient/testblock" - "github.com/pokt-network/poktroll/internal/testclient/testeventsquery" + "github.com/pokt-network/poktroll/testutil/mockclient" + "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/tx" "github.com/pokt-network/poktroll/pkg/either" + "github.com/pokt-network/poktroll/testutil/testclient/testblock" + "github.com/pokt-network/poktroll/testutil/testclient/testeventsquery" ) type signAndBroadcastFn func(context.Context, cosmostypes.Msg) either.AsyncError diff --git a/internal/testclient/testtx/context.go b/testutil/testclient/testtx/context.go similarity index 98% rename from internal/testclient/testtx/context.go rename to testutil/testclient/testtx/context.go index 134d7b2c4..35b3dfb71 100644 --- a/internal/testclient/testtx/context.go +++ b/testutil/testclient/testtx/context.go @@ -17,10 +17,11 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/internal/mocks/mockclient" - "github.com/pokt-network/poktroll/internal/testclient" + "github.com/pokt-network/poktroll/testutil/mockclient" + "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/tx" + "github.com/pokt-network/poktroll/testutil/testclient" ) // NewLocalnetContext creates and returns a new transaction context configured diff --git a/internal/testerrors/require.go b/testutil/testerrors/require.go similarity index 100% rename from internal/testerrors/require.go rename to testutil/testerrors/require.go