Skip to content

Commit

Permalink
test: add the field to http header of existing tests
Browse files Browse the repository at this point in the history
Signed-off-by: 170210 <j170210@icloud.com>
  • Loading branch information
170210 committed Jul 21, 2023
1 parent 535d824 commit 9dac9e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions rpc/jsonrpc/server/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var (
TestFuncMap = map[string]*RPCFunc{"c": TestRPCFunc}
TestGoodBody = `{"jsonrpc": "2.0", "method": "c", "id": "0", "params": null}`
TestBadParams = `{"jsonrpc": "2.0", "method": "c", "id": "0", "params": "s=a,i=b"}`

TestMaxRequestBatchRequest = "10"
)

type FailManager struct {
Expand Down
7 changes: 6 additions & 1 deletion rpc/jsonrpc/server/http_json_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func TestRPCParams(t *testing.T) {

for i, tt := range tests {
req, _ := http.NewRequest("POST", "http://localhost/", strings.NewReader(tt.payload))
req.Header.Set("MaxRequestBatchRequest", TestMaxRequestBatchRequest)
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, req)
res := rec.Result()
Expand Down Expand Up @@ -109,6 +110,7 @@ func TestJSONRPCID(t *testing.T) {

for i, tt := range tests {
req, _ := http.NewRequest("POST", "http://localhost/", strings.NewReader(tt.payload))
req.Header.Set("MaxRequestBatchRequest", TestMaxRequestBatchRequest)
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, req)
res := rec.Result()
Expand Down Expand Up @@ -138,6 +140,7 @@ func TestRPCNotification(t *testing.T) {
mux := testMux()
body := strings.NewReader(`{"jsonrpc": "2.0"}`)
req, _ := http.NewRequest("POST", "http://localhost/", body)
req.Header.Set("MaxRequestBatchRequest", TestMaxRequestBatchRequest)
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, req)
res := rec.Result()
Expand Down Expand Up @@ -175,6 +178,7 @@ func TestRPCNotificationInBatch(t *testing.T) {
}
for i, tt := range tests {
req, _ := http.NewRequest("POST", "http://localhost/", strings.NewReader(tt.payload))
req.Header.Set("MaxRequestBatchRequest", TestMaxRequestBatchRequest)
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, req)
res := rec.Result()
Expand Down Expand Up @@ -230,7 +234,7 @@ func TestTooManyRPCNotificationInBatch_error(t *testing.T) {
// execute the batch request
mux := testMux()
req, _ := http.NewRequest("POST", "http://localhost/", strings.NewReader(string(jsonData)))
req.Header.Set("MaxRequestBatchRequest", "10")
req.Header.Set("MaxRequestBatchRequest", TestMaxRequestBatchRequest)
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, req)
res := rec.Result()
Expand Down Expand Up @@ -280,6 +284,7 @@ func TestMakeJSONRPCHandler_Unmarshal_WriteRPCResponseHTTPError_error(t *testing
func TestMakeJSONRPCHandler_last_WriteRPCResponseHTTP_error(t *testing.T) {
handlerFunc := makeJSONRPCHandler(TestFuncMap, log.TestingLogger())
req, _ := http.NewRequest("GET", "http://localhost/", strings.NewReader(TestGoodBody))
req.Header.Set("MaxRequestBatchRequest", TestMaxRequestBatchRequest)
// WriteRPCResponseHTTP error
rec := NewFailedWriteResponseWriter()
handlerFunc.ServeHTTP(rec, req)
Expand Down

0 comments on commit 9dac9e3

Please sign in to comment.