1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-08-17 02:28:13 +02:00

support responses with null result ({"result":null})

Previously, we incorrectly interpreted these as neither a request nor a response, and we printed an error for them. This is incorrect behavior per JSON-RPC 2.0 spec; responses can have a null result.
This commit is contained in:
Quinn Slack 2017-01-22 14:58:40 -08:00
parent 6e06d561ec
commit d58e8cc226
3 changed files with 34 additions and 9 deletions

View file

@ -24,18 +24,19 @@ func TestRequest_MarshalJSON_jsonrpc(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if want := `"jsonrpc":"2.0"`; !strings.Contains(string(b), want) {
t.Errorf("got %s, want it to include the string %s", b, want)
if want := `{"method":"","id":0,"jsonrpc":"2.0"}`; string(b) != want {
t.Errorf("got %q, want %q", b, want)
}
}
func TestResponse_MarshalJSON_jsonrpc(t *testing.T) {
b, err := json.Marshal(&jsonrpc2.Response{})
null := json.RawMessage("null")
b, err := json.Marshal(&jsonrpc2.Response{Result: &null})
if err != nil {
t.Fatal(err)
}
if want := `"jsonrpc":"2.0"`; !strings.Contains(string(b), want) {
t.Errorf("got %s, want it to include the string %s", b, want)
if want := `{"id":0,"result":null,"jsonrpc":"2.0"}`; string(b) != want {
t.Errorf("got %q, want %q", b, want)
}
}