MCPcopy Create free account
hub / github.com/asternic/wuzapi / assertJSONRPC20Error

Function assertJSONRPC20Error

stdio_test.go:427–447  ·  view source on GitHub ↗

assertJSONRPC20Error checks that a response is an error JSON-RPC 2.0 response

(t *testing.T, response map[string]interface{}, expectedID interface{}, expectedCode float64)

Source from the content-addressed store, hash-verified

425
426// assertJSONRPC20Error checks that a response is an error JSON-RPC 2.0 response
427func assertJSONRPC20Error(t *testing.T, response map[string]interface{}, expectedID interface{}, expectedCode float64) map[string]interface{} {
428 t.Helper()
429 expected := map[string]interface{}{
430 "jsonrpc": "2.0",
431 "id": expectedID,
432 }
433 if diff := compareJSON(expected, response); diff != "" {
434 t.Errorf("Response structure mismatch:\n%s", diff)
435 }
436 if response["result"] != nil {
437 t.Fatalf("Expected no result on error, got: %v", response["result"])
438 }
439 if response["error"] == nil {
440 t.Fatalf("Expected error field, got nil")
441 }
442 errorObj := response["error"].(map[string]interface{})
443 if errorObj["code"].(float64) != expectedCode {
444 t.Errorf("Expected error code %v, got: %v", expectedCode, errorObj["code"])
445 }
446 return errorObj
447}
448
449// compareJSON compares two JSON objects and returns a human-readable diff
450func compareJSON(expected, actual map[string]interface{}) string {

Callers

nothing calls this directly

Calls 1

compareJSONFunction · 0.85

Tested by

no test coverage detected