From 301c92b1ba21004341ccecbbbb07a0a0fb64b5dd Mon Sep 17 00:00:00 2001 From: a <a@tuxpa.in> Date: Thu, 13 Jul 2023 23:25:09 -0500 Subject: [PATCH] fix more tests --- contrib/codecs/websocket/websocket_test.go | 9 +++++---- pkg/jrpctest/testdata/invalid-badid.js | 4 ++-- pkg/jrpctest/testdata/invalid-batch.js | 4 ++-- pkg/jrpctest/testdata/reqresp-batch.js | 4 ++-- pkg/jrpctest/testdata/reqresp-echo.js | 12 ++++++------ pkg/jrpctest/testdata/reqresp-namedparam.js | 2 +- pkg/jrpctest/testdata/reqresp-noargsrets.js | 4 ++-- pkg/jrpctest/testdata/reqresp-nomethod.js | 2 +- pkg/jrpctest/testdata/reqresp-noparam.js | 2 +- pkg/jrpctest/testdata/reqresp-paramsnull.js | 2 +- pkg/jrpctest/testdata/revcall.js.old | 2 +- pkg/jrpctest/testdata/revcall2.js.old | 2 +- 12 files changed, 25 insertions(+), 24 deletions(-) diff --git a/contrib/codecs/websocket/websocket_test.go b/contrib/codecs/websocket/websocket_test.go index 360ce02..0979b5a 100644 --- a/contrib/codecs/websocket/websocket_test.go +++ b/contrib/codecs/websocket/websocket_test.go @@ -2,14 +2,15 @@ package websocket_test import ( "context" + "net/http/httptest" + "strings" + "testing" + "gfx.cafe/open/jrpc/contrib/codecs/websocket" "gfx.cafe/open/jrpc/contrib/jmux" "gfx.cafe/open/jrpc/pkg/codec" "gfx.cafe/open/jrpc/pkg/jrpctest" "gfx.cafe/open/jrpc/pkg/server" - "net/http/httptest" - "strings" - "testing" ) func TestWebsocketClientHeaders(t *testing.T) { @@ -153,7 +154,7 @@ func TestClientWebsocketLargeMessage(t *testing.T) { } var r string - if err := c.Do(nil, &r, "test_largeResp", nil); err != nil { + if err := c.Do(nil, &r, "test/largeResp", nil); err != nil { t.Fatal("call failed:", err) } if len(r) != respLength { diff --git a/pkg/jrpctest/testdata/invalid-badid.js b/pkg/jrpctest/testdata/invalid-badid.js index 2202b8c..358ed1d 100644 --- a/pkg/jrpctest/testdata/invalid-badid.js +++ b/pkg/jrpctest/testdata/invalid-badid.js @@ -1,7 +1,7 @@ // This test checks processing of messages with invalid ID. ---> {"id":[],"method":"test_foo"} +--> {"id":[],"method":"test/foo"} <-- {"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"invalid request"}} ---> {"id":{},"method":"test_foo"} +--> {"id":{},"method":"test/foo"} <-- {"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"invalid request"}} diff --git a/pkg/jrpctest/testdata/invalid-batch.js b/pkg/jrpctest/testdata/invalid-batch.js index 768dbc8..d2a99a1 100644 --- a/pkg/jrpctest/testdata/invalid-batch.js +++ b/pkg/jrpctest/testdata/invalid-batch.js @@ -13,5 +13,5 @@ --> [null] <-- [{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"invalid request"}}] ---> [{"jsonrpc":"2.0","id":1,"method":"test_echo","params":["foo",1]},55,{"jsonrpc":"2.0","id":2,"method":"unknown_method"},{"foo":"bar"}] -<-- [{"jsonrpc":"2.0","id":1,"result":{"String":"foo","Int":1,"Args":null}},{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"invalid request"}},{"jsonrpc":"2.0","id":2,"error":{"code":-32601,"message":"the method unknown_method does not exist/is not available"}},{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"invalid request"}}] +--> [{"jsonrpc":"2.0","id":1,"method":"test/echo","params":["foo",1]},55,{"jsonrpc":"2.0","id":2,"method":"unknown/method"},{"foo":"bar"}] +<-- [{"jsonrpc":"2.0","id":1,"result":{"String":"foo","Int":1,"Args":null}},{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"invalid request"}},{"jsonrpc":"2.0","id":2,"error":{"code":-32601,"message":"the method unknown/method does not exist/is not available"}},{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"invalid request"}}] diff --git a/pkg/jrpctest/testdata/reqresp-batch.js b/pkg/jrpctest/testdata/reqresp-batch.js index 4d796c0..fdc8db2 100644 --- a/pkg/jrpctest/testdata/reqresp-batch.js +++ b/pkg/jrpctest/testdata/reqresp-batch.js @@ -1,9 +1,9 @@ // There is no response for all-notification batches. ---> [{"jsonrpc":"2.0","method":"test_echo","params":["x",99]}] +--> [{"jsonrpc":"2.0","method":"test/echo","params":["x",99]}] <-- // This test checks regular batch calls. ---> [{"jsonrpc":"2.0","id":2,"method":"test_echo","params":[]}, {"jsonrpc":"2.0","id": 3,"method":"test_echo","params":["x",3]}] +--> [{"jsonrpc":"2.0","id":2,"method":"test/echo","params":[]}, {"jsonrpc":"2.0","id": 3,"method":"test/echo","params":["x",3]}] <-- [{"jsonrpc":"2.0","id":2,"error":{"code":-32602,"message":"missing value for required argument 0"}},{"jsonrpc":"2.0","id":3,"result":{"String":"x","Int":3,"Args":null}}] diff --git a/pkg/jrpctest/testdata/reqresp-echo.js b/pkg/jrpctest/testdata/reqresp-echo.js index 7a9e903..fb20c6f 100644 --- a/pkg/jrpctest/testdata/reqresp-echo.js +++ b/pkg/jrpctest/testdata/reqresp-echo.js @@ -1,16 +1,16 @@ -// This test calls the test_echo method. +// This test calls the test/echo method. ---> {"jsonrpc": "2.0", "id": 2, "method": "test_echo", "params": []} +--> {"jsonrpc": "2.0", "id": 2, "method": "test/echo", "params": []} <-- {"jsonrpc":"2.0","id":2,"error":{"code":-32602,"message":"missing value for required argument 0"}} ---> {"jsonrpc": "2.0", "id": 2, "method": "test_echo", "params": ["x"]} +--> {"jsonrpc": "2.0", "id": 2, "method": "test/echo", "params": ["x"]} <-- {"jsonrpc":"2.0","id":2,"error":{"code":-32602,"message":"missing value for required argument 1"}} ---> {"jsonrpc": "2.0", "id": 2, "method": "test_echo", "params": ["x", 3]} +--> {"jsonrpc": "2.0", "id": 2, "method": "test/echo", "params": ["x", 3]} <-- {"jsonrpc":"2.0","id":2,"result":{"String":"x","Int":3,"Args":null}} ---> {"jsonrpc": "2.0", "id": 2, "method": "test_echo", "params": ["x", 3, {"S": "foo"}]} +--> {"jsonrpc": "2.0", "id": 2, "method": "test/echo", "params": ["x", 3, {"S": "foo"}]} <-- {"jsonrpc":"2.0","id":2,"result":{"String":"x","Int":3,"Args":{"S":"foo"}}} ---> {"jsonrpc": "2.0", "id": 2, "method": "test_echoWithCtx", "params": ["x", 3, {"S": "foo"}]} +--> {"jsonrpc": "2.0", "id": 2, "method": "test/echoWithCtx", "params": ["x", 3, {"S": "foo"}]} <-- {"jsonrpc":"2.0","id":2,"result":{"String":"x","Int":3,"Args":{"S":"foo"}}} diff --git a/pkg/jrpctest/testdata/reqresp-namedparam.js b/pkg/jrpctest/testdata/reqresp-namedparam.js index 9a9372b..e89026c 100644 --- a/pkg/jrpctest/testdata/reqresp-namedparam.js +++ b/pkg/jrpctest/testdata/reqresp-namedparam.js @@ -1,5 +1,5 @@ // This test checks that an error response is sent for calls // with named parameters. ---> {"jsonrpc":"2.0","method":"test_echo","params":{"int":23},"id":3} +--> {"jsonrpc":"2.0","method":"test/echo","params":{"int":23},"id":3} <-- {"jsonrpc":"2.0","id":3,"error":{"code":-32602,"message":"non-array args"}} diff --git a/pkg/jrpctest/testdata/reqresp-noargsrets.js b/pkg/jrpctest/testdata/reqresp-noargsrets.js index e61cc70..258959d 100644 --- a/pkg/jrpctest/testdata/reqresp-noargsrets.js +++ b/pkg/jrpctest/testdata/reqresp-noargsrets.js @@ -1,4 +1,4 @@ -// This test calls the test_noArgsRets method. +// This test calls the test/noArgsRets method. ---> {"jsonrpc": "2.0", "id": "foo", "method": "test_noArgsRets", "params": []} +--> {"jsonrpc": "2.0", "id": "foo", "method": "test/noArgsRets", "params": []} <-- {"jsonrpc":"2.0","id":"foo","result":null} diff --git a/pkg/jrpctest/testdata/reqresp-nomethod.js b/pkg/jrpctest/testdata/reqresp-nomethod.js index 97a1956..e4ae7a7 100644 --- a/pkg/jrpctest/testdata/reqresp-nomethod.js +++ b/pkg/jrpctest/testdata/reqresp-nomethod.js @@ -1,4 +1,4 @@ // This test calls a method that doesn't exist. ---> {"jsonrpc": "2.0", "id": 2, "method": "invalid_method", "params": [2, 3]} +--> {"jsonrpc": "2.0", "id": 2, "method": "invalid/method", "params": [2, 3]} <-- {"jsonrpc":"2.0","id":2,"error":{"code":-32601,"message":"the method invalid/method does not exist/is not available"}} diff --git a/pkg/jrpctest/testdata/reqresp-noparam.js b/pkg/jrpctest/testdata/reqresp-noparam.js index 2edf486..b17725c 100644 --- a/pkg/jrpctest/testdata/reqresp-noparam.js +++ b/pkg/jrpctest/testdata/reqresp-noparam.js @@ -1,4 +1,4 @@ // This test checks that calls with no parameters work. ---> {"jsonrpc":"2.0","method":"test_noArgsRets","id":3} +--> {"jsonrpc":"2.0","method":"test/noArgsRets","id":3} <-- {"jsonrpc":"2.0","id":3,"result":null} diff --git a/pkg/jrpctest/testdata/reqresp-paramsnull.js b/pkg/jrpctest/testdata/reqresp-paramsnull.js index 8a01bae..89ec8f8 100644 --- a/pkg/jrpctest/testdata/reqresp-paramsnull.js +++ b/pkg/jrpctest/testdata/reqresp-paramsnull.js @@ -1,4 +1,4 @@ // This test checks that calls with "params":null work. ---> {"jsonrpc":"2.0","method":"test_noArgsRets","params":null,"id":3} +--> {"jsonrpc":"2.0","method":"test/noArgsRets","params":null,"id":3} <-- {"jsonrpc":"2.0","id":3,"result":null} diff --git a/pkg/jrpctest/testdata/revcall.js.old b/pkg/jrpctest/testdata/revcall.js.old index 695d985..f7ce2db 100644 --- a/pkg/jrpctest/testdata/revcall.js.old +++ b/pkg/jrpctest/testdata/revcall.js.old @@ -1,6 +1,6 @@ // This test checks reverse calls. ---> {"jsonrpc":"2.0","id":2,"method":"test_callMeBack","params":["foo",[1]]} +--> {"jsonrpc":"2.0","id":2,"method":"test/callMeBack","params":["foo",[1]]} <-- {"jsonrpc":"2.0","id":1,"method":"foo","params":[1]} --> {"jsonrpc":"2.0","id":1,"result":"my result"} <-- {"jsonrpc":"2.0","id":2,"result":"my result"} diff --git a/pkg/jrpctest/testdata/revcall2.js.old b/pkg/jrpctest/testdata/revcall2.js.old index acab465..5cca063 100644 --- a/pkg/jrpctest/testdata/revcall2.js.old +++ b/pkg/jrpctest/testdata/revcall2.js.old @@ -1,6 +1,6 @@ // This test checks reverse calls. ---> {"jsonrpc":"2.0","id":2,"method":"test_callMeBackLater","params":["foo",[1]]} +--> {"jsonrpc":"2.0","id":2,"method":"test/callMeBackLater","params":["foo",[1]]} <-- {"jsonrpc":"2.0","id":2,"result":null} <-- {"jsonrpc":"2.0","id":1,"method":"foo","params":[1]} --> {"jsonrpc":"2.0","id":1,"result":"my result"} -- GitLab