fix: post data

This commit is contained in:
debugtalk
2021-09-26 16:50:59 +08:00
parent 2be9dd580b
commit fbd238e55a
2 changed files with 27 additions and 9 deletions
+15 -5
View File
@@ -19,31 +19,41 @@ func TestCaseHardcode(t *testing.T) {
WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}). WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}). WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
Validate(). Validate().
AssertEqual("status_code", 200, "check status code"), AssertEqual("status_code", 200, "check status code").
AssertEqual("headers.Connection", "keep-alive", "check header Connection").
AssertEqual("headers.\"Content-Type\"", "application/json; charset=utf-8", "check header Content-Type").
AssertEqual("body.args.foo1", "bar1", "check args foo1").
AssertEqual("body.args.foo2", "bar2", "check args foo2"),
httpboomer.Step("post raw text"). httpboomer.Step("post raw text").
POST("/post"). POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "text/plain"}). WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "text/plain"}).
WithData("This is expected to be sent back as part of response body."). WithData("This is expected to be sent back as part of response body.").
Validate(). Validate().
AssertEqual("status_code", 200, "check status code"), AssertEqual("status_code", 200, "check status code").
AssertEqual("body.data", "This is expected to be sent back as part of response body.", "check data"),
httpboomer.Step("post form data"). httpboomer.Step("post form data").
POST("/post"). POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "application/x-www-form-urlencoded"}). WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "application/x-www-form-urlencoded"}).
WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}). WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
Validate(). Validate().
AssertEqual("status_code", 200, "check status code"), AssertEqual("status_code", 200, "check status code").
AssertEqual("body.form.foo1", "bar1", "check form foo1").
AssertEqual("body.form.foo2", "bar2", "check form foo2"),
httpboomer.Step("post json data"). httpboomer.Step("post json data").
POST("/post"). POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}). WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
WithJSON(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}). WithJSON(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
Validate(). Validate().
AssertEqual("status_code", 200, "check status code"), AssertEqual("status_code", 200, "check status code").
AssertEqual("body.json.foo1", "bar1", "check json foo1").
AssertEqual("body.json.foo2", "bar2", "check json foo2"),
httpboomer.Step("put request"). httpboomer.Step("put request").
PUT("/put"). PUT("/put").
WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "text/plain"}). WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "text/plain"}).
WithData("This is expected to be sent back as part of response body."). WithData("This is expected to be sent back as part of response body.").
Validate(). Validate().
AssertEqual("status_code", 200, "check status code"), AssertEqual("status_code", 200, "check status code").
AssertEqual("body.data", "This is expected to be sent back as part of response body.", "check data"),
}, },
} }
+12 -4
View File
@@ -72,10 +72,18 @@ func (r *Runner) runStep(step IStep, config *TConfig) error {
func (r *Runner) runStepRequest(step *TStep) error { func (r *Runner) runStepRequest(step *TStep) error {
// prepare request args // prepare request args
var v []interface{} var v []interface{}
v = append(v, req.Header(step.Request.Headers)) if len(step.Request.Headers) > 0 {
v = append(v, req.Param(step.Request.Params)) v = append(v, req.Header(step.Request.Headers))
v = append(v, step.Request.Data) }
v = append(v, req.BodyJSON(step.Request.JSON)) if len(step.Request.Params) > 0 {
v = append(v, req.Param(step.Request.Params))
}
if step.Request.Data != nil {
v = append(v, step.Request.Data)
}
if step.Request.JSON != nil {
v = append(v, req.BodyJSON(step.Request.JSON))
}
for cookieName, cookieValue := range step.Request.Cookies { for cookieName, cookieValue := range step.Request.Cookies {
v = append(v, &http.Cookie{ v = append(v, &http.Cookie{