From 4867edc009af4a2db9e51b5e715bf66fa78fd529 Mon Sep 17 00:00:00 2001 From: Albert Esteve Date: Tue, 29 Aug 2023 13:12:46 +0200 Subject: [PATCH] sound: test cli backend argument Signed-off-by: Albert Esteve --- crates/sound/src/lib.rs | 6 +++++- crates/sound/src/main.rs | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/crates/sound/src/lib.rs b/crates/sound/src/lib.rs index 2ad4dde..23fed0a 100644 --- a/crates/sound/src/lib.rs +++ b/crates/sound/src/lib.rs @@ -91,7 +91,7 @@ impl From for Error { } } -#[derive(ValueEnum, Clone, Default, Debug)] +#[derive(ValueEnum, Clone, Copy, Default, Debug, Eq, PartialEq)] pub enum BackendType { #[default] Null, @@ -232,6 +232,10 @@ impl SoundConfig { pub fn get_socket_path(&self) -> String { String::from(&self.socket) } + + pub fn get_audio_backend(&self) -> BackendType { + self.audio_backend + } } pub struct IOMessage { diff --git a/crates/sound/src/main.rs b/crates/sound/src/main.rs index 8f2c627..0d52321 100644 --- a/crates/sound/src/main.rs +++ b/crates/sound/src/main.rs @@ -55,7 +55,7 @@ mod tests { #[test] #[serial] - fn test_vsock_config_setup() { + fn test_sound_config_setup() { let args = SoundArgs::from_args("/tmp/vhost-sound.socket"); let config = SoundConfig::try_from(args); @@ -64,4 +64,22 @@ mod tests { let config = config.unwrap(); assert_eq!(config.get_socket_path(), "/tmp/vhost-sound.socket"); } + + #[test] + #[serial] + fn test_cli_backend_arg() { + let args: SoundArgs = Parser::parse_from([ + "", + "--socket", + "/tmp/vhost-sound.socket ", + "--backend", + "null", + ]); + + let config = SoundConfig::try_from(args); + assert!(config.is_ok()); + + let config = config.unwrap(); + assert_eq!(config.get_audio_backend(), BackendType::Null); + } }