MCPcopy Index your code
hub / github.com/InfinitiBit/graphbit / test_error_conversions

Function test_error_conversions

tests/rust_unit_tests/error_tests.rs:91–125  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

89
90#[test]
91fn test_error_conversions() {
92 // Test reqwest::Error conversion - create a timeout error
93 let timeout_error = std::time::Duration::from_secs(1);
94 let client = reqwest::Client::builder()
95 .timeout(timeout_error)
96 .build()
97 .unwrap();
98
99 // Create a mock reqwest error by trying to connect to a non-existent server
100 // This will be converted to a GraphBitError::Network
101 let rt = tokio::runtime::Runtime::new().unwrap();
102 let reqwest_error =
103 rt.block_on(async { client.get("http://127.0.0.1:1").send().await.unwrap_err() });
104
105 let graphbit_error = GraphBitError::from(reqwest_error);
106 assert!(matches!(graphbit_error, GraphBitError::Network { .. }));
107
108 // Test serde_json::Error conversion
109 let json_error = serde_json::from_str::<serde_json::Value>("invalid json").unwrap_err();
110 let graphbit_error = GraphBitError::from(json_error);
111 assert!(matches!(
112 graphbit_error,
113 GraphBitError::Serialization { .. }
114 ));
115
116 // Test std::io::Error conversion
117 let io_error = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
118 let graphbit_error = GraphBitError::from(io_error);
119 assert!(matches!(graphbit_error, GraphBitError::Io { .. }));
120
121 // Test anyhow::Error conversion
122 let anyhow_error = anyhow::anyhow!("something went wrong");
123 let graphbit_error = GraphBitError::from(anyhow_error);
124 assert!(matches!(graphbit_error, GraphBitError::Internal { .. }));
125}
126
127#[test]
128fn test_error_retryability_comprehensive() {

Callers

nothing calls this directly

Calls 2

buildMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected