From 04a28ed4e06f4dbebcdeb56c400890768e7ff1c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lewandowski?= Date: Wed, 30 Oct 2024 13:20:16 +0100 Subject: [PATCH] ARCO-209: fix PR comments --- internal/k8s_watcher/watcher.go | 4 +- internal/k8s_watcher/watcher_test.go | 4 +- pkg/blocktx/client.go | 4 +- pkg/blocktx/client_mocks.go | 2 +- pkg/blocktx/mocks/blocktx_client_mock.go | 56 ++++++++++++------------ 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/internal/k8s_watcher/watcher.go b/internal/k8s_watcher/watcher.go index dd27e502b..e15948771 100644 --- a/internal/k8s_watcher/watcher.go +++ b/internal/k8s_watcher/watcher.go @@ -28,7 +28,7 @@ type K8sClient interface { type Watcher struct { metamorphClient metamorph.TransactionMaintainer - blocktxClient blocktx.BlockClient + blocktxClient blocktx.Watcher k8sClient K8sClient logger *slog.Logger tickerMetamorph Ticker @@ -55,7 +55,7 @@ func WithRetryInterval(d time.Duration) func(*Watcher) { type ServerOption func(f *Watcher) // New The K8s watcher listens to events coming from Kubernetes. If it detects a metamorph pod which was terminated, then it sets records locked by this pod to unlocked. This is a safety measure for the case that metamorph is terminated ungracefully where it misses to unlock its records itself. -func New(metamorphClient metamorph.TransactionMaintainer, blocktxClient blocktx.BlockClient, k8sClient K8sClient, namespace string, opts ...ServerOption) *Watcher { +func New(metamorphClient metamorph.TransactionMaintainer, blocktxClient blocktx.Watcher, k8sClient K8sClient, namespace string, opts ...ServerOption) *Watcher { watcher := &Watcher{ metamorphClient: metamorphClient, blocktxClient: blocktxClient, diff --git a/internal/k8s_watcher/watcher_test.go b/internal/k8s_watcher/watcher_test.go index 35a9b9da5..04958f681 100644 --- a/internal/k8s_watcher/watcher_test.go +++ b/internal/k8s_watcher/watcher_test.go @@ -69,7 +69,7 @@ func TestStartMetamorphWatcher(t *testing.T) { return 3, nil }, } - blocktxMock := &btxMocks.BlockClientMock{} + blocktxMock := &btxMocks.WatcherMock{} iteration := 0 getPodNamesErrTest := tc.getPodNamesErr @@ -157,7 +157,7 @@ func TestStartBlocktxWatcher(t *testing.T) { for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { metamorphMock := &mtmMocks.TransactionMaintainerMock{} - blocktxMock := &btxMocks.BlockClientMock{ + blocktxMock := &btxMocks.WatcherMock{ DelUnfinishedBlockProcessingFunc: func(_ context.Context, _ string) (int64, error) { return 0, nil }, } diff --git a/pkg/blocktx/client.go b/pkg/blocktx/client.go index e01534fc1..995716ce1 100644 --- a/pkg/blocktx/client.go +++ b/pkg/blocktx/client.go @@ -10,10 +10,10 @@ import ( ) // check if Client implements all necessary interfaces -var _ BlockClient = &Client{} +var _ Watcher = &Client{} var _ MerkleRootsVerifier = &Client{} -type BlockClient interface { +type Watcher interface { Health(ctx context.Context) error ClearTransactions(ctx context.Context, retentionDays int32) (int64, error) ClearBlocks(ctx context.Context, retentionDays int32) (int64, error) diff --git a/pkg/blocktx/client_mocks.go b/pkg/blocktx/client_mocks.go index 239c96bf4..cde4ee8a7 100644 --- a/pkg/blocktx/client_mocks.go +++ b/pkg/blocktx/client_mocks.go @@ -2,4 +2,4 @@ package blocktx //go:generate moq -pkg mocks -out ./mocks/merkle_roots_verifier_mock.go . MerkleRootsVerifier -//go:generate moq -pkg mocks -out ./mocks/blocktx_client_mock.go . BlockClient +//go:generate moq -pkg mocks -out ./mocks/blocktx_client_mock.go . Watcher diff --git a/pkg/blocktx/mocks/blocktx_client_mock.go b/pkg/blocktx/mocks/blocktx_client_mock.go index 9778b87e2..ccaeaa40e 100644 --- a/pkg/blocktx/mocks/blocktx_client_mock.go +++ b/pkg/blocktx/mocks/blocktx_client_mock.go @@ -9,16 +9,16 @@ import ( "sync" ) -// Ensure, that BlockClientMock does implement blocktx.BlockClient. +// Ensure, that WatcherMock does implement blocktx.Watcher. // If this is not the case, regenerate this file with moq. -var _ blocktx.BlockClient = &BlockClientMock{} +var _ blocktx.Watcher = &WatcherMock{} -// BlockClientMock is a mock implementation of blocktx.BlockClient. +// WatcherMock is a mock implementation of blocktx.Watcher. // -// func TestSomethingThatUsesBlockClient(t *testing.T) { +// func TestSomethingThatUsesWatcher(t *testing.T) { // -// // make and configure a mocked blocktx.BlockClient -// mockedBlockClient := &BlockClientMock{ +// // make and configure a mocked blocktx.Watcher +// mockedWatcher := &WatcherMock{ // ClearBlockTransactionsMapFunc: func(ctx context.Context, retentionDays int32) (int64, error) { // panic("mock out the ClearBlockTransactionsMap method") // }, @@ -36,11 +36,11 @@ var _ blocktx.BlockClient = &BlockClientMock{} // }, // } // -// // use mockedBlockClient in code that requires blocktx.BlockClient +// // use mockedWatcher in code that requires blocktx.Watcher // // and then make assertions. // // } -type BlockClientMock struct { +type WatcherMock struct { // ClearBlockTransactionsMapFunc mocks the ClearBlockTransactionsMap method. ClearBlockTransactionsMapFunc func(ctx context.Context, retentionDays int32) (int64, error) @@ -100,9 +100,9 @@ type BlockClientMock struct { } // ClearBlockTransactionsMap calls ClearBlockTransactionsMapFunc. -func (mock *BlockClientMock) ClearBlockTransactionsMap(ctx context.Context, retentionDays int32) (int64, error) { +func (mock *WatcherMock) ClearBlockTransactionsMap(ctx context.Context, retentionDays int32) (int64, error) { if mock.ClearBlockTransactionsMapFunc == nil { - panic("BlockClientMock.ClearBlockTransactionsMapFunc: method is nil but BlockClient.ClearBlockTransactionsMap was just called") + panic("WatcherMock.ClearBlockTransactionsMapFunc: method is nil but Watcher.ClearBlockTransactionsMap was just called") } callInfo := struct { Ctx context.Context @@ -120,8 +120,8 @@ func (mock *BlockClientMock) ClearBlockTransactionsMap(ctx context.Context, rete // ClearBlockTransactionsMapCalls gets all the calls that were made to ClearBlockTransactionsMap. // Check the length with: // -// len(mockedBlockClient.ClearBlockTransactionsMapCalls()) -func (mock *BlockClientMock) ClearBlockTransactionsMapCalls() []struct { +// len(mockedWatcher.ClearBlockTransactionsMapCalls()) +func (mock *WatcherMock) ClearBlockTransactionsMapCalls() []struct { Ctx context.Context RetentionDays int32 } { @@ -136,9 +136,9 @@ func (mock *BlockClientMock) ClearBlockTransactionsMapCalls() []struct { } // ClearBlocks calls ClearBlocksFunc. -func (mock *BlockClientMock) ClearBlocks(ctx context.Context, retentionDays int32) (int64, error) { +func (mock *WatcherMock) ClearBlocks(ctx context.Context, retentionDays int32) (int64, error) { if mock.ClearBlocksFunc == nil { - panic("BlockClientMock.ClearBlocksFunc: method is nil but BlockClient.ClearBlocks was just called") + panic("WatcherMock.ClearBlocksFunc: method is nil but Watcher.ClearBlocks was just called") } callInfo := struct { Ctx context.Context @@ -156,8 +156,8 @@ func (mock *BlockClientMock) ClearBlocks(ctx context.Context, retentionDays int3 // ClearBlocksCalls gets all the calls that were made to ClearBlocks. // Check the length with: // -// len(mockedBlockClient.ClearBlocksCalls()) -func (mock *BlockClientMock) ClearBlocksCalls() []struct { +// len(mockedWatcher.ClearBlocksCalls()) +func (mock *WatcherMock) ClearBlocksCalls() []struct { Ctx context.Context RetentionDays int32 } { @@ -172,9 +172,9 @@ func (mock *BlockClientMock) ClearBlocksCalls() []struct { } // ClearTransactions calls ClearTransactionsFunc. -func (mock *BlockClientMock) ClearTransactions(ctx context.Context, retentionDays int32) (int64, error) { +func (mock *WatcherMock) ClearTransactions(ctx context.Context, retentionDays int32) (int64, error) { if mock.ClearTransactionsFunc == nil { - panic("BlockClientMock.ClearTransactionsFunc: method is nil but BlockClient.ClearTransactions was just called") + panic("WatcherMock.ClearTransactionsFunc: method is nil but Watcher.ClearTransactions was just called") } callInfo := struct { Ctx context.Context @@ -192,8 +192,8 @@ func (mock *BlockClientMock) ClearTransactions(ctx context.Context, retentionDay // ClearTransactionsCalls gets all the calls that were made to ClearTransactions. // Check the length with: // -// len(mockedBlockClient.ClearTransactionsCalls()) -func (mock *BlockClientMock) ClearTransactionsCalls() []struct { +// len(mockedWatcher.ClearTransactionsCalls()) +func (mock *WatcherMock) ClearTransactionsCalls() []struct { Ctx context.Context RetentionDays int32 } { @@ -208,9 +208,9 @@ func (mock *BlockClientMock) ClearTransactionsCalls() []struct { } // DelUnfinishedBlockProcessing calls DelUnfinishedBlockProcessingFunc. -func (mock *BlockClientMock) DelUnfinishedBlockProcessing(ctx context.Context, processedBy string) (int64, error) { +func (mock *WatcherMock) DelUnfinishedBlockProcessing(ctx context.Context, processedBy string) (int64, error) { if mock.DelUnfinishedBlockProcessingFunc == nil { - panic("BlockClientMock.DelUnfinishedBlockProcessingFunc: method is nil but BlockClient.DelUnfinishedBlockProcessing was just called") + panic("WatcherMock.DelUnfinishedBlockProcessingFunc: method is nil but Watcher.DelUnfinishedBlockProcessing was just called") } callInfo := struct { Ctx context.Context @@ -228,8 +228,8 @@ func (mock *BlockClientMock) DelUnfinishedBlockProcessing(ctx context.Context, p // DelUnfinishedBlockProcessingCalls gets all the calls that were made to DelUnfinishedBlockProcessing. // Check the length with: // -// len(mockedBlockClient.DelUnfinishedBlockProcessingCalls()) -func (mock *BlockClientMock) DelUnfinishedBlockProcessingCalls() []struct { +// len(mockedWatcher.DelUnfinishedBlockProcessingCalls()) +func (mock *WatcherMock) DelUnfinishedBlockProcessingCalls() []struct { Ctx context.Context ProcessedBy string } { @@ -244,9 +244,9 @@ func (mock *BlockClientMock) DelUnfinishedBlockProcessingCalls() []struct { } // Health calls HealthFunc. -func (mock *BlockClientMock) Health(ctx context.Context) error { +func (mock *WatcherMock) Health(ctx context.Context) error { if mock.HealthFunc == nil { - panic("BlockClientMock.HealthFunc: method is nil but BlockClient.Health was just called") + panic("WatcherMock.HealthFunc: method is nil but Watcher.Health was just called") } callInfo := struct { Ctx context.Context @@ -262,8 +262,8 @@ func (mock *BlockClientMock) Health(ctx context.Context) error { // HealthCalls gets all the calls that were made to Health. // Check the length with: // -// len(mockedBlockClient.HealthCalls()) -func (mock *BlockClientMock) HealthCalls() []struct { +// len(mockedWatcher.HealthCalls()) +func (mock *WatcherMock) HealthCalls() []struct { Ctx context.Context } { var calls []struct {