refactor(tvix/castore/directoryservice/from_addr): migrate to rstest
Change-Id: I52b14652822766421d66e95bc646ed7baecc705f Reviewed-on: https://cl.tvl.fyi/c/depot/+/11369 Reviewed-by: picnoir picnoir <picnoir@alternativebit.fr> Tested-by: BuildkiteCI
This commit is contained in:
parent
d94ff54d42
commit
936a175b2f
1 changed files with 19 additions and 18 deletions
|
@ -76,48 +76,49 @@ pub async fn from_addr(uri: &str) -> Result<Box<dyn DirectoryService>, crate::Er
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::from_addr;
|
use super::from_addr;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
use rstest::rstest;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
use test_case::test_case;
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref TMPDIR_SLED_1: TempDir = TempDir::new().unwrap();
|
static ref TMPDIR_SLED_1: TempDir = TempDir::new().unwrap();
|
||||||
static ref TMPDIR_SLED_2: TempDir = TempDir::new().unwrap();
|
static ref TMPDIR_SLED_2: TempDir = TempDir::new().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
/// This uses an unsupported scheme.
|
/// This uses an unsupported scheme.
|
||||||
#[test_case("http://foo.example/test", false; "unsupported scheme")]
|
#[case::unsupported_scheme("http://foo.example/test", false)]
|
||||||
/// This configures sled in temporary mode.
|
/// This configures sled in temporary mode.
|
||||||
#[test_case("sled://", true; "sled valid temporary")]
|
#[case::sled_valid_temporary("sled://", true)]
|
||||||
/// This configures sled with /, which should fail.
|
/// This configures sled with /, which should fail.
|
||||||
#[test_case("sled:///", false; "sled invalid root")]
|
#[case::sled_invalid_root("sled:///", false)]
|
||||||
/// This configures sled with a host, not path, which should fail.
|
/// This configures sled with a host, not path, which should fail.
|
||||||
#[test_case("sled://foo.example", false; "sled invalid host")]
|
#[case::sled_invalid_host("sled://foo.example", false)]
|
||||||
/// This configures sled with a valid path path, which should succeed.
|
/// This configures sled with a valid path path, which should succeed.
|
||||||
#[test_case(&format!("sled://{}", &TMPDIR_SLED_1.path().to_str().unwrap()), true; "sled valid path")]
|
#[case::sled_valid_path(&format!("sled://{}", &TMPDIR_SLED_1.path().to_str().unwrap()), true)]
|
||||||
/// This configures sled with a host, and a valid path path, which should fail.
|
/// This configures sled with a host, and a valid path path, which should fail.
|
||||||
#[test_case(&format!("sled://foo.example{}", &TMPDIR_SLED_2.path().to_str().unwrap()), false; "sled invalid host with valid path")]
|
#[case::sled_invalid_host_with_valid_path(&format!("sled://foo.example{}", &TMPDIR_SLED_2.path().to_str().unwrap()), false)]
|
||||||
/// This correctly sets the scheme, and doesn't set a path.
|
/// This correctly sets the scheme, and doesn't set a path.
|
||||||
#[test_case("memory://", true; "memory valid")]
|
#[case::memory_valid("memory://", true)]
|
||||||
/// This sets a memory url host to `foo`
|
/// This sets a memory url host to `foo`
|
||||||
#[test_case("memory://foo", false; "memory invalid host")]
|
#[case::memory_invalid_host("memory://foo", false)]
|
||||||
/// This sets a memory url path to "/", which is invalid.
|
/// This sets a memory url path to "/", which is invalid.
|
||||||
#[test_case("memory:///", false; "memory invalid root path")]
|
#[case::memory_invalid_root_path("memory:///", false)]
|
||||||
/// This sets a memory url path to "/foo", which is invalid.
|
/// This sets a memory url path to "/foo", which is invalid.
|
||||||
#[test_case("memory:///foo", false; "memory invalid root path foo")]
|
#[case::memory_invalid_root_path_foo("memory:///foo", false)]
|
||||||
/// Correct scheme to connect to a unix socket.
|
/// Correct scheme to connect to a unix socket.
|
||||||
#[test_case("grpc+unix:///path/to/somewhere", true; "grpc valid unix socket")]
|
#[case::grpc_valid_unix_socket("grpc+unix:///path/to/somewhere", true)]
|
||||||
/// Correct scheme for unix socket, but setting a host too, which is invalid.
|
/// Correct scheme for unix socket, but setting a host too, which is invalid.
|
||||||
#[test_case("grpc+unix://host.example/path/to/somewhere", false; "grpc invalid unix socket and host")]
|
#[case::grpc_invalid_unix_socket_and_host("grpc+unix://host.example/path/to/somewhere", false)]
|
||||||
/// Correct scheme to connect to localhost, with port 12345
|
/// Correct scheme to connect to localhost, with port 12345
|
||||||
#[test_case("grpc+http://[::1]:12345", true; "grpc valid IPv6 localhost port 12345")]
|
#[case::grpc_valid_ipv6_localhost_port_12345("grpc+http://[::1]:12345", true)]
|
||||||
/// Correct scheme to connect to localhost over http, without specifying a port.
|
/// Correct scheme to connect to localhost over http, without specifying a port.
|
||||||
#[test_case("grpc+http://localhost", true; "grpc valid http host without port")]
|
#[case::grpc_valid_http_host_without_port("grpc+http://localhost", true)]
|
||||||
/// Correct scheme to connect to localhost over http, without specifying a port.
|
/// Correct scheme to connect to localhost over http, without specifying a port.
|
||||||
#[test_case("grpc+https://localhost", true; "grpc valid https host without port")]
|
#[case::grpc_valid_https_host_without_port("grpc+https://localhost", true)]
|
||||||
/// Correct scheme to connect to localhost over http, but with additional path, which is invalid.
|
/// Correct scheme to connect to localhost over http, but with additional path, which is invalid.
|
||||||
#[test_case("grpc+http://localhost/some-path", false; "grpc valid invalid host and path")]
|
#[case::grpc_invalid_host_and_path("grpc+http://localhost/some-path", false)]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_from_addr_tokio(uri_str: &str, exp_succeed: bool) {
|
async fn test_from_addr_tokio(#[case] uri_str: &str, #[case] exp_succeed: bool) {
|
||||||
if exp_succeed {
|
if exp_succeed {
|
||||||
from_addr(uri_str).await.expect("should succeed");
|
from_addr(uri_str).await.expect("should succeed");
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue