sound: test cli backend argument

Signed-off-by: Albert Esteve <aesteve@redhat.com>
This commit is contained in:
Albert Esteve 2023-08-29 13:12:46 +02:00
parent 6c5b2db7db
commit 4867edc009
2 changed files with 24 additions and 2 deletions

View File

@ -91,7 +91,7 @@ impl From<stream::Error> 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 {

View File

@ -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);
}
}