1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-29 12:51:29 +00:00
Beego/httplib/httplib_test.go

52 lines
1.1 KiB
Go
Raw Normal View History

2014-04-12 05:18:18 +00:00
// Beego (http://beego.me/)
// @description beego is an open-source, high-performance web framework for the Go programming language.
// @link http://github.com/astaxie/beego for the canonical source repository
// @license http://github.com/astaxie/beego/blob/master/LICENSE
// @authors astaxie
package httplib
2013-08-03 14:20:09 +00:00
import (
2014-05-08 08:58:08 +00:00
"fmt"
2013-08-03 14:20:09 +00:00
"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")
}
}
2014-05-08 08:58:08 +00:00
2014-05-20 09:34:52 +00:00
func ExamplePost(t *testing.T) {
2014-05-08 08:58:08 +00:00
b := Post("http://beego.me/").Debug(true)
b.Param("username", "astaxie")
b.Param("password", "hello")
b.PostFile("uploadfile", "httplib.go")
str, err := b.String()
if err != nil {
t.Fatal(err)
}
fmt.Println(str)
}