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

View File

@@ -19,31 +19,41 @@ func TestCaseHardcode(t *testing.T) {
WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
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").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "text/plain"}).
WithData("This is expected to be sent back as part of response body.").
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").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "application/x-www-form-urlencoded"}).
WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
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").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
WithJSON(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
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").
PUT("/put").
WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "text/plain"}).
WithData("This is expected to be sent back as part of response body.").
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"),
},
}

View File

@@ -72,10 +72,18 @@ func (r *Runner) runStep(step IStep, config *TConfig) error {
func (r *Runner) runStepRequest(step *TStep) error {
// prepare request args
var v []interface{}
v = append(v, req.Header(step.Request.Headers))
v = append(v, req.Param(step.Request.Params))
v = append(v, step.Request.Data)
v = append(v, req.BodyJSON(step.Request.JSON))
if len(step.Request.Headers) > 0 {
v = append(v, req.Header(step.Request.Headers))
}
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 {
v = append(v, &http.Cookie{