use tempfile::TempDir;
pub(crate) trait Fixtures {
fn bind_addr(&self) -> String;
fn connect_addr(&self, listener_local_addr: &str) -> String;
fn path(&self, name: &str) -> String;
fn unbound_addr(&self) -> Option<String>;
}
pub(crate) struct TokioFixtures {
dir: TempDir,
}
impl TokioFixtures {
pub(crate) fn new() -> Self {
Self {
dir: TempDir::new().expect("failed to create temp dir"),
}
}
}
impl Fixtures for TokioFixtures {
fn bind_addr(&self) -> String {
"127.0.0.1:0".to_string()
}
fn connect_addr(&self, listener_local_addr: &str) -> String {
listener_local_addr.to_string()
}
fn path(&self, name: &str) -> String {
self.dir
.path()
.join(name)
.to_str()
.expect("temp path is valid UTF-8")
.to_string()
}
fn unbound_addr(&self) -> Option<String> {
Some("127.0.0.1:1".to_string())
}
}