Closed hashworks closed 2 years ago
Pull request #39 partly resolves this, but this test still failes:
func TestCachePageStatus201(t *testing.T) {
store := persistence.NewInMemoryStore(60 * time.Second)
router := gin.New()
router.GET("/cache_201", CachePage(store, time.Second*3, func(c *gin.Context) {
c.String(201, fmt.Sprint(time.Now().UnixNano()))
}))
w1 := performRequest("GET", "/cache_201", router)
time.Sleep(time.Millisecond * 500)
w2 := performRequest("GET", "/cache_201", router)
assert.Equal(t, 201, w1.Code)
assert.Equal(t, 201, w2.Code)
assert.Equal(t, w1.Body.String(), w2.Body.String())
}
--- FAIL: TestCachePageStatus201 (0.50s)
Error Trace: cache_test.go:190
Error: Not equal: 201 (expected)
!= 200 (actual)
FAIL
exit status 1
Returning a body and any status code that is not 200 always results in a cache page with a 200 status code. This even occurs at
AbortWithStatusJSON
! The status code should be cached and any aborted request should not be cached.