From 128b70f89ddf847f7e2da8dfed0dafc79a26cd46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lewandowski?= Date: Thu, 3 Oct 2024 11:21:28 +0200 Subject: [PATCH] ARCO-209: replace mocks --- internal/callbacker/callbacker.go | 2 +- internal/callbacker/callbacker_mock.go | 32 ++++++++++++------------ internal/callbacker/callbacker_mocks.go | 2 +- internal/callbacker/dispatcher.go | 6 ++--- internal/callbacker/dispatcher_test.go | 2 +- internal/callbacker/send_manager.go | 6 ++--- internal/callbacker/send_manager_test.go | 4 +-- internal/k8s_watcher/watcher_test.go | 4 +-- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/internal/callbacker/callbacker.go b/internal/callbacker/callbacker.go index 6b4e0c39c..2ad4f8b2c 100644 --- a/internal/callbacker/callbacker.go +++ b/internal/callbacker/callbacker.go @@ -4,7 +4,7 @@ import ( "time" ) -type SendInterface interface { +type SendCallbackInterface interface { Send(url, token string, callback *Callback) bool SendBatch(url, token string, callbacks []*Callback) bool } diff --git a/internal/callbacker/callbacker_mock.go b/internal/callbacker/callbacker_mock.go index 9b1e217fe..275c08100 100644 --- a/internal/callbacker/callbacker_mock.go +++ b/internal/callbacker/callbacker_mock.go @@ -7,16 +7,16 @@ import ( "sync" ) -// Ensure, that SendInterfaceMock does implement SendInterface. +// Ensure, that SendCallbackInterfaceMock does implement SendCallbackInterface. // If this is not the case, regenerate this file with moq. -var _ SendInterface = &SendInterfaceMock{} +var _ SendCallbackInterface = &SendCallbackInterfaceMock{} -// SendInterfaceMock is a mock implementation of SendInterface. +// SendCallbackInterfaceMock is a mock implementation of SendCallbackInterface. // -// func TestSomethingThatUsesSendInterface(t *testing.T) { +// func TestSomethingThatUsesSendCallbackInterface(t *testing.T) { // -// // make and configure a mocked SendInterface -// mockedSendInterface := &SendInterfaceMock{ +// // make and configure a mocked SendCallbackInterface +// mockedSendCallbackInterface := &SendCallbackInterfaceMock{ // SendFunc: func(url string, token string, callback *Callback) bool { // panic("mock out the Send method") // }, @@ -25,11 +25,11 @@ var _ SendInterface = &SendInterfaceMock{} // }, // } // -// // use mockedSendInterface in code that requires SendInterface +// // use mockedSendCallbackInterface in code that requires SendCallbackInterface // // and then make assertions. // // } -type SendInterfaceMock struct { +type SendCallbackInterfaceMock struct { // SendFunc mocks the Send method. SendFunc func(url string, token string, callback *Callback) bool @@ -62,9 +62,9 @@ type SendInterfaceMock struct { } // Send calls SendFunc. -func (mock *SendInterfaceMock) Send(url string, token string, callback *Callback) bool { +func (mock *SendCallbackInterfaceMock) Send(url string, token string, callback *Callback) bool { if mock.SendFunc == nil { - panic("SendInterfaceMock.SendFunc: method is nil but SendInterface.Send was just called") + panic("SendCallbackInterfaceMock.SendFunc: method is nil but SendCallbackInterface.Send was just called") } callInfo := struct { URL string @@ -84,8 +84,8 @@ func (mock *SendInterfaceMock) Send(url string, token string, callback *Callback // SendCalls gets all the calls that were made to Send. // Check the length with: // -// len(mockedSendInterface.SendCalls()) -func (mock *SendInterfaceMock) SendCalls() []struct { +// len(mockedSendCallbackInterface.SendCalls()) +func (mock *SendCallbackInterfaceMock) SendCalls() []struct { URL string Token string Callback *Callback @@ -102,9 +102,9 @@ func (mock *SendInterfaceMock) SendCalls() []struct { } // SendBatch calls SendBatchFunc. -func (mock *SendInterfaceMock) SendBatch(url string, token string, callbacks []*Callback) bool { +func (mock *SendCallbackInterfaceMock) SendBatch(url string, token string, callbacks []*Callback) bool { if mock.SendBatchFunc == nil { - panic("SendInterfaceMock.SendBatchFunc: method is nil but SendInterface.SendBatch was just called") + panic("SendCallbackInterfaceMock.SendBatchFunc: method is nil but SendCallbackInterface.SendBatch was just called") } callInfo := struct { URL string @@ -124,8 +124,8 @@ func (mock *SendInterfaceMock) SendBatch(url string, token string, callbacks []* // SendBatchCalls gets all the calls that were made to SendBatch. // Check the length with: // -// len(mockedSendInterface.SendBatchCalls()) -func (mock *SendInterfaceMock) SendBatchCalls() []struct { +// len(mockedSendCallbackInterface.SendBatchCalls()) +func (mock *SendCallbackInterfaceMock) SendBatchCalls() []struct { URL string Token string Callbacks []*Callback diff --git a/internal/callbacker/callbacker_mocks.go b/internal/callbacker/callbacker_mocks.go index a290d54f4..7ab6db93b 100644 --- a/internal/callbacker/callbacker_mocks.go +++ b/internal/callbacker/callbacker_mocks.go @@ -1,4 +1,4 @@ package callbacker // from callbacker.go -//go:generate moq -out ./callbacker_mock.go ./ SendInterface +//go:generate moq -out ./callbacker_mock.go ./ SendCallbackInterface diff --git a/internal/callbacker/dispatcher.go b/internal/callbacker/dispatcher.go index 9e509d364..b7656be2e 100644 --- a/internal/callbacker/dispatcher.go +++ b/internal/callbacker/dispatcher.go @@ -6,7 +6,7 @@ package callbacker The CallbackDispatcher is responsible for routing and dispatching callbacks to appropriate sendManager based on the callback URL. Key components: -- SendInterface Interface: the CallbackDispatcher decorates this interface, enhancing its functionality by managing the actual dispatch logic +- SendCallbackInterface Interface: the CallbackDispatcher decorates this interface, enhancing its functionality by managing the actual dispatch logic - sendManager: each sendManager handles specific types of callbacks, determined by the URL Dispatch Logic: the CallbackDispatcher ensures that callbacks are sent to the correct sendManager, maintaining efficient processing and delivery. @@ -23,7 +23,7 @@ import ( ) type CallbackDispatcher struct { - c SendInterface + c SendCallbackInterface s store.CallbackerStore l *slog.Logger @@ -41,7 +41,7 @@ type CallbackEntry struct { postponedUntil *time.Time } -func NewCallbackDispatcher(callbacker SendInterface, store store.CallbackerStore, logger *slog.Logger, +func NewCallbackDispatcher(callbacker SendCallbackInterface, store store.CallbackerStore, logger *slog.Logger, singleSendPause, batchSendInterval, quarantineBaseDuration, permQuarantineAfterDuration time.Duration) *CallbackDispatcher { return &CallbackDispatcher{ diff --git a/internal/callbacker/dispatcher_test.go b/internal/callbacker/dispatcher_test.go index e6b5620d9..83b41ea1a 100644 --- a/internal/callbacker/dispatcher_test.go +++ b/internal/callbacker/dispatcher_test.go @@ -39,7 +39,7 @@ func TestCallbackDispatcher(t *testing.T) { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { // given - cMq := &CallbackerIMock{ + cMq := &SendCallbackInterfaceMock{ SendFunc: func(_, _ string, _ *Callback) bool { return true }, } diff --git a/internal/callbacker/send_manager.go b/internal/callbacker/send_manager.go index fe79456fe..524a65b4f 100644 --- a/internal/callbacker/send_manager.go +++ b/internal/callbacker/send_manager.go @@ -14,7 +14,7 @@ The manager operates in various modes: It processes callbacks from two channels, ensuring either single or batch dispatch, and manages retries based on a quarantine policy. Key components: -- SendInterface : responsible for sending callbacks +- SendCallbackInterface : responsible for sending callbacks - quarantine policy: the duration for quarantining a URL are governed by a configurable policy, determining how long the URL remains inactive before retry attempts Sending logic: callbacks are sent to the designated URL one at a time, ensuring sequential and orderly processing. @@ -40,7 +40,7 @@ type sendManager struct { url string // dependencies - c SendInterface + c SendCallbackInterface s store.CallbackerStore l *slog.Logger q *quarantinePolicy @@ -68,7 +68,7 @@ const ( StoppingMode ) -func runNewSendManager(u string, c SendInterface, s store.CallbackerStore, l *slog.Logger, q *quarantinePolicy, +func runNewSendManager(u string, c SendCallbackInterface, s store.CallbackerStore, l *slog.Logger, q *quarantinePolicy, singleSendSleep, batchSendInterval time.Duration) *sendManager { const defaultBatchSendInterval = time.Duration(5 * time.Second) diff --git a/internal/callbacker/send_manager_test.go b/internal/callbacker/send_manager_test.go index fc86653d2..5aca6a84f 100644 --- a/internal/callbacker/send_manager_test.go +++ b/internal/callbacker/send_manager_test.go @@ -62,7 +62,7 @@ func TestSendManager(t *testing.T) { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { // given - cMq := &CallbackerIMock{ + cMq := &SendCallbackInterfaceMock{ SendFunc: func(_, _ string, _ *Callback) bool { return true }, SendBatchFunc: func(_, _ string, _ []*Callback) bool { return true }, } @@ -163,7 +163,7 @@ func TestSendManager_Quarantine(t *testing.T) { // given sendOK := true - senderMq := &CallbackerIMock{ + senderMq := &SendCallbackInterfaceMock{ SendFunc: func(_, _ string, _ *Callback) bool { return sendOK }, SendBatchFunc: func(_, _ string, _ []*Callback) bool { return sendOK }, } diff --git a/internal/k8s_watcher/watcher_test.go b/internal/k8s_watcher/watcher_test.go index e813bed31..8ed2e577e 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.BlocktxClientMock{} + blocktxMock := &btxMocks.BlockClientMock{} 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.BlocktxClientMock{ + blocktxMock := &btxMocks.BlockClientMock{ DelUnfinishedBlockProcessingFunc: func(_ context.Context, _ string) (int64, error) { return 0, nil }, }