MCPcopy Index your code
hub / github.com/gavv/httpexpect / JSON

Method JSON

websocket_message.go:537–562  ·  view source on GitHub ↗

JSON returns a new Value instance with JSON contents of WebSocket message. JSON succeeds if JSON may be decoded from message content. Example: msg := conn.Expect() msg.JSON().Array().ConsistsOf("foo", "bar")

()

Source from the content-addressed store, hash-verified

535// msg := conn.Expect()
536// msg.JSON().Array().ConsistsOf("foo", "bar")
537func (wm *WebsocketMessage) JSON() *Value {
538 opChain := wm.chain.enter("JSON()")
539 defer opChain.leave()
540
541 if opChain.failed() {
542 return newValue(opChain, nil)
543 }
544
545 var value interface{}
546
547 if err := json.Unmarshal(wm.content, &value); err != nil {
548 opChain.fail(AssertionFailure{
549 Type: AssertValid,
550 Actual: &AssertionValue{
551 string(wm.content),
552 },
553 Errors: []error{
554 errors.New("failed to decode json"),
555 err,
556 },
557 })
558 return newValue(opChain, nil)
559 }
560
561 return newValue(opChain, value)
562}
563
564type wsMessageType int
565

Callers 1

Calls 5

newValueFunction · 0.85
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80

Tested by 1