meow servers validation
continuous-integration/drone/push Build is failing
continuous-integration/drone Build is passing

This commit is contained in:
yves committed 2026-11-21 17:27:41 +01:00
1 parent 6ea7512af8
commit af12f4ebcf
6 files changed
+202 -103

No files matched your search

+43
View File
@@ -917,3 +917,46 @@ async fn background_watch_peeks_without_consuming() {
assert!(!path.exists());
let _ = std::fs::remove_dir_all(&dir);
}
/// Adding something that is not a Meow v2 server gives a clear error.
#[tokio::test(flavor = "multi_thread")]
async fn adding_a_non_meow_server_is_reported_clearly() {
use std::io::{Read, Write};
// A v1-like server: answers every path with an HTML page (or a 404 for the second).
fn fake(status: &'static str, body: &'static str) -> String {
let l = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
let url = format!("http://{}", l.local_addr().unwrap());
std::thread::spawn(move || {
for mut s in l.incoming().flatten() {
let mut buf = [0u8; 1024];
let _ = s.read(&mut buf);
let _ = write!(
s,
"HTTP/1.1 {status}\r\nContent-Type: text/html\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
body.len()
);
}
});
url
}
let dir = tmpdir();
let mut c = client(&dir, "alice", &[]).await;
let html = fake("200 OK", "<html><body>meow v1</body></html>");
assert!(matches!(
c.add_server(&html).await,
Err(meow_client::Error::NotAMeowServer(_))
));
let missing = fake("404 Not Found", "not found");
assert!(matches!(
c.add_server(&missing).await,
Err(meow_client::Error::NotAMeowServer(_))
));
let closed = {
let l = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
format!("http://{}", l.local_addr().unwrap())
}; // listener dropped: nothing listens there
let err = c.add_server(&closed).await.unwrap_err();
assert!(matches!(err, meow_client::Error::Unreachable(_)), "{err}");
assert!(c.servers().is_empty());
let _ = std::fs::remove_dir_all(&dir);
}