Skip to content

Commit

Permalink
Merge pull request labstack#1632 from imxyb/hardcode_for_http
Browse files Browse the repository at this point in the history
Use http constants instead of hardcoded status
  • Loading branch information
lammel authored Sep 14, 2020
2 parents 28ec3f7 + 5c5c83d commit 0fd6fce
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions middleware/rewrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ func TestRewrite(t *testing.T) {
rec = httptest.NewRecorder()
e.ServeHTTP(rec, req)
assert.Equal(t, "/new%20users", req.URL.EscapedPath())
req.URL.Path = "/users/jill/orders/T%2FcO4lW%2Ft%2FVp%2F"
req.URL.Path = "/users/jill/orders/T%2FcO4lW%2Ft%2FVp%2F"
rec = httptest.NewRecorder()
e.ServeHTTP(rec, req)
assert.Equal(t, "/user/jill/order/T%2FcO4lW%2Ft%2FVp%2F", req.URL.EscapedPath())
req.URL.Path = "/users/jill/orders/%%%%"
req.URL.Path = "/users/jill/orders/%%%%"
rec = httptest.NewRecorder()
e.ServeHTTP(rec, req)
assert.Equal(t, http.StatusBadRequest, rec.Code)
Expand All @@ -66,14 +66,14 @@ func TestEchoRewritePreMiddleware(t *testing.T) {

// Route
r.Add(http.MethodGet, "/new", func(c echo.Context) error {
return c.NoContent(200)
return c.NoContent(http.StatusOK)
})

req := httptest.NewRequest(http.MethodGet, "/old", nil)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
assert.Equal(t, "/new", req.URL.EscapedPath())
assert.Equal(t, 200, rec.Code)
assert.Equal(t, http.StatusOK, rec.Code)
}

// Issue #1143
Expand All @@ -89,18 +89,18 @@ func TestRewriteWithConfigPreMiddleware_Issue1143(t *testing.T) {
}))

r.Add(http.MethodGet, "/api/:version/hosts/:name", func(c echo.Context) error {
return c.String(200, "hosts")
return c.String(http.StatusOK, "hosts")
})
r.Add(http.MethodGet, "/api/:version/eng", func(c echo.Context) error {
return c.String(200, "eng")
return c.String(http.StatusOK, "eng")
})

for i := 0; i < 100; i++ {
req := httptest.NewRequest(http.MethodGet, "/api/v1/mgmt/proj/test/agt", nil)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
assert.Equal(t, "/api/v1/hosts/test", req.URL.EscapedPath())
assert.Equal(t, 200, rec.Code)
assert.Equal(t, http.StatusOK, rec.Code)

defer rec.Result().Body.Close()
bodyBytes, _ := ioutil.ReadAll(rec.Result().Body)
Expand Down

0 comments on commit 0fd6fce

Please sign in to comment.