Skip to content

Commit

Permalink
chore: add report dispatcher test if error
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Oct 26, 2024
1 parent e31f21c commit d0af687
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/database/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/report/dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package report

import (
"context"
"errors"
databasePkg "main/pkg/database"
"main/pkg/events"
"main/pkg/logger"
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit d0af687

Please sign in to comment.