1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-24 08:22:21 +02:00
echo/middleware/slash_test.go
Vishal Rana 13ac746093 Refactored Echo.HandlerFunc, added WebSocket support.
Signed-off-by: Vishal Rana <vr@labstack.com>
2015-05-20 14:38:51 -07:00

39 lines
966 B
Go

package middleware
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/labstack/echo"
)
func TestStripTrailingSlash(t *testing.T) {
req, _ := http.NewRequest(echo.GET, "/users/", nil)
res := echo.NewResponse(httptest.NewRecorder())
c := echo.NewContext(req, res, echo.New())
StripTrailingSlash()(c)
p := c.Request.URL.Path
if p != "/users" {
t.Errorf("expected path `/users` got, %s.", p)
}
}
func TestRedirectToSlash(t *testing.T) {
req, _ := http.NewRequest(echo.GET, "/users", nil)
res := echo.NewResponse(httptest.NewRecorder())
c := echo.NewContext(req, res, echo.New())
RedirectToSlash(RedirectToSlashOptions{Code: http.StatusTemporaryRedirect})(c)
// Status code
if res.Status() != http.StatusTemporaryRedirect {
t.Errorf("expected status `307`, got %d.", res.Status())
}
// Location header
l := c.Response.Header().Get("Location")
if l != "/users/" {
t.Errorf("expected Location header `/users/`, got %s.", l)
}
}