(t *testing.T)
| 100 | } |
| 101 | |
| 102 | func TestCaseParseVariables(t *testing.T) { |
| 103 | testcase := &hrp.TestCase{ |
| 104 | Config: hrp.NewConfig("run request with functions"). |
| 105 | SetBaseURL("https://postman-echo.com"). |
| 106 | WithVariables(map[string]interface{}{ |
| 107 | "n": 5, |
| 108 | "a": 12.3, |
| 109 | "b": 3.45, |
| 110 | "varFoo1": "${gen_random_string($n)}", |
| 111 | "varFoo2": "${max($a, $b)}", // 12.3 |
| 112 | }).SetVerifySSL(false), |
| 113 | TestSteps: []hrp.IStep{ |
| 114 | hrp.NewStep("get with params"). |
| 115 | WithVariables(map[string]interface{}{ |
| 116 | "n": 3, |
| 117 | "b": 34.5, |
| 118 | "varFoo2": "${max($a, $b)}", // 34.5 |
| 119 | }). |
| 120 | GET("/get"). |
| 121 | WithParams(map[string]interface{}{"foo1": "$varFoo1", "foo2": "$varFoo2"}). |
| 122 | WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}). |
| 123 | Extract(). |
| 124 | WithJmesPath("body.args.foo1", "varFoo1"). |
| 125 | Validate(). |
| 126 | AssertEqual("status_code", 200, "check status code"). |
| 127 | AssertLengthEqual("body.args.foo1", 5, "check args foo1"). |
| 128 | AssertEqual("body.args.foo2", "34.5", "check args foo2"), // notice: request params value will be converted to string |
| 129 | hrp.NewStep("post json data with functions"). |
| 130 | POST("/post"). |
| 131 | WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}). |
| 132 | WithBody(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}). |
| 133 | Validate(). |
| 134 | AssertEqual("status_code", 200, "check status code"). |
| 135 | AssertLengthEqual("body.json.foo1", 5, "check args foo1"). |
| 136 | AssertEqual("body.json.foo2", 12.3, "check args foo2"), |
| 137 | }, |
| 138 | } |
| 139 | |
| 140 | err := hrp.NewRunner(t).Run(testcase) |
| 141 | if err != nil { |
| 142 | t.Fatalf("run testcase error: %v", err) |
| 143 | } |
| 144 | } |
nothing calls this directly
no test coverage detected