feat: add httpc.Parse (#1698)

This commit is contained in:
Kevin Wan
2022-03-23 17:58:21 +08:00
committed by GitHub
parent 0aeb49a6b0
commit c1d9e6a00b
10 changed files with 178 additions and 21 deletions

View File

@@ -10,6 +10,7 @@ import (
func TestNamedService_Do(t *testing.T) {
svr := httptest.NewServer(http.RedirectHandler("/foo", http.StatusMovedPermanently))
defer svr.Close()
req, err := http.NewRequest(http.MethodGet, svr.URL, nil)
assert.Nil(t, err)
service := NewService("foo")
@@ -22,6 +23,7 @@ func TestNamedService_Get(t *testing.T) {
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("foo", r.Header.Get("foo"))
}))
defer svr.Close()
service := NewService("foo", func(r *http.Request) *http.Request {
r.Header.Set("foo", "bar")
return r
@@ -34,6 +36,7 @@ func TestNamedService_Get(t *testing.T) {
func TestNamedService_Post(t *testing.T) {
svr := httptest.NewServer(http.NotFoundHandler())
defer svr.Close()
service := NewService("foo")
_, err := service.Post("tcp://bad request", "application/json", nil)
assert.NotNil(t, err)