Skip to content

Commit

Permalink
add mongo client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jackchuma committed Nov 21, 2024
1 parent ae1c796 commit f19cea0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion services/go-filler/log-fetcher/internal/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Main(ctx *cli.Context) error {
log.Crit("Failed to read checkpoint", "error", err)
}

l, err := listener.NewListener(chainIdBigInt, cfg.Networks, queue, checkpoint)
l, err := listener.NewListener(chainIdBigInt, cfg.Networks, queue, checkpoint+1)
if err != nil {
log.Crit("Failed to create listener", "error", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func pollListener(l *listener) error {
for {
select {
case <-l.pollReqCh:
logger.Info("Running")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
logIterator, err := l.outbox.FilterCrossChainCallRequested(&bind.FilterOpts{Context: ctx, Start: l.startingBlock}, [][32]byte{})
if err != nil {
Expand Down
25 changes: 25 additions & 0 deletions services/go-filler/log-fetcher/internal/store/mongo_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,31 @@ func TestEnqueueError(t *testing.T) {
assert.Error(t, err)
}

func TestReadCheckpoint(t *testing.T) {
mockConnection := new(MongoConnectionMock)
queue := &queue{checkpoint: mockConnection}

mockConnection.On("FindOne", mock.Anything, mock.Anything, mock.Anything).Return(&mongo.SingleResult{})

checkpoint, err := queue.ReadCheckpoint("test")

assert.NoError(t, err)
assert.Equal(t, uint64(0), checkpoint)
mockConnection.AssertExpectations(t)
}

func TestWriteCheckpoint(t *testing.T) {
mockConnection := new(MongoConnectionMock)
queue := &queue{checkpoint: mockConnection}

mockConnection.On("UpdateOne", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&mongo.UpdateResult{}, nil)

err := queue.WriteCheckpoint("test", 1)

assert.NoError(t, err)
mockConnection.AssertExpectations(t)
}

func TestClose(t *testing.T) {
mockClient := new(MongoClientMock)
queue := &queue{client: mockClient}
Expand Down

0 comments on commit f19cea0

Please sign in to comment.