|
1 | | -#[cfg(feature = "schemars")] |
2 | 1 | mod tests { |
3 | 2 | use rmcp::model::{ClientJsonRpcMessage, ServerJsonRpcMessage}; |
4 | | - use super::*; |
5 | 3 | use schemars::schema_for; |
6 | 4 |
|
7 | 5 | #[test] |
8 | 6 | fn test_client_json_rpc_message_schema() { |
9 | 7 | let schema = schema_for!(ClientJsonRpcMessage); |
10 | 8 | let schema_str = serde_json::to_string_pretty(&schema).unwrap(); |
11 | | - let expected = std::fs::read_to_string("tests/test_message_schema/client_json_rpc_message_schema.json").unwrap(); |
12 | | - assert_eq!(schema_str, expected, "Schema generation for ClientJsonRpcMessage should match expected output"); |
| 9 | + let expected = std::fs::read_to_string( |
| 10 | + "tests/test_message_schema/client_json_rpc_message_schema.json", |
| 11 | + ) |
| 12 | + .unwrap(); |
| 13 | + |
| 14 | + // Parse both strings to JSON values for more robust comparison |
| 15 | + let schema_json: serde_json::Value = serde_json::from_str(&schema_str).unwrap(); |
| 16 | + let expected_json: serde_json::Value = serde_json::from_str(&expected).unwrap(); |
| 17 | + assert_eq!( |
| 18 | + schema_json, expected_json, |
| 19 | + "Schema generation for ClientJsonRpcMessage should match expected output" |
| 20 | + ); |
13 | 21 | } |
14 | 22 |
|
15 | 23 | #[test] |
16 | 24 | fn test_server_json_rpc_message_schema() { |
17 | 25 | let schema = schema_for!(ServerJsonRpcMessage); |
18 | 26 | let schema_str = serde_json::to_string_pretty(&schema).unwrap(); |
19 | | - let expected = std::fs::read_to_string("tests/test_message_schema/server_json_rpc_message_schema.json").unwrap(); |
20 | | - assert_eq!(schema_str, expected, "Schema generation for ServerJsonRpcMessage should match expected output"); |
| 27 | + let expected = std::fs::read_to_string( |
| 28 | + "tests/test_message_schema/server_json_rpc_message_schema.json", |
| 29 | + ) |
| 30 | + .unwrap(); |
| 31 | + |
| 32 | + // Parse both strings to JSON values for more robust comparison |
| 33 | + let schema_json: serde_json::Value = serde_json::from_str(&schema_str).unwrap(); |
| 34 | + let expected_json: serde_json::Value = serde_json::from_str(&expected).unwrap(); |
| 35 | + assert_eq!( |
| 36 | + schema_json, expected_json, |
| 37 | + "Schema generation for ServerJsonRpcMessage should match expected output" |
| 38 | + ); |
21 | 39 | } |
22 | 40 | } |
0 commit comments