mirror of
https://github.com/labstack/echo.git
synced 2025-03-19 21:17:58 +02:00
Fixed test
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
c8d77b2675
commit
4255f4bd44
BIN
_fixture/favicon.ico
Normal file
BIN
_fixture/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
9
_fixture/folder/index.html
Normal file
9
_fixture/folder/index.html
Normal file
@ -0,0 +1,9 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Echo</title>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
Before Width: | Height: | Size: 215 KiB After Width: | Height: | Size: 215 KiB |
9
_fixture/index.html
Normal file
9
_fixture/index.html
Normal file
@ -0,0 +1,9 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Echo</title>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
@ -194,7 +194,7 @@ func TestContext(t *testing.T) {
|
||||
// File
|
||||
rec = httptest.NewRecorder()
|
||||
c = NewContext(req, NewResponse(rec, e), e)
|
||||
err = c.File("test/fixture/walle.png", "", false)
|
||||
err = c.File("_fixture/images/walle.png", "", false)
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, http.StatusOK, rec.Code)
|
||||
assert.Equal(t, 219885, rec.Body.Len())
|
||||
@ -203,7 +203,7 @@ func TestContext(t *testing.T) {
|
||||
// File as attachment
|
||||
rec = httptest.NewRecorder()
|
||||
c = NewContext(req, NewResponse(rec, e), e)
|
||||
err = c.File("test/fixture/walle.png", "WALLE.PNG", true)
|
||||
err = c.File("_fixture/images/walle.png", "WALLE.PNG", true)
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, http.StatusOK, rec.Code)
|
||||
assert.Equal(t, rec.Header().Get(ContentDisposition), "attachment; filename=WALLE.PNG")
|
||||
|
21
echo_test.go
21
echo_test.go
@ -43,7 +43,7 @@ func TestEcho(t *testing.T) {
|
||||
|
||||
func TestEchoIndex(t *testing.T) {
|
||||
e := New()
|
||||
e.Index("recipes/website/public/index.html")
|
||||
e.Index("_fixture/index.html")
|
||||
c, b := request(GET, "/", e)
|
||||
assert.Equal(t, http.StatusOK, c)
|
||||
assert.NotEmpty(t, b)
|
||||
@ -51,7 +51,7 @@ func TestEchoIndex(t *testing.T) {
|
||||
|
||||
func TestEchoFavicon(t *testing.T) {
|
||||
e := New()
|
||||
e.Favicon("recipes/website/public/favicon.ico")
|
||||
e.Favicon("_fixture/favicon.ico")
|
||||
c, b := request(GET, "/favicon.ico", e)
|
||||
assert.Equal(t, http.StatusOK, c)
|
||||
assert.NotEmpty(t, b)
|
||||
@ -61,23 +61,23 @@ func TestEchoStatic(t *testing.T) {
|
||||
e := New()
|
||||
|
||||
// OK
|
||||
e.Static("/scripts", "recipes/website/public/scripts")
|
||||
c, b := request(GET, "/scripts/main.js", e)
|
||||
e.Static("/images", "_fixture/images")
|
||||
c, b := request(GET, "/images/walle.png", e)
|
||||
assert.Equal(t, http.StatusOK, c)
|
||||
assert.NotEmpty(t, b)
|
||||
|
||||
// No file
|
||||
e.Static("/scripts", "recipes/website/public/scripts")
|
||||
c, _ = request(GET, "/scripts/index.js", e)
|
||||
e.Static("/images", "_fixture/scripts")
|
||||
c, _ = request(GET, "/images/bolt.png", e)
|
||||
assert.Equal(t, http.StatusNotFound, c)
|
||||
|
||||
// Directory
|
||||
e.Static("/scripts", "recipes/website/public/scripts")
|
||||
c, _ = request(GET, "/scripts", e)
|
||||
e.Static("/images", "_fixture/images")
|
||||
c, _ = request(GET, "/images", e)
|
||||
assert.Equal(t, http.StatusForbidden, c)
|
||||
|
||||
// Directory with index.html
|
||||
e.Static("/", "recipes/website/public")
|
||||
e.Static("/", "_fixture")
|
||||
c, r := request(GET, "/", e)
|
||||
assert.Equal(t, http.StatusOK, c)
|
||||
assert.Equal(t, true, strings.HasPrefix(r, "<!doctype html>"))
|
||||
@ -85,7 +85,8 @@ func TestEchoStatic(t *testing.T) {
|
||||
// Sub-directory with index.html
|
||||
c, r = request(GET, "/folder", e)
|
||||
assert.Equal(t, http.StatusOK, c)
|
||||
assert.Equal(t, "sub directory", r)
|
||||
assert.Equal(t, true, strings.HasPrefix(r, "<!doctype html>"))
|
||||
// assert.Equal(t, "sub directory", r)
|
||||
}
|
||||
|
||||
func TestEchoMiddleware(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user