use std::os::unix::net::UnixListener;

use rpki::fetch::rsync::{LocalDirRsyncFetcher, RsyncFetcher};

#[test]
fn local_dir_rsync_fetcher_normalizes_base_and_skips_non_files() {
    let td = tempfile::tempdir().expect("tempdir");
    let dir = td.path();

    std::fs::write(dir.join("a.txt"), b"a").expect("write file");

    // Create a Unix domain socket entry; metadata().is_file() should be false.
    let _sock = UnixListener::bind(dir.join("sock")).expect("bind unix socket");

    let fetcher = LocalDirRsyncFetcher::new(dir);

    let out = fetcher
        .fetch_objects("rsync://example.test/repo") // intentionally no trailing slash
        .expect("fetch objects");

    let uris: Vec<_> = out.iter().map(|(u, _)| u.as_str()).collect();
    assert!(uris.contains(&"rsync://example.test/repo/a.txt"));
    assert!(!uris.iter().any(|u| u.ends_with("/sock")));
}
