From cd955a71324d888d33b670f7c6a0cca278d76047 Mon Sep 17 00:00:00 2001 From: Albert Esteve Date: Tue, 29 Aug 2023 13:20:38 +0200 Subject: [PATCH] sound: introduce rstest crate Introduce 'rstest'[1] crate dependency to allow run multiple parametrized tests (and fixtures). [1] - https://docs.rs/rstest/latest/rstest/ Signed-off-by: Albert Esteve --- Cargo.lock | 57 ++++++++++++++++++++++++++++++++++++++++ crates/sound/Cargo.toml | 1 + crates/sound/src/main.rs | 12 ++++++--- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76f9d89..5007d0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -412,6 +412,12 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +[[package]] +name = "futures-timer" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" + [[package]] name = "futures-util" version = "0.3.28" @@ -868,12 +874,56 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +[[package]] +name = "relative-path" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c707298afce11da2efef2f600116fa93ffa7a032b5d7b628aa17711ec81383ca" + +[[package]] +name = "rstest" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97eeab2f3c0a199bc4be135c36c924b6590b88c377d416494288c14f2db30199" +dependencies = [ + "futures", + "futures-timer", + "rstest_macros", + "rustc_version", +] + +[[package]] +name = "rstest_macros" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d428f8247852f894ee1be110b375111b586d4fa431f6c46e64ba5a0dcccbe605" +dependencies = [ + "cfg-if", + "glob", + "proc-macro2", + "quote", + "regex", + "relative-path", + "rustc_version", + "syn 2.0.26", + "unicode-ident", +] + [[package]] name = "rustc-hash" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.37.23" @@ -907,6 +957,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "semver" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" + [[package]] name = "serde" version = "1.0.163" @@ -1211,6 +1267,7 @@ dependencies = [ "log", "pipewire", "pipewire-sys", + "rstest", "serial_test", "thiserror", "vhost", diff --git a/crates/sound/Cargo.toml b/crates/sound/Cargo.toml index 962fe01..55a6a6d 100644 --- a/crates/sound/Cargo.toml +++ b/crates/sound/Cargo.toml @@ -35,3 +35,4 @@ vmm-sys-util = "0.11" [dev-dependencies] serial_test = "1.0" +rstest = "0.18.2" diff --git a/crates/sound/src/main.rs b/crates/sound/src/main.rs index 0d52321..f4dcced 100644 --- a/crates/sound/src/main.rs +++ b/crates/sound/src/main.rs @@ -43,6 +43,7 @@ mod tests { use serial_test::serial; use super::*; + use rstest::*; impl SoundArgs { fn from_args(socket: &str) -> Self { @@ -65,21 +66,24 @@ mod tests { assert_eq!(config.get_socket_path(), "/tmp/vhost-sound.socket"); } - #[test] + #[rstest] #[serial] - fn test_cli_backend_arg() { + #[case::null_backend("null", BackendType::Null)] + #[case::pipewire("pipewire", BackendType::Pipewire)] + #[case::alsa("alsa", BackendType::Alsa)] + fn test_cli_backend_arg(#[case] backend_name: &str, #[case] backend: BackendType) { let args: SoundArgs = Parser::parse_from([ "", "--socket", "/tmp/vhost-sound.socket ", "--backend", - "null", + backend_name, ]); let config = SoundConfig::try_from(args); assert!(config.is_ok()); let config = config.unwrap(); - assert_eq!(config.get_audio_backend(), BackendType::Null); + assert_eq!(config.get_audio_backend(), backend); } }