From d0af687b65abf65be9894a8b96c73302b10f0994 Mon Sep 17 00:00:00 2001 From: Sergey Date: Sat, 26 Oct 2024 15:26:45 +0300 Subject: [PATCH] chore: add report dispatcher test if error --- pkg/database/stub.go | 5 +++++ pkg/report/dispatcher_test.go | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/pkg/database/stub.go b/pkg/database/stub.go index 76d8a92..1b0e98b 100644 --- a/pkg/database/stub.go +++ b/pkg/database/stub.go @@ -12,6 +12,7 @@ type StubDatabase struct { UpsertProposalError error GetVoteError error UpsertVoteError error + IsMutedError error Proposals map[string]map[string]*types.Proposal Votes map[string]map[string]map[string]*types.Vote @@ -196,6 +197,10 @@ func (d *StubDatabase) DeleteMute(mute *types.Mute) (bool, error) { } func (d *StubDatabase) IsMuted(chain, proposalID string) (bool, error) { + if d.IsMutedError != nil { + return false, d.IsMutedError + } + if d.Mutes == nil { return false, nil } diff --git a/pkg/report/dispatcher_test.go b/pkg/report/dispatcher_test.go index f713139..bf3382c 100644 --- a/pkg/report/dispatcher_test.go +++ b/pkg/report/dispatcher_test.go @@ -2,6 +2,7 @@ package report import ( "context" + "errors" databasePkg "main/pkg/database" "main/pkg/events" "main/pkg/logger" @@ -114,6 +115,26 @@ func TestReportDispatcherSendReportErrorSending(t *testing.T) { }}, context.Background()) } +func TestReportDispatcherSendReportErrorGettingMutes(t *testing.T) { + t.Parallel() + + db := &databasePkg.StubDatabase{IsMutedError: errors.New("mutes error")} + mutesManager := mutes.NewMutesManager(logger.GetNopLogger(), db) + dispatcher := NewDispatcher(logger.GetNopLogger(), mutesManager, []reportersPkg.Reporter{ + &reportersPkg.TestReporter{}, + }, tracing.InitNoopTracer()) + + err := dispatcher.Init() + require.NoError(t, err) + + dispatcher.SendReport(reportersPkg.Report{Entries: []entry.ReportEntry{ + events.NotVotedEvent{ + Chain: &types.Chain{Name: "chain"}, + Proposal: types.Proposal{ID: "proposal"}, + }, + }}, context.Background()) +} + func TestReportDispatcherSendReportOk(t *testing.T) { t.Parallel()