github.com/msales/pkg/v3@v3.24.0/httpx/client_test.go (about) 1 package httpx_test 2 3 import ( 4 "bytes" 5 "net/http" 6 "net/http/httptest" 7 "testing" 8 9 "github.com/msales/pkg/v3/httpx" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestGet(t *testing.T) { 14 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) 15 16 _, err := httpx.Get(ts.URL) 17 18 assert.NoError(t, err) 19 } 20 21 func TestHead(t *testing.T) { 22 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) 23 24 _, err := httpx.Head(ts.URL) 25 26 assert.NoError(t, err) 27 } 28 29 func TestPost(t *testing.T) { 30 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) 31 32 body := bytes.NewReader([]byte{}) 33 _, err := httpx.Post(ts.URL, "plain/text", body) 34 35 assert.NoError(t, err) 36 }