Skip to content

Commit f7c895a

Browse files
committed
chore(rmcp): improve json schema comparison in tests
Enhances the robustness of JSON schema comparison tests by parsing the schema strings into JSON values before comparison. This change prevents false test failures that could occur due to insignificant differences in whitespace or object key ordering. The test now properly focuses on structural equality rather than exact string matching.
1 parent 6a4a87a commit f7c895a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#[cfg(feature = "schemars")]
21
mod tests {
32
use rmcp::model::{ClientJsonRpcMessage, ServerJsonRpcMessage};
43
use super::*;
@@ -9,14 +8,22 @@ mod tests {
98
let schema = schema_for!(ClientJsonRpcMessage);
109
let schema_str = serde_json::to_string_pretty(&schema).unwrap();
1110
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");
11+
12+
// Parse both strings to JSON values for more robust comparison
13+
let schema_json: serde_json::Value = serde_json::from_str(&schema_str).unwrap();
14+
let expected_json: serde_json::Value = serde_json::from_str(&expected).unwrap();
15+
assert_eq!(schema_json, expected_json, "Schema generation for ClientJsonRpcMessage should match expected output");
1316
}
1417

1518
#[test]
1619
fn test_server_json_rpc_message_schema() {
1720
let schema = schema_for!(ServerJsonRpcMessage);
1821
let schema_str = serde_json::to_string_pretty(&schema).unwrap();
1922
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");
23+
24+
// Parse both strings to JSON values for more robust comparison
25+
let schema_json: serde_json::Value = serde_json::from_str(&schema_str).unwrap();
26+
let expected_json: serde_json::Value = serde_json::from_str(&expected).unwrap();
27+
assert_eq!(schema_json, expected_json, "Schema generation for ServerJsonRpcMessage should match expected output");
2128
}
2229
}

0 commit comments

Comments
 (0)