Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina committed Oct 10, 2023
1 parent ecee8fb commit 2082357
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion service/cachemdw/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/kava-labs/kava-proxy-service/service"
)

func TestServiceCacheMiddleware(t *testing.T) {
func TestE2ETestServiceCacheMiddleware(t *testing.T) {
logger, err := logging.New("TRACE")
require.NoError(t, err)

Expand Down Expand Up @@ -68,6 +68,33 @@ func TestServiceCacheMiddleware(t *testing.T) {
})
}

func TestE2ETestServiceCacheMiddlewareInvalidRequestBody(t *testing.T) {
logger, err := logging.New("TRACE")
require.NoError(t, err)

inMemoryCache := cache.NewInMemoryCache()
evmClient := NewMockEVMClient()
cacheTTL := time.Duration(0) // TTL: no expiry

serviceCache := NewServiceCache(inMemoryCache, evmClient, cacheTTL, service.DecodedRequestContextKey, &logger)

req, err := http.NewRequest(http.MethodPost, "/test", nil)
require.NoError(t, err)
req = req.WithContext(context.WithValue(req.Context(), service.DecodedRequestContextKey, "invalid"))

recorder := httptest.NewRecorder()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("test response"))
})

serviceCache.Middleware(handler).ServeHTTP(recorder, req)

require.Equal(t, http.StatusOK, recorder.Code)
require.Equal(t, "test response", recorder.Body.String())
require.Empty(t, recorder.Header().Get(CacheHeaderKey))
}

func createTestHttpRequest(
t *testing.T,
url string,
Expand Down

0 comments on commit 2082357

Please sign in to comment.