MCPcopy Create free account
hub / github.com/gavv/httpexpect / CloseWithText

Method CloseWithText

websocket.go:387–408  ·  view source on GitHub ↗

CloseWithText cleanly closes the underlying WebSocket connection by sending given text as a close message and then waiting (with timeout) for the server to close the connection. WebSocket close code may be optionally specified. If not, then "1000 - Normal Closure" will be used. WebSocket close cod

(s string, code ...int)

Source from the content-addressed store, hash-verified

385// conn := resp.Connection()
386// conn.CloseWithText("bye!")
387func (ws *Websocket) CloseWithText(s string, code ...int) *Websocket {
388 opChain := ws.chain.enter("CloseWithText()")
389 defer opChain.leave()
390
391 switch {
392 case ws.checkUnusable(opChain, "CloseWithText()"):
393 return ws
394
395 case len(code) > 1:
396 opChain.fail(AssertionFailure{
397 Type: AssertUsage,
398 Errors: []error{
399 errors.New("unexpected multiple code arguments"),
400 },
401 })
402 return ws
403 }
404
405 ws.writeMessage(opChain, websocket.CloseMessage, []byte(s), code...)
406
407 return ws
408}
409
410// WriteMessage writes to the underlying WebSocket connection a message
411// of given type with given content.

Callers 7

TestWsHandlerCloseFunction · 0.80
TestWsFastHandlerCloseFunction · 0.80
testWebsocketSessionFunction · 0.80
TestE2EWebsocket_ClosedFunction · 0.80

Calls 5

checkUnusableMethod · 0.95
writeMessageMethod · 0.95
enterMethod · 0.80
leaveMethod · 0.80
failMethod · 0.80

Tested by 7

TestWsHandlerCloseFunction · 0.64
TestWsFastHandlerCloseFunction · 0.64
testWebsocketSessionFunction · 0.64
TestE2EWebsocket_ClosedFunction · 0.64