feat: initial commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/FernandoVideira/LK_API_Temp/internal/auth"
|
||||
"github.com/FernandoVideira/LK_API_Temp/internal/ratelimiter"
|
||||
"github.com/FernandoVideira/LK_API_Temp/internal/store"
|
||||
"github.com/FernandoVideira/LK_API_Temp/internal/store/cache"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func newTestApi(t *testing.T, cfg config) *api {
|
||||
t.Helper()
|
||||
|
||||
logger := zap.NewNop().Sugar()
|
||||
mockStore := store.NewMockStorage()
|
||||
mockCache := cache.NewMockCache()
|
||||
testAuth := &auth.TestAuthenticator{}
|
||||
rateLimiter := ratelimiter.NewFixedWindowLimiter(
|
||||
cfg.rateLimiter.RequestsPerTimeFrame,
|
||||
cfg.rateLimiter.TimeFrame,
|
||||
)
|
||||
|
||||
return &api{
|
||||
logger: logger,
|
||||
store: mockStore,
|
||||
cacheStore: mockCache,
|
||||
authenticator: testAuth,
|
||||
config: cfg,
|
||||
rateLimiter: rateLimiter,
|
||||
}
|
||||
}
|
||||
|
||||
func executeRequest(req *http.Request, mux http.Handler) *httptest.ResponseRecorder {
|
||||
rr := httptest.NewRecorder()
|
||||
mux.ServeHTTP(rr, req)
|
||||
return rr
|
||||
}
|
||||
Reference in New Issue
Block a user