(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestWireMessage(t *testing.T) { |
| 17 | for _, test := range []struct { |
| 18 | name string |
| 19 | msg jsonrpc2.Message |
| 20 | encoded []byte |
| 21 | }{{ |
| 22 | name: "notification", |
| 23 | msg: newNotification("alive", nil), |
| 24 | encoded: []byte(`{"jsonrpc":"2.0","method":"alive"}`), |
| 25 | }, { |
| 26 | name: "call", |
| 27 | msg: newCall("msg1", "ping", nil), |
| 28 | encoded: []byte(`{"jsonrpc":"2.0","id":"msg1","method":"ping"}`), |
| 29 | }, { |
| 30 | name: "response", |
| 31 | msg: newResponse("msg2", "pong", nil), |
| 32 | encoded: []byte(`{"jsonrpc":"2.0","id":"msg2","result":"pong"}`), |
| 33 | }, { |
| 34 | name: "numerical id", |
| 35 | msg: newCall(1, "poke", nil), |
| 36 | encoded: []byte(`{"jsonrpc":"2.0","id":1,"method":"poke"}`), |
| 37 | }, { |
| 38 | // originally reported in #39719, this checks that result is not present if |
| 39 | // it is an error response |
| 40 | name: "computing fix edits", |
| 41 | msg: newResponse(3, nil, jsonrpc2.NewError(0, "computing fix edits")), |
| 42 | encoded: []byte(`{ |
| 43 | "jsonrpc":"2.0", |
| 44 | "id":3, |
| 45 | "error":{ |
| 46 | "code":0, |
| 47 | "message":"computing fix edits" |
| 48 | } |
| 49 | }`), |
| 50 | }} { |
| 51 | b, err := jsonrpc2.EncodeMessage(test.msg) |
| 52 | if err != nil { |
| 53 | t.Fatal(err) |
| 54 | } |
| 55 | checkJSON(t, b, test.encoded) |
| 56 | msg, err := jsonrpc2.DecodeMessage(test.encoded) |
| 57 | if err != nil { |
| 58 | t.Fatal(err) |
| 59 | } |
| 60 | if !reflect.DeepEqual(msg, test.msg) { |
| 61 | t.Errorf("decoded message does not match\nGot:\n%+#v\nWant:\n%+#v", msg, test.msg) |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | func newNotification(method string, params any) jsonrpc2.Message { |
| 67 | msg, err := jsonrpc2.NewNotification(method, params) |
nothing calls this directly
no test coverage detected
searching dependent graphs…