Skip to content

Commit

Permalink
Fixed test
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <[email protected]>
  • Loading branch information
vishr committed Feb 22, 2017
1 parent d259f88 commit 29fd583
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go
go:
- 1.6
- 1.7
- 1.8
- tip
install:
- go get golang.org/x/tools/cmd/cover
Expand Down
12 changes: 6 additions & 6 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestBindForm(t *testing.T) {
testBindOkay(t, strings.NewReader(userForm), MIMEApplicationForm)
testBindError(t, nil, MIMEApplicationForm)
e := New()
req, _ := http.NewRequest(POST, "/", strings.NewReader(userForm))
req := httptest.NewRequest(POST, "/", strings.NewReader(userForm))
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
req.Header.Set(HeaderContentType, MIMEApplicationForm)
Expand All @@ -113,7 +113,7 @@ func TestBindForm(t *testing.T) {

func TestBindQueryParams(t *testing.T) {
e := New()
req, _ := http.NewRequest(GET, "/?id=1&name=Jon Snow", nil)
req := httptest.NewRequest(GET, "/?id=1&name=Jon+Snow", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
u := new(user)
Expand All @@ -126,7 +126,7 @@ func TestBindQueryParams(t *testing.T) {

func TestBindUnmarshalParam(t *testing.T) {
e := New()
req, _ := http.NewRequest(GET, "/?ts=2016-12-06T19:09:05Z&sa=one,two,three&ta=2016-12-06T19:09:05Z&ta=2016-12-06T19:09:05Z&ST=baz", nil)
req := httptest.NewRequest(GET, "/?ts=2016-12-06T19:09:05Z&sa=one,two,three&ta=2016-12-06T19:09:05Z&ta=2016-12-06T19:09:05Z&ST=baz", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
result := struct {
Expand All @@ -148,7 +148,7 @@ func TestBindUnmarshalParam(t *testing.T) {

func TestBindUnmarshalParamPtr(t *testing.T) {
e := New()
req, _ := http.NewRequest(GET, "/?ts=2016-12-06T19:09:05Z", nil)
req := httptest.NewRequest(GET, "/?ts=2016-12-06T19:09:05Z", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
result := struct {
Expand Down Expand Up @@ -270,7 +270,7 @@ func assertBindTestStruct(t *testing.T, ts *bindTestStruct) {

func testBindOkay(t *testing.T, r io.Reader, ctype string) {
e := New()
req, _ := http.NewRequest(POST, "/", r)
req := httptest.NewRequest(POST, "/", r)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
req.Header.Set(HeaderContentType, ctype)
Expand All @@ -284,7 +284,7 @@ func testBindOkay(t *testing.T, r io.Reader, ctype string) {

func testBindError(t *testing.T, r io.Reader, ctype string) {
e := New()
req, _ := http.NewRequest(POST, "/", r)
req := httptest.NewRequest(POST, "/", r)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
req.Header.Set(HeaderContentType, ctype)
Expand Down
18 changes: 9 additions & 9 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (t *Template) Render(w io.Writer, name string, data interface{}, c Context)

func TestContext(t *testing.T) {
e := New()
req, _ := http.NewRequest(POST, "/", strings.NewReader(userJSON))
req := httptest.NewRequest(POST, "/", strings.NewReader(userJSON))
rec := httptest.NewRecorder()
c := e.NewContext(req, rec).(*context)

Expand Down Expand Up @@ -195,7 +195,7 @@ func TestContext(t *testing.T) {

func TestContextCookie(t *testing.T) {
e := New()
req, _ := http.NewRequest(GET, "/", nil)
req := httptest.NewRequest(GET, "/", nil)
theme := "theme=light"
user := "user=Jon Snow"
req.Header.Add(HeaderCookie, theme)
Expand Down Expand Up @@ -255,7 +255,7 @@ func TestContextPath(t *testing.T) {

func TestContextPathParam(t *testing.T) {
e := New()
req, _ := http.NewRequest(GET, "/", nil)
req := httptest.NewRequest(GET, "/", nil)
c := e.NewContext(req, nil)

// ParamNames
Expand All @@ -272,7 +272,7 @@ func TestContextPathParam(t *testing.T) {

func TestContextPathParamNamesAlais(t *testing.T) {
e := New()
req, _ := http.NewRequest(GET, "/", nil)
req := httptest.NewRequest(GET, "/", nil)
c := e.NewContext(req, nil)

c.SetParamNames("id,name")
Expand All @@ -288,7 +288,7 @@ func TestContextFormValue(t *testing.T) {
f.Set("email", "[email protected]")

e := New()
req, _ := http.NewRequest(POST, "/", strings.NewReader(f.Encode()))
req := httptest.NewRequest(POST, "/", strings.NewReader(f.Encode()))
req.Header.Add(HeaderContentType, MIMEApplicationForm)
c := e.NewContext(req, nil)

Expand All @@ -310,7 +310,7 @@ func TestContextQueryParam(t *testing.T) {
q := make(url.Values)
q.Set("name", "Jon Snow")
q.Set("email", "[email protected]")
req, _ := http.NewRequest(GET, "/?"+q.Encode(), nil)
req := httptest.NewRequest(GET, "/?"+q.Encode(), nil)
e := New()
c := e.NewContext(req, nil)

Expand All @@ -334,7 +334,7 @@ func TestContextFormFile(t *testing.T) {
w.Write([]byte("test"))
}
mr.Close()
req, _ := http.NewRequest(POST, "/", buf)
req := httptest.NewRequest(POST, "/", buf)
req.Header.Set(HeaderContentType, mr.FormDataContentType())
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
Expand All @@ -350,7 +350,7 @@ func TestContextMultipartForm(t *testing.T) {
mw := multipart.NewWriter(buf)
mw.WriteField("name", "Jon Snow")
mw.Close()
req, _ := http.NewRequest(POST, "/", buf)
req := httptest.NewRequest(POST, "/", buf)
req.Header.Set(HeaderContentType, mw.FormDataContentType())
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
Expand All @@ -362,7 +362,7 @@ func TestContextMultipartForm(t *testing.T) {

func TestContextRedirect(t *testing.T) {
e := New()
req, _ := http.NewRequest(GET, "/", nil)
req := httptest.NewRequest(GET, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
assert.Equal(t, nil, c.Redirect(http.StatusMovedPermanently, "http://labstack.github.io/echo"))
Expand Down
2 changes: 1 addition & 1 deletion echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func (e *Echo) Static(prefix, root string) {

func static(i i, prefix, root string) {
h := func(c Context) error {
name := filepath.Join(root, path.Clean("/"+c.Param("*"))) // `/` for security
name := filepath.Join(root, path.Clean("/"+c.Param("*"))) // "/"+ for security
return c.File(name)
}
i.GET(prefix, h)
Expand Down
12 changes: 6 additions & 6 deletions echo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const userXMLPretty = `<user>

func TestEcho(t *testing.T) {
e := New()
req, _ := http.NewRequest(GET, "/", nil)
req := httptest.NewRequest(GET, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)

Expand Down Expand Up @@ -164,7 +164,7 @@ func TestEchoHandler(t *testing.T) {

func TestEchoWrapHandler(t *testing.T) {
e := New()
req, _ := http.NewRequest(GET, "", nil)
req := httptest.NewRequest(GET, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
h := WrapHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -179,7 +179,7 @@ func TestEchoWrapHandler(t *testing.T) {

func TestEchoWrapMiddleware(t *testing.T) {
e := New()
req, _ := http.NewRequest(GET, "", nil)
req := httptest.NewRequest(GET, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
buf := new(bytes.Buffer)
Expand Down Expand Up @@ -364,7 +364,7 @@ func TestEchoGroup(t *testing.T) {

func TestEchoNotFound(t *testing.T) {
e := New()
req, _ := http.NewRequest(GET, "/files", nil)
req := httptest.NewRequest(GET, "/files", nil)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
assert.Equal(t, http.StatusNotFound, rec.Code)
Expand All @@ -375,7 +375,7 @@ func TestEchoMethodNotAllowed(t *testing.T) {
e.GET("/", func(c Context) error {
return c.String(http.StatusOK, "Echo!")
})
req, _ := http.NewRequest(POST, "/", nil)
req := httptest.NewRequest(POST, "/", nil)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
assert.Equal(t, http.StatusMethodNotAllowed, rec.Code)
Expand Down Expand Up @@ -418,7 +418,7 @@ func testMethod(t *testing.T, method, path string, e *Echo) {
}

func request(method, path string, e *Echo) (int, string) {
req, _ := http.NewRequest(method, path, nil)
req := httptest.NewRequest(method, path, nil)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
return rec.Code, rec.Body.String()
Expand Down
2 changes: 1 addition & 1 deletion middleware/basic_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestBasicAuth(t *testing.T) {
e := echo.New()
req, _ := http.NewRequest(echo.GET, "/", nil)
req := httptest.NewRequest(echo.GET, "/", nil)
res := httptest.NewRecorder()
c := e.NewContext(req, res)
f := func(u, p string, c echo.Context) bool {
Expand Down
2 changes: 1 addition & 1 deletion middleware/body_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestBodyLimit(t *testing.T) {
e := echo.New()
hw := []byte("Hello, World!")
req, _ := http.NewRequest(echo.POST, "/", bytes.NewReader(hw))
req := httptest.NewRequest(echo.POST, "/", bytes.NewReader(hw))
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
h := func(c echo.Context) error {
Expand Down
8 changes: 4 additions & 4 deletions middleware/compress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestGzip(t *testing.T) {
e := echo.New()
req, _ := http.NewRequest(echo.GET, "/", nil)
req := httptest.NewRequest(echo.GET, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)

Expand Down Expand Up @@ -45,7 +45,7 @@ func TestGzip(t *testing.T) {

func TestGzipNoContent(t *testing.T) {
e := echo.New()
req, _ := http.NewRequest(echo.GET, "/", nil)
req := httptest.NewRequest(echo.GET, "/", nil)
req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
Expand All @@ -65,7 +65,7 @@ func TestGzipErrorReturned(t *testing.T) {
e.GET("/", func(c echo.Context) error {
return echo.ErrNotFound
})
req, _ := http.NewRequest(echo.GET, "/", nil)
req := httptest.NewRequest(echo.GET, "/", nil)
req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
Expand All @@ -78,7 +78,7 @@ func TestGzipWithStatic(t *testing.T) {
e := echo.New()
e.Use(Gzip())
e.Static("/test", "../_fixture/images")
req, _ := http.NewRequest(echo.GET, "/test/walle.png", nil)
req := httptest.NewRequest(echo.GET, "/test/walle.png", nil)
req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
Expand Down
2 changes: 1 addition & 1 deletion middleware/cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestCORS(t *testing.T) {
e := echo.New()

// Wildcard origin
req, _ := http.NewRequest(echo.GET, "/", nil)
req := httptest.NewRequest(echo.GET, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
h := CORS()(echo.NotFoundHandler)
Expand Down
6 changes: 3 additions & 3 deletions middleware/csrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestCSRF(t *testing.T) {
e := echo.New()
req, _ := http.NewRequest(echo.GET, "/", nil)
req := httptest.NewRequest(echo.GET, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
csrf := CSRFWithConfig(CSRFConfig{
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestCSRFTokenFromForm(t *testing.T) {
f := make(url.Values)
f.Set("csrf", "token")
e := echo.New()
req, _ := http.NewRequest(echo.POST, "/", strings.NewReader(f.Encode()))
req := httptest.NewRequest(echo.POST, "/", strings.NewReader(f.Encode()))
req.Header.Add(echo.HeaderContentType, echo.MIMEApplicationForm)
c := e.NewContext(req, nil)
token, err := csrfTokenFromForm("csrf")(c)
Expand All @@ -69,7 +69,7 @@ func TestCSRFTokenFromQuery(t *testing.T) {
q := make(url.Values)
q.Set("csrf", "token")
e := echo.New()
req, _ := http.NewRequest(echo.GET, "/?"+q.Encode(), nil)
req := httptest.NewRequest(echo.GET, "/?"+q.Encode(), nil)
req.Header.Add(echo.HeaderContentType, echo.MIMEApplicationForm)
c := e.NewContext(req, nil)
token, err := csrfTokenFromQuery("csrf")(c)
Expand Down
2 changes: 1 addition & 1 deletion middleware/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestJWT(t *testing.T) {
tc.reqURL = "/"
}

req, _ := http.NewRequest(echo.GET, tc.reqURL, nil)
req := httptest.NewRequest(echo.GET, tc.reqURL, nil)
res := httptest.NewRecorder()
req.Header.Set(echo.HeaderAuthorization, tc.hdrAuth)
req.Header.Set(echo.HeaderCookie, tc.hdrCookie)
Expand Down
2 changes: 1 addition & 1 deletion middleware/key_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestKeyAuth(t *testing.T) {
e := echo.New()
req, _ := http.NewRequest(echo.GET, "/", nil)
req := httptest.NewRequest(echo.GET, "/", nil)
res := httptest.NewRecorder()
c := e.NewContext(req, res)
config := KeyAuthConfig{
Expand Down
6 changes: 3 additions & 3 deletions middleware/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func TestLogger(t *testing.T) {
// Note: Just for the test coverage, not a real test.
e := echo.New()
req, _ := http.NewRequest(echo.GET, "/", nil)
req := httptest.NewRequest(echo.GET, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
h := Logger()(func(c echo.Context) error {
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestLogger(t *testing.T) {

func TestLoggerIPAddress(t *testing.T) {
e := echo.New()
req, _ := http.NewRequest(echo.GET, "/", nil)
req := httptest.NewRequest(echo.GET, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
buf := new(bytes.Buffer)
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestLoggerTemplate(t *testing.T) {
return c.String(http.StatusOK, "Header Logged")
})

req, _ := http.NewRequest(echo.GET, "/?username=apagano-param&password=secret", nil)
req := httptest.NewRequest(echo.GET, "/?username=apagano-param&password=secret", nil)
req.RequestURI = "/"
req.Header.Add(echo.HeaderXRealIP, "127.0.0.1")
req.Header.Add("Referer", "google.com")
Expand Down
2 changes: 1 addition & 1 deletion middleware/method_override_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestMethodOverride(t *testing.T) {
}

// Override with http header
req, _ := http.NewRequest(echo.POST, "/", nil)
req := httptest.NewRequest(echo.POST, "/", nil)
rec := httptest.NewRecorder()
req.Header.Set(echo.HeaderXHTTPMethodOverride, echo.DELETE)
c := e.NewContext(req, rec)
Expand Down
2 changes: 1 addition & 1 deletion middleware/recover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestRecover(t *testing.T) {
e := echo.New()
buf := new(bytes.Buffer)
e.Logger.SetOutput(buf)
req, _ := http.NewRequest(echo.GET, "/", nil)
req := httptest.NewRequest(echo.GET, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
h := Recover()(echo.HandlerFunc(func(c echo.Context) error {
Expand Down
Loading

0 comments on commit 29fd583

Please sign in to comment.