fader_master/fader_master/tests/cli.rs

96 lines
2.5 KiB
Rust

use std::path::PathBuf;
use clap::{CommandFactory, Parser};
use fader_master::cli::{AudioArgument, Cli, Command, ProfileCommand, ThemeArgument};
#[test]
fn every_planned_command_is_present_in_help() {
let help = Cli::command().render_long_help().to_string();
for command in ["serve", "tui", "validate", "devices", "status", "profile"] {
assert!(help.contains(command), "missing {command:?} in help");
}
}
#[test]
fn serve_requires_a_config_and_parses_session_override() {
assert!(Cli::try_parse_from(["fader_master", "serve"]).is_err());
assert_eq!(
Cli::try_parse_from([
"fader_master",
"serve",
"--config",
"profile.toml",
"--audio",
"pulse",
])
.unwrap()
.command,
Command::Serve {
config: PathBuf::from("profile.toml"),
audio: Some(AudioArgument::Pulse),
socket: None,
}
);
}
#[test]
fn unknown_commands_and_adapter_values_are_rejected() {
assert!(Cli::try_parse_from(["fader_master", "unknown"]).is_err());
assert!(
Cli::try_parse_from([
"fader_master",
"serve",
"--config",
"profile.toml",
"--audio",
"alsa-master",
])
.is_err()
);
}
#[test]
fn tui_accepts_known_themes_and_rejects_unknown_names() {
assert_eq!(
Cli::try_parse_from(["fader_master", "tui"])
.unwrap()
.command,
Command::Tui {
socket: None,
theme: ThemeArgument::Default,
}
);
assert_eq!(
Cli::try_parse_from(["fader_master", "tui", "--theme", "catppuccin-mocha"])
.unwrap()
.command,
Command::Tui {
socket: None,
theme: ThemeArgument::CatppuccinMocha,
}
);
assert!(Cli::try_parse_from(["fader_master", "tui", "--theme", "hot-dog-stand"]).is_err());
}
#[test]
fn profile_switch_accepts_an_id_and_socket_override() {
assert_eq!(
Cli::try_parse_from([
"fader_master",
"profile",
"switch",
"gaming",
"--socket",
"/run/user/1000/fader_master/control.sock",
])
.unwrap()
.command,
Command::Profile {
command: ProfileCommand::Switch {
id: "gaming".into(),
socket: Some("/run/user/1000/fader_master/control.sock".into()),
},
}
);
}