@@ -25,6 +25,7 @@ type RequestData struct {
2525var responseBody = ""
2626
2727var httpStatusCode = http .StatusOK
28+
2829var httpServer * httptest.Server
2930
3031// start the test-http server and stop it when tests are finished
@@ -173,6 +174,36 @@ func TestRpcClient_Call(t *testing.T) {
173174 },
174175 })
175176 check .Equal (`{"method":"nestedStruct","params":{"name":"Mars","properties":{"distance":54600000,"color":"red"}},"id":0,"jsonrpc":"2.0"}` , (<- requestChan ).body )
177+
178+ // test nil slice handling for JSON-RPC compliance
179+ var nilSlice []int = nil
180+ rpcClient .Call (context .Background (), "nilSliceParam" , nilSlice )
181+ check .Equal (`{"method":"nilSliceParam","params":[],"id":0,"jsonrpc":"2.0"}` , (<- requestChan ).body )
182+
183+ // test nil map handling for JSON-RPC compliance
184+ var nilMap map [string ]interface {} = nil
185+ rpcClient .Call (context .Background (), "nilMapParam" , nilMap )
186+ check .Equal (`{"method":"nilMapParam","params":{},"id":0,"jsonrpc":"2.0"}` , (<- requestChan ).body )
187+
188+ // test empty slice
189+ emptySlice := []int {}
190+ rpcClient .Call (context .Background (), "emptySliceParam" , emptySlice )
191+ check .Equal (`{"method":"emptySliceParam","params":[],"id":0,"jsonrpc":"2.0"}` , (<- requestChan ).body )
192+
193+ // test empty map
194+ emptyMap := map [string ]interface {}{}
195+ rpcClient .Call (context .Background (), "emptyMapParam" , emptyMap )
196+ check .Equal (`{"method":"emptyMapParam","params":{},"id":0,"jsonrpc":"2.0"}` , (<- requestChan ).body )
197+
198+ // test nil slice of strings
199+ var nilStringSlice []string = nil
200+ rpcClient .Call (context .Background (), "nilStringSliceParam" , nilStringSlice )
201+ check .Equal (`{"method":"nilStringSliceParam","params":[],"id":0,"jsonrpc":"2.0"}` , (<- requestChan ).body )
202+
203+ // test nil map with string keys
204+ var nilStringMap map [string ]string = nil
205+ rpcClient .Call (context .Background (), "nilStringMapParam" , nilStringMap )
206+ check .Equal (`{"method":"nilStringMapParam","params":{},"id":0,"jsonrpc":"2.0"}` , (<- requestChan ).body )
176207}
177208
178209func TestRpcClient_CallBatch (t * testing.T ) {
0 commit comments