rollback the ToFile func implement, and add testcase

This commit is contained in:
smallfish
2014-08-18 21:29:45 +08:00
parent de87529387
commit c16b7be9ac
2 changed files with 26 additions and 2 deletions

View File

@@ -15,6 +15,8 @@
package httplib
import (
"io/ioutil"
"os"
"strings"
"testing"
)
@@ -41,6 +43,10 @@ func TestGet(t *testing.T) {
t.Fatal(err)
}
t.Log(s)
if string(b) != s {
t.Fatal("request data not match")
}
}
func TestSimplePost(t *testing.T) {
@@ -171,3 +177,17 @@ func TestToJson(t *testing.T) {
t.Fatal("response is not valid ip")
}
}
func TestToFile(t *testing.T) {
f := "beego_testfile"
req := Get("http://httpbin.org/ip")
err := req.ToFile(f)
if err != nil {
t.Fatal(err)
}
defer os.Remove(f)
b, err := ioutil.ReadFile(f)
if n := strings.Index(string(b), "origin"); n == -1 {
t.Fatal(err)
}
}