change: replace tab with space

This commit is contained in:
debugtalk
2021-10-04 18:43:08 +08:00
parent 6c042dcb68
commit a51d9ecb62
+48 -48
View File
@@ -35,59 +35,59 @@ This is an example of HttpBoomer testcase. You can find more in the [`examples`]
```go ```go
import ( import (
"testing" "testing"
"github.com/httprunner/httpboomer" "github.com/httprunner/httpboomer"
) )
func TestCaseDemo(t *testing.T) { func TestCaseDemo(t *testing.T) {
testcase := &httpboomer.TestCase{ testcase := &httpboomer.TestCase{
Config: httpboomer.TConfig{ Config: httpboomer.TConfig{
Name: "demo with complex mechanisms", Name: "demo with complex mechanisms",
BaseURL: "https://postman-echo.com", BaseURL: "https://postman-echo.com",
Variables: map[string]interface{}{ // global level variables Variables: map[string]interface{}{ // global level variables
"n": 5, "n": 5,
"a": 12.3, "a": 12.3,
"b": 3.45, "b": 3.45,
"varFoo1": "${gen_random_string($n)}", "varFoo1": "${gen_random_string($n)}",
"varFoo2": "${max($a, $b)}", // 12.3; eval with built-in function "varFoo2": "${max($a, $b)}", // 12.3; eval with built-in function
}, },
}, },
TestSteps: []httpboomer.IStep{ TestSteps: []httpboomer.IStep{
httpboomer.Step("get with params"). httpboomer.Step("get with params").
WithVariables(map[string]interface{}{ // step level variables WithVariables(map[string]interface{}{ // step level variables
"n": 3, // inherit config level variables if not set in step level, a/varFoo1 "n": 3, // inherit config level variables if not set in step level, a/varFoo1
"b": 34.5, // override config level variable if existed, n/b/varFoo2 "b": 34.5, // override config level variable if existed, n/b/varFoo2
"varFoo2": "${max($a, $b)}", // 34.5; override variable b and eval again "varFoo2": "${max($a, $b)}", // 34.5; override variable b and eval again
}). }).
GET("/get"). GET("/get").
WithParams(map[string]interface{}{"foo1": "$varFoo1", "foo2": "$varFoo2"}). // request with params WithParams(map[string]interface{}{"foo1": "$varFoo1", "foo2": "$varFoo2"}). // request with params
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}). // request with headers WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}). // request with headers
Extract(). Extract().
WithJmesPath("body.args.foo1", "varFoo1"). // extract variable with jmespath WithJmesPath("body.args.foo1", "varFoo1"). // extract variable with jmespath
Validate(). Validate().
AssertEqual("status_code", 200, "check response status code"). // validate response status code AssertEqual("status_code", 200, "check response status code"). // validate response status code
AssertStartsWith("headers.\"Content-Type\"", "application/json", ""). // validate response header AssertStartsWith("headers.\"Content-Type\"", "application/json", ""). // validate response header
AssertLengthEqual("body.args.foo1", 5, "check args foo1"). // validate response body with jmespath AssertLengthEqual("body.args.foo1", 5, "check args foo1"). // validate response body with jmespath
AssertLengthEqual("$varFoo1", 5, "check args foo1"). // assert with extracted variable from current step AssertLengthEqual("$varFoo1", 5, "check args foo1"). // assert with extracted variable from current step
AssertEqual("body.args.foo2", "34.5", "check args foo2"), // notice: request params value will be converted to string AssertEqual("body.args.foo2", "34.5", "check args foo2"), // notice: request params value will be converted to string
httpboomer.Step("post json data"). httpboomer.Step("post json data").
POST("/post"). POST("/post").
WithJSON(map[string]interface{}{ WithJSON(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
}). }).
Validate(). Validate().
AssertEqual("status_code", 200, "check status code"). AssertEqual("status_code", 200, "check status code").
AssertLengthEqual("body.json.foo1", 5, "check args foo1"). AssertLengthEqual("body.json.foo1", 5, "check args foo1").
AssertEqual("body.json.foo2", 12.3, "check args foo2"), AssertEqual("body.json.foo2", 12.3, "check args foo2"),
}, },
} }
err := httpboomer.Test(t, testcase) err := httpboomer.Test(t, testcase)
if err != nil { if err != nil {
t.Fatalf("run testcase error: %v", err) t.Fatalf("run testcase error: %v", err)
} }
} }
``` ```