Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Nov 21, 2024
1 parent a986130 commit 3b3e03f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions systemapi/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"bytes"
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"

"github.com/flashbots/system-api/common"
"github.com/go-chi/httplog/v2"
Expand Down Expand Up @@ -152,3 +154,26 @@ func TestBasicAuth(t *testing.T) {
code, _ = reqGetLiveZ("admin", "foo", nil)
require.Equal(t, http.StatusUnauthorized, code)
}

func TestMaxEntries(t *testing.T) {
// Verify maximum number of log entries is working correctly
maxEntries := 5

cfg := NewConfig()
cfg.General.LogMaxEntries = maxEntries
srv, err := NewServer(getTestLogger(), cfg)
require.NoError(t, err)

// Add 6 events, only last 5 should be stored
for i := 0; i < 6; i++ {

Check failure on line 168 in systemapi/server_test.go

View workflow job for this annotation

GitHub Actions / Lint

for loop can be changed to use an integer range (Go 1.22+) (intrange)
srv.addEvent(Event{ReceivedAt: time.Now(), Message: fmt.Sprint(i)})

Check failure on line 169 in systemapi/server_test.go

View workflow job for this annotation

GitHub Actions / Lint

fmt.Sprint can be replaced with faster strconv.Itoa (perfsprint)
}

// Ensure only 5 events are stored
require.Len(t, srv.events, 5)
require.Equal(t, "1", srv.events[0].Message) // originally, 0 was written to this position, but has been overwritten
require.Equal(t, "2", srv.events[1].Message)
require.Equal(t, "3", srv.events[2].Message)
require.Equal(t, "4", srv.events[3].Message)
require.Equal(t, "5", srv.events[4].Message)
}

0 comments on commit 3b3e03f

Please sign in to comment.