feat: listen both ipv4 and ipv6 by default (#40)

This commit is contained in:
sigoden
2022-06-15 19:33:51 +08:00
committed by GitHub
parent 5142430e93
commit 12aafa00d8
8 changed files with 407 additions and 237 deletions

View File

@@ -19,25 +19,30 @@ fn bind_fails(tmpdir: TempDir, port: u16, #[case] args: &[&str]) -> Result<(), E
.arg(port.to_string())
.args(args)
.assert()
.stderr(predicates::str::contains("creating server listener"))
.stderr(predicates::str::contains("Failed to bind"))
.failure();
Ok(())
}
#[rstest]
fn bind_ipv4(server: TestServer) -> Result<(), Error> {
assert!(reqwest::blocking::get(format!("http://127.0.0.1:{}", server.port()).as_str()).is_ok());
Ok(())
}
#[rstest]
fn bind_ipv6(#[with(&["-b", "::"])] server: TestServer) -> Result<(), Error> {
#[case(server(&[] as &[&str]), true, true)]
#[case(server(&["-b", "0.0.0.0"]), true, false)]
#[case(server(&["-b", "127.0.0.1", "-b", "::1"]), true, true)]
fn bind_ipv4_ipv6(
#[case] server: TestServer,
#[case] bind_ipv4: bool,
#[case] bind_ipv6: bool,
) -> Result<(), Error> {
assert_eq!(
reqwest::blocking::get(format!("http://127.0.0.1:{}", server.port()).as_str()).is_ok(),
!cfg!(windows)
bind_ipv4
);
assert!(reqwest::blocking::get(format!("http://[::1]:{}", server.port()).as_str()).is_ok());
assert_eq!(
reqwest::blocking::get(format!("http://[::1]:{}", server.port()).as_str()).is_ok(),
bind_ipv6
);
Ok(())
}

View File

@@ -79,7 +79,7 @@ pub fn port() -> u16 {
free_local_port().expect("Couldn't find a free local port")
}
/// Run miniserve as a server; Start with a temporary directory, a free port and some
/// Run duf as a server; Start with a temporary directory, a free port and some
/// optional arguments then wait for a while for the server setup to complete.
#[fixture]
#[allow(dead_code)]