fn can_navigate_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));

    let base_url = Url::parse(&format!("http://localhost:{}/", port))?;
    let initial_body = reqwest::blocking::get(base_url.as_str())?.error_for_status()?;
    let initial_parsed = Document::from_read(initial_body)?;
    for &directory in DIRECTORIES {
        let dir_elem = get_link_from_text(&initial_parsed, &directory).expect("Dir not found.");
        let body =
            reqwest::blocking::get(&format!("{}{}", base_url, dir_elem))?.error_for_status()?;
        let parsed = Document::from_read(body)?;
        let back_link =
            get_link_from_text(&parsed, "Parent directory").expect("Back link not found.");
        let resp = reqwest::blocking::get(&format!("{}{}", base_url, back_link))?;

        // Now check that we can actually get back to the original location we came from using the
        // link.
        assert_eq!(resp.url().as_str(), base_url.as_str());
    }

    child.kill()?;

    Ok(())
}
/// We can navigate into directories and back using shown links.
We can navigate into directories and back using shown links.
We can navigate into directories and back using shown links .
fn can_navigate_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));
    let base_url = Url::parse(&format!("http://localhost:{}/", port))?;
    let initial_body = reqwest::blocking::get(base_url.as_str())?.error_for_status()?;
    let initial_parsed = Document::from_read(initial_body)?;
    for &directory in DIRECTORIES {
        let dir_elem = get_link_from_text(&initial_parsed, &directory).expect("Dir not found.");
        let body =
            reqwest::blocking::get(&format!("{}{}", base_url, dir_elem))?.error_for_status()?;
        let parsed = Document::from_read(body)?;
        let back_link =
            get_link_from_text(&parsed, "Parent directory").expect("Back link not found.");
        let resp = reqwest::blocking::get(&format!("{}{}", base_url, back_link))?;
        // Now check that we can actually get back to the original location we came from using the
        // link.
        assert_eq!(resp.url().as_str(), base_url.as_str());
    }
    child.kill()?;
    Ok(())
}
fn can_navigate_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 ) ) ; let base_url = Url :: parse ( & format ! ( " " port ) ) ? ; let initial_body = reqwest :: blocking :: get ( base_url . as_str ( ) ) ? . error_for_status ( ) ? ; let initial_parsed = Document :: from_read ( initial_body ) ? ; for & directory in DIRECTORIES { let dir_elem = get_link_from_text ( & initial_parsed , & directory ) . expect ( " " ) ; let body = reqwest :: blocking :: get ( & format ! ( " " base_url dir_elem ) ) ? . error_for_status ( ) ? ; let parsed = Document :: from_read ( body ) ? ; let back_link = get_link_from_text ( & parsed , " " ) . expect ( " " ) ; let resp = reqwest :: blocking :: get ( & format ! ( " " base_url back_link ) ) ? ; // Now check that we can actually get back to the original location we came from using the // link. assert_eq ! ( resp url ( ) as_str ( ) base_url as_str ( ) ) ; } child . kill ( ) ? ; Ok ( ( ) ) }
We can navigate into directories and back using shown links.
We can navigate into directories and back using shown links .
tmpdir
TempDir
port
u16
tmpdir
TempDir
port
u16