use bssh::cli::{Cli, Commands};
use clap::Parser;
use std::path::PathBuf;
#[test]
fn test_download_command_parsing() {
let args = vec![
"bssh",
"-H",
"host1,host2",
"download",
"/remote/file.txt",
"/local/downloads/",
];
let cli = Cli::parse_from(args);
assert!(matches!(
cli.command,
Some(Commands::Download {
source: _,
destination: _,
recursive: _
})
));
if let Some(Commands::Download {
source,
destination,
recursive: _,
}) = cli.command
{
assert_eq!(source, "/remote/file.txt");
assert_eq!(destination, PathBuf::from("/local/downloads/"));
}
}
#[test]
fn test_download_command_with_cluster() {
let args = vec![
"bssh",
"-c",
"staging",
"download",
"/var/log/app.log",
"./logs/",
];
let cli = Cli::parse_from(args);
assert_eq!(cli.cluster, Some("staging".to_string()));
assert!(matches!(
cli.command,
Some(Commands::Download {
source: _,
destination: _,
recursive: _
})
));
}
#[test]
fn test_download_command_with_glob() {
let args = vec![
"bssh",
"-H",
"server1",
"download",
"/var/log/*.log",
"/tmp/collected_logs/",
];
let cli = Cli::parse_from(args);
if let Some(Commands::Download {
source,
destination,
recursive: _,
}) = cli.command
{
assert_eq!(source, "/var/log/*.log");
assert_eq!(destination, PathBuf::from("/tmp/collected_logs/"));
}
}
#[test]
fn test_download_command_with_options() {
let args = vec![
"bssh",
"-H",
"node1,node2",
"-i",
"~/.ssh/id_ed25519",
"-p",
"20",
"--use-agent",
"download",
"/etc/config.conf",
"./backups/",
];
let cli = Cli::parse_from(args);
assert_eq!(
cli.hosts,
Some(vec!["node1".to_string(), "node2".to_string()])
);
assert_eq!(cli.identity, Some(PathBuf::from("~/.ssh/id_ed25519")));
assert_eq!(cli.parallel, 20);
assert!(cli.use_agent);
if let Some(Commands::Download {
source,
destination,
recursive: _,
}) = cli.command
{
assert_eq!(source, "/etc/config.conf");
assert_eq!(destination, PathBuf::from("./backups/"));
}
}