1
0
mirror of https://github.com/labstack/echo.git synced 2025-06-23 00:38:07 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2016-03-27 16:29:41 -07:00
parent d3e33ec4dd
commit a2d757eddc
4 changed files with 51 additions and 11 deletions

View File

@ -239,6 +239,33 @@ func TestContextNetContext(t *testing.T) {
// assert.Equal(t, "val", c.Value("key"))
}
func TestContextServeContent(t *testing.T) {
e := New()
rq := test.NewRequest(GET, "/", nil)
rc := test.NewResponseRecorder()
c := NewContext(rq, rc, e)
// Not cached
fs := http.Dir("_fixture/images")
f, err := fs.Open("walle.png")
if assert.NoError(t, err) {
if assert.NoError(t, c.ServeContent(f)) {
assert.Equal(t, http.StatusOK, rc.Status())
}
}
// Cached
rc = test.NewResponseRecorder()
c = NewContext(rq, rc, e)
fi, err := f.Stat()
if assert.NoError(t, err) {
rq.Header().Set(IfModifiedSince, fi.ModTime().UTC().Format(http.TimeFormat))
if assert.NoError(t, c.ServeContent(f)) {
assert.Equal(t, http.StatusNotModified, rc.Status())
}
}
}
func testBindOk(t *testing.T, c Context, ct string) {
c.Request().Header().Set(ContentType, ct)
u := new(user)