diff --git a/internal/middleware/ratelimiter.go b/internal/middleware/ratelimiter.go index afd5e09..78e9298 100644 --- a/internal/middleware/ratelimiter.go +++ b/internal/middleware/ratelimiter.go @@ -7,7 +7,7 @@ import ( "log/slog" "net/http" "server/internal/db" - mock "server/internal/tests/dbmocks" // Import the mock DB for testing + mock "server/internal/tests/dbmocks" "strconv" "strings" "time" @@ -85,7 +85,7 @@ func RateLimiter(client *db.DiceDB, next http.Handler, limit int64, window float }) } -func MockRateLimiter(client *mock.InMemoryDiceDB, next http.Handler, limit int64, window float64) http.Handler { +func MockRateLimiter(client *mock.DiceDBMock, next http.Handler, limit int64, window float64) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Handle CORS for requests origin := r.Header.Get("Origin") diff --git a/internal/tests/dbmocks/mock_dicedb.go b/internal/tests/dbmocks/mock_dicedb.go index c8f18ce..97deee2 100644 --- a/internal/tests/dbmocks/mock_dicedb.go +++ b/internal/tests/dbmocks/mock_dicedb.go @@ -7,18 +7,18 @@ import ( "time" ) -type InMemoryDiceDB struct { +type DiceDBMock struct { data map[string]string mutex sync.Mutex } -func NewInMemoryDiceDB() *InMemoryDiceDB { - return &InMemoryDiceDB{ +func NewDiceDBMock() *DiceDBMock { + return &DiceDBMock{ data: make(map[string]string), } } -func (db *InMemoryDiceDB) Get(ctx context.Context, key string) (string, error) { +func (db *DiceDBMock) Get(ctx context.Context, key string) (string, error) { db.mutex.Lock() defer db.mutex.Unlock() @@ -29,7 +29,7 @@ func (db *InMemoryDiceDB) Get(ctx context.Context, key string) (string, error) { return val, nil } -func (db *InMemoryDiceDB) Set(ctx context.Context, key, value string, expiration time.Duration) error { +func (db *DiceDBMock) Set(ctx context.Context, key, value string, expiration time.Duration) error { db.mutex.Lock() defer db.mutex.Unlock() @@ -37,7 +37,7 @@ func (db *InMemoryDiceDB) Set(ctx context.Context, key, value string, expiration return nil } -func (db *InMemoryDiceDB) Incr(ctx context.Context, key string) (int64, error) { +func (db *DiceDBMock) Incr(ctx context.Context, key string) (int64, error) { db.mutex.Lock() defer db.mutex.Unlock() @@ -54,6 +54,6 @@ func (db *InMemoryDiceDB) Incr(ctx context.Context, key string) (int64, error) { return count, nil } -func (db *InMemoryDiceDB) Expire(ctx context.Context, key string, expiration time.Duration) error { +func (db *DiceDBMock) Expire(ctx context.Context, key string, expiration time.Duration) error { return nil } diff --git a/pkg/util/helpers.go b/pkg/util/helpers.go index d884955..c86cef0 100644 --- a/pkg/util/helpers.go +++ b/pkg/util/helpers.go @@ -174,7 +174,7 @@ func MockHandler(w http.ResponseWriter, r *http.Request) { } func SetupRateLimiter(limit int64, window float64) (*httptest.ResponseRecorder, *http.Request, http.Handler) { - mockClient := db.NewInMemoryDiceDB() + mockClient := db.NewDiceDBMock() r := httptest.NewRequest("GET", "/cli/somecommand", http.NoBody) w := httptest.NewRecorder()