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
+1 -1
View File
@@ -83,7 +83,7 @@ func TestCaseDemo(t *testing.T) {
hrp.Step("post form data"). hrp.Step("post form data").
POST("/post"). POST("/post").
WithHeaders(map[string]string{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}). 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 "foo1": "$varFoo1", // reference former extracted variable
"foo2": "${max($a, $b)}", // 12.3; step level variables are independent, variable b is 3.45 here "foo2": "${max($a, $b)}", // 12.3; step level variables are independent, variable b is 3.45 here
}). }).
+1 -1
View File
@@ -50,7 +50,7 @@ func TestCaseDemo(t *testing.T) {
hrp.Step("post form data"). hrp.Step("post form data").
POST("/post"). POST("/post").
WithHeaders(map[string]string{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}). 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 "foo1": "$varFoo1", // reference former extracted variable
"foo2": "${max($a, $b)}", // 12.3; step level variables are independent, variable b is 3.45 here "foo2": "${max($a, $b)}", // 12.3; step level variables are independent, variable b is 3.45 here
}). }).
+19 -6
View File
@@ -17,7 +17,9 @@ func TestCaseBasicRequest(t *testing.T) {
hrp.Step("get with params"). hrp.Step("get with params").
GET("/get"). GET("/get").
WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}). WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}). WithHeaders(map[string]string{
"User-Agent": "HttpRunnerPlus",
}).
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.Connection", "keep-alive", "check header Connection").
@@ -26,22 +28,30 @@ func TestCaseBasicRequest(t *testing.T) {
AssertEqual("body.args.foo2", "bar2", "check args foo2"), AssertEqual("body.args.foo2", "bar2", "check args foo2"),
hrp.Step("post raw text"). hrp.Step("post raw text").
POST("/post"). 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."). WithBody("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"), AssertEqual("body.data", "This is expected to be sent back as part of response body.", "check data"),
hrp.Step("post form data"). hrp.Step("post form data").
POST("/post"). POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus", "Content-Type": "application/x-www-form-urlencoded"}). WithHeaders(map[string]string{
WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}). "User-Agent": "HttpRunnerPlus",
"Content-Type": "application/x-www-form-urlencoded",
}).
WithBody(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.foo1", "bar1", "check form foo1").
AssertEqual("body.form.foo2", "bar2", "check form foo2"), AssertEqual("body.form.foo2", "bar2", "check form foo2"),
hrp.Step("post json data"). hrp.Step("post json data").
POST("/post"). POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}). WithHeaders(map[string]string{
"User-Agent": "HttpRunnerPlus",
}).
WithBody(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}). WithBody(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
Validate(). Validate().
AssertEqual("status_code", 200, "check status code"). AssertEqual("status_code", 200, "check status code").
@@ -49,7 +59,10 @@ func TestCaseBasicRequest(t *testing.T) {
AssertEqual("body.json.foo2", "bar2", "check json foo2"), AssertEqual("body.json.foo2", "bar2", "check json foo2"),
hrp.Step("put request"). hrp.Step("put request").
PUT("/put"). 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."). WithBody("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").