()
| 417 | /// the server responds with a JSON-encoded response. |
| 418 | #[tokio::test] |
| 419 | async fn json_request_gets_json_response() { |
| 420 | let server = NativeTestServer::start().await; |
| 421 | |
| 422 | let (mut stream, _ack) = do_handshake(server.addr, &HelloFrame::current()) |
| 423 | .await |
| 424 | .expect("handshake"); |
| 425 | |
| 426 | // Encode a Ping request as JSON. |
| 427 | let req = NativeRequest { |
| 428 | op: OpCode::Ping, |
| 429 | seq: 77, |
| 430 | fields: RequestFields::Text(TextFields::default()), |
| 431 | }; |
| 432 | let json_bytes = sonic_rs::to_vec(&req).expect("json encode"); |
| 433 | assert_eq!(json_bytes[0], b'{', "JSON must start with open brace"); |
| 434 | |
| 435 | write_frame(&mut stream, &json_bytes).await; |
| 436 | |
| 437 | let response_payload = tokio::time::timeout(Duration::from_secs(5), read_frame(&mut stream)) |
| 438 | .await |
| 439 | .expect("timeout") |
| 440 | .expect("response"); |
| 441 | |
| 442 | server.shutdown().await; |
| 443 | |
| 444 | // Response must be valid JSON (starts with `{`). |
| 445 | assert_eq!( |
| 446 | response_payload[0], b'{', |
| 447 | "JSON session must produce JSON response, got first byte 0x{:02X}", |
| 448 | response_payload[0] |
| 449 | ); |
| 450 | let resp: NativeResponse = sonic_rs::from_slice(&response_payload).expect("json decode"); |
| 451 | assert_eq!(resp.seq, 77, "seq must echo"); |
| 452 | assert_eq!( |
| 453 | resp.status, |
| 454 | nodedb_types::protocol::opcodes::ResponseStatus::Ok, |
| 455 | "Ping must return Ok" |
| 456 | ); |
| 457 | } |
| 458 | |
| 459 | /// MsgPack request → MsgPack response: if the client sends a MsgPack-encoded Ping, |
| 460 | /// the server responds with a MsgPack-encoded response. |
nothing calls this directly
no test coverage detected