|
@ -2,7 +2,7 @@ package server |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
"io/ioutil" |
|
|
|
|
|
|
|
|
"io" |
|
|
"net/http" |
|
|
"net/http" |
|
|
"net/http/httptest" |
|
|
"net/http/httptest" |
|
|
"strings" |
|
|
"strings" |
|
@ -65,7 +65,7 @@ func TestRPCParams(t *testing.T) { |
|
|
defer res.Body.Close() |
|
|
defer res.Body.Close() |
|
|
// Always expecting back a JSONRPCResponse
|
|
|
// Always expecting back a JSONRPCResponse
|
|
|
assert.NotZero(t, res.StatusCode, "#%d: should always return code", i) |
|
|
assert.NotZero(t, res.StatusCode, "#%d: should always return code", i) |
|
|
blob, err := ioutil.ReadAll(res.Body) |
|
|
|
|
|
|
|
|
blob, err := io.ReadAll(res.Body) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
t.Errorf("#%d: err reading body: %v", i, err) |
|
|
t.Errorf("#%d: err reading body: %v", i, err) |
|
|
continue |
|
|
continue |
|
@ -112,7 +112,7 @@ func TestJSONRPCID(t *testing.T) { |
|
|
res := rec.Result() |
|
|
res := rec.Result() |
|
|
// Always expecting back a JSONRPCResponse
|
|
|
// Always expecting back a JSONRPCResponse
|
|
|
assert.NotZero(t, res.StatusCode, "#%d: should always return code", i) |
|
|
assert.NotZero(t, res.StatusCode, "#%d: should always return code", i) |
|
|
blob, err := ioutil.ReadAll(res.Body) |
|
|
|
|
|
|
|
|
blob, err := io.ReadAll(res.Body) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
t.Errorf("#%d: err reading body: %v", i, err) |
|
|
t.Errorf("#%d: err reading body: %v", i, err) |
|
|
continue |
|
|
continue |
|
@ -142,7 +142,7 @@ func TestRPCNotification(t *testing.T) { |
|
|
|
|
|
|
|
|
// Always expecting back a JSONRPCResponse
|
|
|
// Always expecting back a JSONRPCResponse
|
|
|
require.True(t, statusOK(res.StatusCode), "should always return 2XX") |
|
|
require.True(t, statusOK(res.StatusCode), "should always return 2XX") |
|
|
blob, err := ioutil.ReadAll(res.Body) |
|
|
|
|
|
|
|
|
blob, err := io.ReadAll(res.Body) |
|
|
res.Body.Close() |
|
|
res.Body.Close() |
|
|
require.Nil(t, err, "reading from the body should not give back an error") |
|
|
require.Nil(t, err, "reading from the body should not give back an error") |
|
|
require.Equal(t, len(blob), 0, "a notification SHOULD NOT be responded to by the server") |
|
|
require.Equal(t, len(blob), 0, "a notification SHOULD NOT be responded to by the server") |
|
@ -178,7 +178,7 @@ func TestRPCNotificationInBatch(t *testing.T) { |
|
|
res := rec.Result() |
|
|
res := rec.Result() |
|
|
// Always expecting back a JSONRPCResponse
|
|
|
// Always expecting back a JSONRPCResponse
|
|
|
assert.True(t, statusOK(res.StatusCode), "#%d: should always return 2XX", i) |
|
|
assert.True(t, statusOK(res.StatusCode), "#%d: should always return 2XX", i) |
|
|
blob, err := ioutil.ReadAll(res.Body) |
|
|
|
|
|
|
|
|
blob, err := io.ReadAll(res.Body) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
t.Errorf("#%d: err reading body: %v", i, err) |
|
|
t.Errorf("#%d: err reading body: %v", i, err) |
|
|
continue |
|
|
continue |
|
@ -239,7 +239,7 @@ func TestRPCResponseCache(t *testing.T) { |
|
|
require.True(t, statusOK(res.StatusCode), "should always return 2XX") |
|
|
require.True(t, statusOK(res.StatusCode), "should always return 2XX") |
|
|
require.Equal(t, "max-age=31536000", res.Header.Get("Cache-control")) |
|
|
require.Equal(t, "max-age=31536000", res.Header.Get("Cache-control")) |
|
|
|
|
|
|
|
|
_, err := ioutil.ReadAll(res.Body) |
|
|
|
|
|
|
|
|
_, err := io.ReadAll(res.Body) |
|
|
res.Body.Close() |
|
|
res.Body.Close() |
|
|
require.Nil(t, err, "reading from the body should not give back an error") |
|
|
require.Nil(t, err, "reading from the body should not give back an error") |
|
|
|
|
|
|
|
@ -254,7 +254,7 @@ func TestRPCResponseCache(t *testing.T) { |
|
|
require.True(t, statusOK(res.StatusCode), "should always return 2XX") |
|
|
require.True(t, statusOK(res.StatusCode), "should always return 2XX") |
|
|
require.Equal(t, "", res.Header.Get("Cache-control")) |
|
|
require.Equal(t, "", res.Header.Get("Cache-control")) |
|
|
|
|
|
|
|
|
_, err = ioutil.ReadAll(res.Body) |
|
|
|
|
|
|
|
|
_, err = io.ReadAll(res.Body) |
|
|
res.Body.Close() |
|
|
res.Body.Close() |
|
|
require.Nil(t, err, "reading from the body should not give back an error") |
|
|
require.Nil(t, err, "reading from the body should not give back an error") |
|
|
} |
|
|
} |