feat: shared IONOS HTTP client with retry/backoff
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
use alpha_id::ionos::IonosClient;
|
||||
use std::io::Write;
|
||||
|
||||
fn mock_server(body: &'static str) -> (String, std::thread::JoinHandle<()>) {
|
||||
let server = tiny_http::Server::http("127.0.0.1:0").unwrap();
|
||||
let url = format!("http://{}", server.server_addr());
|
||||
let h = std::thread::spawn(move || {
|
||||
if let Ok(req) = server.recv() {
|
||||
let resp = tiny_http::Response::from_string(body);
|
||||
req.respond(resp).ok();
|
||||
}
|
||||
});
|
||||
(url, h)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn posts_json_and_parses_response() {
|
||||
let (url, h) = mock_server(r#"{"ok":true}"#);
|
||||
let mut tf = tempfile::NamedTempFile::new().unwrap();
|
||||
write!(tf, "test-token-123").unwrap();
|
||||
let c = IonosClient::new(&url, tf.path().to_str().unwrap()).unwrap();
|
||||
let v: serde_json::Value = c.post_json("/ping", &serde_json::json!({"x":1})).unwrap();
|
||||
assert_eq!(v["ok"], true);
|
||||
h.join().ok();
|
||||
}
|
||||
Reference in New Issue
Block a user