use bssh::cli::Cli;
use bssh::executor::OutputMode;
use clap::Parser;
use std::path::PathBuf;
#[test]
fn test_no_prefix_long_option() {
let args = vec!["bssh", "-H", "host1,host2", "--no-prefix", "uptime"];
let cli = Cli::parse_from(args);
assert!(cli.no_prefix, "--no-prefix should set no_prefix to true");
assert_eq!(
cli.hosts,
Some(vec!["host1".to_string(), "host2".to_string()])
);
}
#[test]
fn test_no_prefix_short_option() {
let args = vec!["bssh", "-H", "host1,host2", "-N", "uptime"];
let cli = Cli::parse_from(args);
assert!(cli.no_prefix, "-N should set no_prefix to true");
}
#[test]
fn test_no_prefix_default_false() {
let args = vec!["bssh", "-H", "host1,host2", "uptime"];
let cli = Cli::parse_from(args);
assert!(!cli.no_prefix, "no_prefix should be false by default");
}
#[test]
fn test_no_prefix_with_stream_mode() {
let args = vec![
"bssh",
"-H",
"host1,host2",
"--stream",
"--no-prefix",
"uptime",
];
let cli = Cli::parse_from(args);
assert!(cli.no_prefix, "--no-prefix should be set");
assert!(cli.stream, "--stream should be set");
let mode = OutputMode::from_args_with_no_prefix(cli.stream, None, cli.no_prefix);
assert!(mode.is_stream());
assert!(mode.is_no_prefix());
}
#[test]
fn test_no_prefix_with_output_dir() {
let args = vec![
"bssh",
"-H",
"host1,host2",
"--output-dir",
"/tmp/output",
"-N",
"uptime",
];
let cli = Cli::parse_from(args);
assert!(cli.no_prefix, "-N should be set");
assert_eq!(cli.output_dir, Some(PathBuf::from("/tmp/output")));
let mode =
OutputMode::from_args_with_no_prefix(cli.stream, cli.output_dir.clone(), cli.no_prefix);
assert!(mode.is_file());
assert!(mode.is_no_prefix());
}
#[test]
fn test_no_prefix_with_cluster() {
let args = vec!["bssh", "-C", "production", "--no-prefix", "df -h"];
let cli = Cli::parse_from(args);
assert!(cli.no_prefix, "--no-prefix should be set");
assert_eq!(cli.cluster, Some("production".to_string()));
}
#[test]
fn test_no_prefix_with_other_options() {
let args = vec![
"bssh", "-H", "host1", "-N", "-A", "-v", "uptime",
];
let cli = Cli::parse_from(args);
assert!(cli.no_prefix, "-N should be set");
assert!(cli.use_agent, "-A should be set");
assert_eq!(cli.verbose, 1, "-v should increase verbosity");
}
#[test]
fn test_output_mode_is_no_prefix_normal() {
let mode = OutputMode::Normal;
assert!(
!mode.is_no_prefix(),
"Normal mode should not report no_prefix as true"
);
}
#[test]
fn test_output_mode_is_no_prefix_tui() {
let mode = OutputMode::Tui;
assert!(
!mode.is_no_prefix(),
"Tui mode should not report no_prefix as true"
);
}
#[test]
fn test_output_mode_explicit_construction() {
let stream_with_prefix = OutputMode::Stream { no_prefix: false };
assert!(!stream_with_prefix.is_no_prefix());
let stream_without_prefix = OutputMode::Stream { no_prefix: true };
assert!(stream_without_prefix.is_no_prefix());
let file_with_prefix = OutputMode::File {
path: PathBuf::from("/tmp"),
no_prefix: false,
};
assert!(!file_with_prefix.is_no_prefix());
let file_without_prefix = OutputMode::File {
path: PathBuf::from("/tmp"),
no_prefix: true,
};
assert!(file_without_prefix.is_no_prefix());
}