代码拉取完成,页面将自动刷新
package dolphin
import (
"net/http"
"testing"
)
func TestReset(t *testing.T) {
resp := &Response{}
resp.reset()
if len(resp.body.Bytes()) != 0 {
t.Errorf("Response body expect 0, actual %d", len(resp.body.Bytes()))
}
if len(resp.cookies) != 0 {
t.Errorf("Length of response cookies expect 0, actual %d", len(resp.cookies))
}
if len(resp.header) != 0 {
t.Errorf("Length of response header expect 0, actual %d", len(resp.header))
}
if resp.statusCode != http.StatusOK {
t.Errorf("Response status code expect %d, actual %d",
http.StatusOK,
resp.statusCode,
)
}
}
func TestSetStatus(t *testing.T) {
resp := &Response{}
resp.reset()
err := resp.SetStatusCode(-1)
if err == nil {
t.Errorf("Set status code as -1 expect return error, actual return nil")
}
if resp.StatusCode() != http.StatusOK {
t.Errorf("Set status code as -1 expect resp.statusCode is 200%d, actual %d",
http.StatusOK,
resp.statusCode,
)
}
err = resp.SetStatusCode(0)
if err == nil {
t.Errorf("Set status code as 0 expect return error, actual return nil")
}
if resp.StatusCode() != http.StatusOK {
t.Errorf("Set status code as 0 expect resp.statusCode is %d, actual %d",
http.StatusOK,
resp.statusCode,
)
}
err = resp.SetStatusCode(1000)
if err == nil {
t.Errorf("Set status code as 1000 expect return error, actual return nil")
}
if resp.StatusCode() != http.StatusOK {
t.Errorf("Set status code as 1000 expect resp.statusCode is %d, actual %d",
http.StatusOK,
resp.statusCode,
)
}
err = resp.SetStatusCode(http.StatusCreated)
if err != nil {
t.Errorf("Set status code as %d expect return nil, actual return %v",
http.StatusCreated,
err,
)
}
if resp.StatusCode() != http.StatusCreated {
t.Errorf("Set status code as %d expect resp.statusCode is %d, actual %d",
http.StatusCreated,
http.StatusCreated,
resp.statusCode,
)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。