feat: simplify httpc (#1748)
* feat: simplify httpc * chore: fix lint errors * chore: fix log url issue * chore: fix log url issue * refactor: handle resp & err in ResponseHandler * chore: remove unnecessary var names in return clause
This commit is contained in:
@@ -12,9 +12,9 @@ func TestDo(t *testing.T) {
|
||||
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
}))
|
||||
defer svr.Close()
|
||||
_, err := Get("foo", "tcp://bad request")
|
||||
assert.NotNil(t, err)
|
||||
resp, err := Get("foo", svr.URL)
|
||||
req, err := http.NewRequest(http.MethodGet, svr.URL, nil)
|
||||
assert.Nil(t, err)
|
||||
resp, err := DoRequest(req)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
}
|
||||
@@ -22,9 +22,10 @@ func TestDo(t *testing.T) {
|
||||
func TestDoNotFound(t *testing.T) {
|
||||
svr := httptest.NewServer(http.NotFoundHandler())
|
||||
defer svr.Close()
|
||||
_, err := Post("foo", "tcp://bad request", "application/json", nil)
|
||||
assert.NotNil(t, err)
|
||||
resp, err := Post("foo", svr.URL, "application/json", nil)
|
||||
req, err := http.NewRequest(http.MethodPost, svr.URL, nil)
|
||||
assert.Nil(t, err)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
resp, err := DoRequest(req)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
|
||||
}
|
||||
@@ -34,7 +35,7 @@ func TestDoMoved(t *testing.T) {
|
||||
defer svr.Close()
|
||||
req, err := http.NewRequest(http.MethodGet, svr.URL, nil)
|
||||
assert.Nil(t, err)
|
||||
_, err = Do("foo", req)
|
||||
_, err = DoRequest(req)
|
||||
// too many redirects
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user