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

Method WriteJSON

websocket.go:480–505  ·  view source on GitHub ↗

WriteJSON writes to the underlying WebSocket connection given object, marshaled using json.Marshal().

(object interface{})

Source from the content-addressed store, hash-verified

478// WriteJSON writes to the underlying WebSocket connection given object,
479// marshaled using json.Marshal().
480func (ws *Websocket) WriteJSON(object interface{}) *Websocket {
481 opChain := ws.chain.enter("WriteJSON()")
482 defer opChain.leave()
483
484 if ws.checkUnusable(opChain, "WriteJSON()") {
485 return ws
486 }
487
488 b, err := json.Marshal(object)
489
490 if err != nil {
491 opChain.fail(AssertionFailure{
492 Type: AssertValid,
493 Actual: &AssertionValue{object},
494 Errors: []error{
495 errors.New("invalid json object"),
496 err,
497 },
498 })
499 return ws
500 }
501
502 ws.writeMessage(opChain, websocket.TextMessage, b)
503
504 return ws
505}
506
507func (ws *Websocket) checkUnusable(opChain *chain, where string) bool {
508 switch {

Callers 5

TestWebsocket_WriteJSONFunction · 0.80
TestWsHandlerJSONFunction · 0.80
TestWsFastHandlerJSONFunction · 0.80
testWebsocketSessionFunction · 0.80

Calls 5

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

Tested by 5

TestWebsocket_WriteJSONFunction · 0.64
TestWsHandlerJSONFunction · 0.64
TestWsFastHandlerJSONFunction · 0.64
testWebsocketSessionFunction · 0.64