fix: post form data

This commit is contained in:
debugtalk
2021-10-30 16:11:39 +08:00
parent ff243a9402
commit 646f7c3868
3 changed files with 21 additions and 8 deletions

View File

@@ -83,7 +83,7 @@ func TestCaseDemo(t *testing.T) {
hrp.Step("post form data").
POST("/post").
WithHeaders(map[string]string{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}).
WithParams(map[string]interface{}{
WithBody(map[string]interface{}{
"foo1": "$varFoo1", // reference former extracted variable
"foo2": "${max($a, $b)}", // 12.3; step level variables are independent, variable b is 3.45 here
}).

View File

@@ -50,7 +50,7 @@ func TestCaseDemo(t *testing.T) {
hrp.Step("post form data").
POST("/post").
WithHeaders(map[string]string{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}).
WithParams(map[string]interface{}{
WithBody(map[string]interface{}{
"foo1": "$varFoo1", // reference former extracted variable
"foo2": "${max($a, $b)}", // 12.3; step level variables are independent, variable b is 3.45 here
}).

View File

@@ -17,7 +17,9 @@ func TestCaseBasicRequest(t *testing.T) {
hrp.Step("get with params").
GET("/get").
WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
WithHeaders(map[string]string{
"User-Agent": "HttpRunnerPlus",
}).
Validate().
AssertEqual("status_code", 200, "check status code").
AssertEqual("headers.Connection", "keep-alive", "check header Connection").
@@ -26,22 +28,30 @@ func TestCaseBasicRequest(t *testing.T) {
AssertEqual("body.args.foo2", "bar2", "check args foo2"),
hrp.Step("post raw text").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus", "Content-Type": "text/plain"}).
WithHeaders(map[string]string{
"User-Agent": "HttpRunnerPlus",
"Content-Type": "text/plain",
}).
WithBody("This is expected to be sent back as part of response body.").
Validate().
AssertEqual("status_code", 200, "check status code").
AssertEqual("body.data", "This is expected to be sent back as part of response body.", "check data"),
hrp.Step("post form data").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus", "Content-Type": "application/x-www-form-urlencoded"}).
WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
WithHeaders(map[string]string{
"User-Agent": "HttpRunnerPlus",
"Content-Type": "application/x-www-form-urlencoded",
}).
WithBody(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
Validate().
AssertEqual("status_code", 200, "check status code").
AssertEqual("body.form.foo1", "bar1", "check form foo1").
AssertEqual("body.form.foo2", "bar2", "check form foo2"),
hrp.Step("post json data").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
WithHeaders(map[string]string{
"User-Agent": "HttpRunnerPlus",
}).
WithBody(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
Validate().
AssertEqual("status_code", 200, "check status code").
@@ -49,7 +59,10 @@ func TestCaseBasicRequest(t *testing.T) {
AssertEqual("body.json.foo2", "bar2", "check json foo2"),
hrp.Step("put request").
PUT("/put").
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus", "Content-Type": "text/plain"}).
WithHeaders(map[string]string{
"User-Agent": "HttpRunnerPlus",
"Content-Type": "text/plain",
}).
WithBody("This is expected to be sent back as part of response body.").
Validate().
AssertEqual("status_code", 200, "check status code").