fn can_navigate_deep_into_dirs_and_back(tmpdir: TempDir, port: u16) -> Result<(), Error> {
    let mut child = Command::cargo_bin("miniserve")?
        .arg("-p")
        .arg(port.to_string())
        .arg(tmpdir.path())
        .stdout(Stdio::null())
        .spawn()?;

    sleep(Duration::from_secs(1));

    // Create a vector of directory names. We don't need to fetch the file and so we'll
    // remove that part.
    let dir_names = {
        let mut comps = DEEPLY_NESTED_FILE
            .split("/")
            .map(|d| format!("{}/", d))
            .collect::<Vec<String>>();
        comps.pop();
        comps
    };
    let base_url = Url::parse(&format!("http://localhost:{}/", port))?;

    // First we'll go forwards through the directory tree and then we'll go backwards.
    // In the end, we'll have to end up where we came from.
    let mut next_url = base_url.clone();
    for dir_name in dir_names.iter() {
        let resp = reqwest::blocking::get(next_url.as_str())?;
        let body = resp.error_for_status()?;
        let parsed = Document::from_read(body)?;
        let dir_elem = get_link_from_text(&parsed, &dir_name).expect("Dir not found.");
        next_url = next_url.join(&dir_elem)?;
    }
    assert_ne!(base_url, next_url);

    // Now try to get out the tree again using links only.
    while next_url != base_url {
        let resp = reqwest::blocking::get(next_url.as_str())?;
        let body = resp.error_for_status()?;
        let parsed = Document::from_read(body)?;
        let dir_elem =
            get_link_from_text(&parsed, "Parent directory").expect("Back link not found.");
        next_url = next_url.join(&dir_elem)?;
    }
    assert_eq!(base_url, next_url);

    child.kill()?;

    Ok(())
}
/// We can navigate deep into the file tree and back using shown links.
We can navigate deep into the file tree and back using shown links.
We can navigate deep into the file tree and back using shown links .
fn can_navigate_deep_into_dirs_and_back(tmpdir: TempDir, port: u16) -> Result<(), Error> {
    let mut child = Command::cargo_bin("miniserve")?
        .arg("-p")
        .arg(port.to_string())
        .arg(tmpdir.path())
        .stdout(Stdio::null())
        .spawn()?;
    sleep(Duration::from_secs(1));
    // Create a vector of directory names. We don't need to fetch the file and so we'll
    // remove that part.
    let dir_names = {
        let mut comps = DEEPLY_NESTED_FILE
            .split("/")
            .map(|d| format!("{}/", d))
            .collect::<Vec<String>>();
        comps.pop();
        comps
    };
    let base_url = Url::parse(&format!("http://localhost:{}/", port))?;
    // First we'll go forwards through the directory tree and then we'll go backwards.
    // In the end, we'll have to end up where we came from.
    let mut next_url = base_url.clone();
    for dir_name in dir_names.iter() {
        let resp = reqwest::blocking::get(next_url.as_str())?;
        let body = resp.error_for_status()?;
        let parsed = Document::from_read(body)?;
        let dir_elem = get_link_from_text(&parsed, &dir_name).expect("Dir not found.");
        next_url = next_url.join(&dir_elem)?;
    }
    assert_ne!(base_url, next_url);
    // Now try to get out the tree again using links only.
    while next_url != base_url {
        let resp = reqwest::blocking::get(next_url.as_str())?;
        let body = resp.error_for_status()?;
        let parsed = Document::from_read(body)?;
        let dir_elem =
            get_link_from_text(&parsed, "Parent directory").expect("Back link not found.");
        next_url = next_url.join(&dir_elem)?;
    }
    assert_eq!(base_url, next_url);
    child.kill()?;
    Ok(())
}
fn can_navigate_deep_into_dirs_and_back ( tmpdir : TempDir , port : u16 ) -> Result < ( ) , Error > { let mut child = Command :: cargo_bin ( " " ) ? . arg ( " " ) . arg ( port . to_string ( ) ) . arg ( tmpdir . path ( ) ) . stdout ( Stdio :: null ( ) ) . spawn ( ) ? ; sleep ( Duration :: from_secs ( 1 ) ) ; // Create a vector of directory names. We don't need to fetch the file and so we'll // remove that part. let dir_names = { let mut comps = DEEPLY_NESTED_FILE . split ( " " ) . map ( | d | format ! ( " " d ) ) . collect :: < Vec < String > > ( ) ; comps . pop ( ) ; comps } ; let base_url = Url :: parse ( & format ! ( " " port ) ) ? ; // First we'll go forwards through the directory tree and then we'll go backwards. // In the end, we'll have to end up where we came from. let mut next_url = base_url . clone ( ) ; for dir_name in dir_names . iter ( ) { let resp = reqwest :: blocking :: get ( next_url . as_str ( ) ) ? ; let body = resp . error_for_status ( ) ? ; let parsed = Document :: from_read ( body ) ? ; let dir_elem = get_link_from_text ( & parsed , & dir_name ) . expect ( " " ) ; next_url = next_url . join ( & dir_elem ) ? ; } assert_ne ! ( base_url next_url ) ; // Now try to get out the tree again using links only. while next_url != base_url { let resp = reqwest :: blocking :: get ( next_url . as_str ( ) ) ? ; let body = resp . error_for_status ( ) ? ; let parsed = Document :: from_read ( body ) ? ; let dir_elem = get_link_from_text ( & parsed , " " ) . expect ( " " ) ; next_url = next_url . join ( & dir_elem ) ? ; } assert_eq ! ( base_url next_url ) ; child . kill ( ) ? ; Ok ( ( ) ) }
We can navigate deep into the file tree and back using shown links.
We can navigate deep into the file tree and back using shown links .
tmpdir
TempDir
port
u16
tmpdir
TempDir
port
u16