MCPcopy
hub / github.com/httprunner/httprunner / writeWebSocket

Function writeWebSocket

hrp/step_websocket.go:536–568  ·  view source on GitHub ↗
(urlString string, r *SessionRunner, step *TStep, stepVariables map[string]interface{})

Source from the content-addressed store, hash-verified

534}
535
536func writeWebSocket(urlString string, r *SessionRunner, step *TStep, stepVariables map[string]interface{}) error {
537 wsConn := r.getWsClient(urlString)
538 if wsConn == nil {
539 return errors.New("try to use existing connection, but there is no connection")
540 }
541 // check priority: text message > binary message
542 if step.WebSocket.TextMessage != nil {
543 parsedMessage, parseErr := r.caseRunner.parser.Parse(step.WebSocket.TextMessage, stepVariables)
544 if parseErr != nil {
545 return parseErr
546 }
547 writeErr := writeWithType(wsConn, step, websocket.TextMessage, parsedMessage)
548 if writeErr != nil {
549 return writeErr
550 }
551 } else if step.WebSocket.BinaryMessage != nil {
552 parsedMessage, parseErr := r.caseRunner.parser.Parse(step.WebSocket.BinaryMessage, stepVariables)
553 if parseErr != nil {
554 return parseErr
555 }
556 writeErr := writeWithType(wsConn, step, websocket.BinaryMessage, parsedMessage)
557 if writeErr != nil {
558 return writeErr
559 }
560 } else {
561 log.Info().Msg("step with empty message")
562 err := writeWithAction(wsConn, step, websocket.BinaryMessage, []byte{})
563 if err != nil {
564 return err
565 }
566 }
567 return nil
568}
569
570func writeWithType(c *websocket.Conn, step *TStep, messageType int, message interface{}) error {
571 if message == nil {

Callers 2

runStepWebSocketFunction · 0.85
closeWithTimeoutFunction · 0.85

Calls 4

writeWithTypeFunction · 0.85
writeWithActionFunction · 0.85
getWsClientMethod · 0.80
ParseMethod · 0.80

Tested by

no test coverage detected