代码拉取完成,页面将自动刷新
package baa
import (
"bytes"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestRequest1(t *testing.T) {
Convey("request body", t, func() {
b.Get("/body", func(c *Context) {
s, err := c.Body().String()
So(err, ShouldBeNil)
So(s, ShouldEqual, "{}")
// because one req can only read once
b, err := c.Body().Bytes()
So(err, ShouldBeNil)
So(string(b), ShouldEqual, "")
r := c.Body().ReadCloser()
b, err = ioutil.ReadAll(r)
So(err, ShouldBeNil)
So(string(b), ShouldEqual, "")
})
body := bytes.NewBuffer(nil)
body.Write([]byte("{}"))
req, _ := http.NewRequest("GET", "/body", body)
w := httptest.NewRecorder()
b.ServeHTTP(w, req)
So(w.Code, ShouldEqual, http.StatusOK)
})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。