requests/response_test.go

49 lines
920 B
Go
Raw Normal View History

2018-10-17 06:25:17 +00:00
package requests
2018-10-17 10:38:04 +00:00
import (
2019-09-03 19:08:28 +00:00
"net/http"
2018-10-17 10:38:04 +00:00
"testing"
2019-09-03 19:08:28 +00:00
"474420502.top/eson/gjson"
2018-10-17 10:38:04 +00:00
)
2019-09-04 03:35:21 +00:00
func TestFromHTTPResponse(t *testing.T) {
2018-10-17 10:38:04 +00:00
2019-09-03 19:08:28 +00:00
var gresp *http.Response
var err error
gresp, err = http.DefaultClient.Get("http://httpbin.org/get")
if err != nil {
t.Error(err)
}
2019-09-04 03:35:21 +00:00
resp, err := FromHTTPResponse(gresp, false)
2019-09-03 19:08:28 +00:00
if err != nil {
t.Error(err)
}
if gjson.Get(resp.Content(), "headers.Host").String() != "httpbin.org" {
t.Error("headers.Host != httpbin.org ?")
}
if resp.GetSrcResponse().StatusCode != 200 {
t.Error("StatusCode != 200")
}
if len(resp.GetSrcResponse().Header) == 0 {
t.Error("esp.GetSrcResponse().Header == nil")
}
2018-10-17 10:38:04 +00:00
}
2019-09-04 03:35:21 +00:00
func TestResponseGzipZip(t *testing.T) {
ses := NewSession()
if wf := ses.Get("http://httpbin.org/get"); wf != nil {
wf.AddHeader("accept-encoding", "deflate")
resp, err := wf.Execute()
if err != nil {
t.Error(err)
} else {
t.Error(resp.Content())
}
}
}