2013-08-06 08:13:45 +00:00
|
|
|
package httplib
|
2013-08-03 14:20:09 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetUrl(t *testing.T) {
|
2013-12-07 05:26:22 +00:00
|
|
|
resp, err := Get("http://beego.me/").Debug(true).Response()
|
2013-08-03 14:20:09 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp.Body == nil {
|
|
|
|
t.Fatal("body is nil")
|
|
|
|
}
|
|
|
|
data, err := ioutil.ReadAll(resp.Body)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(data) == 0 {
|
|
|
|
t.Fatal("data is no")
|
|
|
|
}
|
|
|
|
|
2013-08-03 14:22:37 +00:00
|
|
|
str, err := Get("http://beego.me/").String()
|
2013-08-03 14:20:09 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(str) == 0 {
|
|
|
|
t.Fatal("has no info")
|
|
|
|
}
|
|
|
|
}
|