(t *testing.T)
| 54 | } |
| 55 | |
| 56 | func TestWebSocketProtocol(t *testing.T) { |
| 57 | testcase := &hrp.TestCase{ |
| 58 | Config: hrp.NewConfig("run request with WebSocket protocol"). |
| 59 | WithVariables(map[string]interface{}{ |
| 60 | "n": 5, |
| 61 | "a": 12.3, |
| 62 | "b": 3.45, |
| 63 | "file": "./demo_file_load_ws_message.txt", |
| 64 | "wsEchoURL": "ws://echo.websocket.events", |
| 65 | "wsPostmanURL": "wss://ws.postman-echo.com/raw", |
| 66 | }), |
| 67 | TestSteps: []hrp.IStep{ |
| 68 | hrp.NewStep("open connection"). |
| 69 | WebSocket(). |
| 70 | OpenConnection("$wsEchoURL"). // absolute url specified, disable base url anyway |
| 71 | WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}). |
| 72 | Validate(). |
| 73 | AssertEqual("status_code", 101, "check open status code"). |
| 74 | AssertEqual("headers.Connection", "Upgrade", "check headers"), |
| 75 | hrp.NewStep("ping pong test"). |
| 76 | WebSocket(). |
| 77 | PingPong("$wsEchoURL"). |
| 78 | WithTimeout(5000), |
| 79 | hrp.NewStep("read sponsor info"). |
| 80 | WebSocket(). |
| 81 | Read("$wsEchoURL"). |
| 82 | WithTimeout(5000). |
| 83 | Validate(). |
| 84 | AssertContains("body", "Lob.com", "check sponsor message"), |
| 85 | hrp.NewStep("write json"). |
| 86 | WebSocket(). |
| 87 | Write("$wsEchoURL"). |
| 88 | WithTextMessage(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}), |
| 89 | hrp.NewStep("read json"). |
| 90 | WebSocket(). |
| 91 | Read("$wsEchoURL"). |
| 92 | Extract(). |
| 93 | WithJmesPath("body.foo1", "varFoo1"). |
| 94 | Validate(). |
| 95 | AssertLengthEqual("body.foo1", 5, "check json foo1"). |
| 96 | AssertEqual("body.foo2", 12.3, "check json foo2"), |
| 97 | hrp.NewStep("write and read text"). |
| 98 | WebSocket(). |
| 99 | WriteAndRead("$wsEchoURL"). |
| 100 | WithTextMessage("$varFoo1"). |
| 101 | Validate(). |
| 102 | AssertLengthEqual("body", 5, "check length equal"), |
| 103 | hrp.NewStep("write and read binary file"). |
| 104 | WebSocket(). |
| 105 | WriteAndRead("$wsEchoURL"). |
| 106 | WithBinaryMessage("${load_ws_message($file)}"), |
| 107 | hrp.NewStep("write something redundant"). |
| 108 | WebSocket(). |
| 109 | Write("$wsEchoURL"). |
| 110 | WithTextMessage("have a nice day!"), |
| 111 | hrp.NewStep("write something redundant"). |
| 112 | WebSocket(). |
| 113 | Write("$wsEchoURL"). |
nothing calls this directly
no test coverage detected