MCPcopy
hub / github.com/httprunner/httprunner / TestWebSocketProtocolUsingRelativeURL

Function TestWebSocketProtocolUsingRelativeURL

hrp/tests/protocol_test.go:162–213  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

160}
161
162func TestWebSocketProtocolUsingRelativeURL(t *testing.T) {
163 testcase := &hrp.TestCase{
164 Config: hrp.NewConfig("run request with WebSocket protocol").
165 SetBaseURL("wss://ws.postman-echo.com").
166 WithVariables(map[string]interface{}{
167 "n": 5,
168 "a": 12.3,
169 "b": 3.45,
170 "file": "./demo_file_load_ws_message.txt",
171 }),
172 TestSteps: []hrp.IStep{
173 hrp.NewStep("open connection").
174 WebSocket().
175 OpenConnection("/raw"). // relative url specified ==> wss://ws.postman-echo.com/raw
176 WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
177 Validate().
178 AssertEqual("status_code", 101, "check open status code").
179 AssertEqualFold("headers.Connection", "Upgrade", "check headers").
180 AssertEqualFold("headers.Server", "nginx", "check server").
181 AssertEqualFold("headers.Upgrade", "websocket", "checkout upgrade"),
182 hrp.NewStep("write json").
183 WebSocket().
184 Write("/raw").
185 WithTextMessage(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}),
186 hrp.NewStep("read json").
187 WebSocket().
188 Read("/raw").
189 Extract().
190 WithJmesPath("body.foo1", "varFoo1").
191 Validate().
192 AssertLengthEqual("body.foo1", 5, "check json foo1").
193 AssertEqual("body.foo2", 12.3, "check json foo2"),
194 hrp.NewStep("write and read text").
195 WebSocket().
196 WriteAndRead("/raw").
197 WithTextMessage("$varFoo1").
198 Validate().
199 AssertLengthEqual("body", 5, "check length equal"),
200 hrp.NewStep("close connection").
201 WebSocket().
202 CloseConnection("/raw").
203 WithTimeout(30000).
204 WithCloseStatus(1000).
205 Validate().
206 AssertEqual("status_code", 1000, "check close status code"),
207 },
208 }
209 err := hrp.NewRunner(t).Run(testcase)
210 if err != nil {
211 t.Fatalf("run testcase error: %v", err)
212 }
213}
214
215func TestWebSocketProtocolUsingBaseURL(t *testing.T) {
216 testcase := &hrp.TestCase{

Callers

nothing calls this directly

Calls 15

NewConfigFunction · 0.92
NewStepFunction · 0.92
NewRunnerFunction · 0.92
SetBaseURLMethod · 0.80
AssertEqualFoldMethod · 0.80
AssertEqualMethod · 0.80
OpenConnectionMethod · 0.80
WebSocketMethod · 0.80
WithTextMessageMethod · 0.80
AssertLengthEqualMethod · 0.80
WithJmesPathMethod · 0.80
WriteAndReadMethod · 0.80

Tested by

no test coverage detected