(t *testing.T)
| 213 | } |
| 214 | |
| 215 | func TestWebSocketProtocolUsingBaseURL(t *testing.T) { |
| 216 | testcase := &hrp.TestCase{ |
| 217 | Config: hrp.NewConfig("run request with WebSocket protocol"). |
| 218 | SetBaseURL("wss://ws.postman-echo.com/raw"). |
| 219 | WithVariables(map[string]interface{}{ |
| 220 | "n": 5, |
| 221 | "a": 12.3, |
| 222 | "b": 3.45, |
| 223 | "file": "./demo_file_load_ws_message.txt", |
| 224 | }), |
| 225 | TestSteps: []hrp.IStep{ |
| 226 | hrp.NewStep("open connection"). |
| 227 | WebSocket(). |
| 228 | OpenConnection(). // no url specified, using base url instead |
| 229 | WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}). |
| 230 | Validate(). |
| 231 | AssertEqual("status_code", 101, "check open status code"). |
| 232 | AssertEqualFold("headers.Connection", "Upgrade", "check headers"). |
| 233 | AssertEqualFold("headers.Server", "nginx", "check server"). |
| 234 | AssertEqualFold("headers.Upgrade", "websocket", "checkout upgrade"), |
| 235 | hrp.NewStep("write json"). |
| 236 | WebSocket(). |
| 237 | Write(). |
| 238 | WithTextMessage(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}), |
| 239 | hrp.NewStep("read json"). |
| 240 | WebSocket(). |
| 241 | Read(). |
| 242 | Extract(). |
| 243 | WithJmesPath("body.foo1", "varFoo1"). |
| 244 | Validate(). |
| 245 | AssertLengthEqual("body.foo1", 5, "check json foo1"). |
| 246 | AssertEqual("body.foo2", 12.3, "check json foo2"), |
| 247 | hrp.NewStep("write and read text"). |
| 248 | WebSocket(). |
| 249 | WriteAndRead(). |
| 250 | WithTextMessage("$varFoo1"). |
| 251 | Validate(). |
| 252 | AssertLengthEqual("body", 5, "check length equal"), |
| 253 | hrp.NewStep("close connection"). |
| 254 | WebSocket(). |
| 255 | CloseConnection(). |
| 256 | WithTimeout(30000). |
| 257 | WithCloseStatus(1000). |
| 258 | Validate(). |
| 259 | AssertEqual("status_code", 1000, "check close status code"), |
| 260 | }, |
| 261 | } |
| 262 | err := hrp.NewRunner(t).Run(testcase) |
| 263 | if err != nil { |
| 264 | t.Fatalf("run testcase error: %v", err) |
| 265 | } |
| 266 | } |
nothing calls this directly
no test coverage detected