mirror of
https://github.com/rust-vmm/vhost-device.git
synced 2026-01-08 20:57:35 +00:00
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 <aesteve@redhat.com>
This commit is contained in:
parent
4867edc009
commit
cd955a7132
57
Cargo.lock
generated
57
Cargo.lock
generated
@ -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",
|
||||
|
||||
@ -35,3 +35,4 @@ vmm-sys-util = "0.11"
|
||||
|
||||
[dev-dependencies]
|
||||
serial_test = "1.0"
|
||||
rstest = "0.18.2"
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user