TODO: 解决覆盖率问题

This commit is contained in:
eson 2019-09-04 03:08:28 +08:00
parent cade90cc40
commit 469276cdaa
4 changed files with 55 additions and 25 deletions

View File

@ -54,3 +54,8 @@ func FromHTTPResponse(resp *http.Response) (*Response, error) {
func (gresp *Response) Content() string {
return gresp.readContent
}
// GetSrcResponse 获取原生golang http.Response
func (gresp *Response) GetSrcResponse() *http.Response {
return gresp.readResponse
}

View File

@ -1,9 +1,34 @@
package requests
import (
"net/http"
"testing"
"474420502.top/eson/gjson"
)
func TestTest(t *testing.T) {
var gresp *http.Response
var err error
gresp, err = http.DefaultClient.Get("http://httpbin.org/get")
if err != nil {
t.Error(err)
}
resp, err := FromHTTPResponse(gresp)
if err != nil {
t.Error(err)
}
if gjson.Get(resp.Content(), "headers.Host").String() != "httpbin.org" {
t.Error("headers.Host != httpbin.org ?")
}
if resp.GetSrcResponse().StatusCode != 200 {
t.Error("StatusCode != 200")
}
if len(resp.GetSrcResponse().Header) == 0 {
t.Error("esp.GetSrcResponse().Header == nil")
}
}

View File

@ -76,7 +76,7 @@ func TestSession_Post(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ses := NewSession()
got, err := ses.Post("http://httpbin.org/post").AutoSetBody(tt.args.params...).Execute()
got, err := ses.Post("http://httpbin.org/post").SetBodyAuto(tt.args.params...).Execute()
if err != nil {
t.Errorf("Metchod error = %v", err)
@ -127,7 +127,7 @@ func TestSession_Setparams(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
ses := NewSession()
got, err := ses.Post("http://httpbin.org/post").AutoSetBody(tt.args.params...).Execute()
got, err := ses.Post("http://httpbin.org/post").SetBodyAuto(tt.args.params...).Execute()
if (err != nil) != tt.wantErr {
t.Errorf("Metchod error = %v, wantErr %v", err, tt.wantErr)
return
@ -169,7 +169,7 @@ func TestSession_PostUploadFile(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ses := NewSession()
got, err := ses.Post("http://httpbin.org/post").AutoSetBody(tt.args.params, TypeFormData).Execute()
got, err := ses.Post("http://httpbin.org/post").SetBodyAuto(tt.args.params, TypeFormData).Execute()
if err != nil {
t.Errorf("Metchod error = %v", err)
@ -213,7 +213,7 @@ func TestSession_Put(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ses := NewSession()
got, err := ses.Put("http://httpbin.org/put").AutoSetBody(tt.args.params, TypeFormData).Execute()
got, err := ses.Put("http://httpbin.org/put").SetBodyAuto(tt.args.params, TypeFormData).Execute()
if err != nil {
t.Errorf("Metchod error = %v", err)
@ -257,7 +257,7 @@ func TestSession_Patch(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ses := NewSession()
got, err := ses.Patch("http://httpbin.org/patch").AutoSetBody(tt.args.params, TypeFormData).Execute()
got, err := ses.Patch("http://httpbin.org/patch").SetBodyAuto(tt.args.params, TypeFormData).Execute()
if err != nil {
t.Errorf("Metchod error = %v", err)

View File

@ -173,25 +173,25 @@ func (wf *Workflow) GetURLRawPath() string {
}
// encodePath path格式每个item都必须以/开头
func encodePath(path []string) string {
rawpath := ""
for _, p := range path {
if p[0] != '/' {
p = "/" + p
}
rawpath += p
}
return rawpath
}
// func encodePath(path []string) string {
// rawpath := ""
// for _, p := range path {
// if p[0] != '/' {
// p = "/" + p
// }
// rawpath += p
// }
// return rawpath
// }
// SetURLPath 设置Path参数
func (wf *Workflow) SetURLPath(path []string) *Workflow {
if path == nil {
return wf
}
wf.ParsedURL.Path = encodePath(path)
return wf
}
// // SetURLPath 设置Path参数
// func (wf *Workflow) SetURLPath(path []string) *Workflow {
// if path == nil {
// return wf
// }
// wf.ParsedURL.Path = encodePath(path)
// return wf
// }
// SetURLRawPath 设置Pa晚上参数
func (wf *Workflow) SetURLRawPath(path string) *Workflow {
@ -210,8 +210,8 @@ func (wf *Workflow) GetBody(body IBody) IBody {
return wf.Body
}
// AutoSetBody 参数设置
func (wf *Workflow) AutoSetBody(params ...interface{}) *Workflow {
// SetBodyAuto 参数设置
func (wf *Workflow) SetBodyAuto(params ...interface{}) *Workflow {
if params != nil {
plen := len(params)