use docker_wrapper::{ensure_docker, InfoCommand};
async fn setup_docker() -> Result<(), Box<dyn std::error::Error>> {
ensure_docker().await?;
Ok(())
}
#[tokio::test]
async fn test_info_prerequisites_validation() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
Ok(())
}
#[tokio::test]
async fn test_info_basic_command() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = InfoCommand::new();
let args = command.build_command_args();
assert_eq!(args[0], "info");
assert_eq!(args, vec!["info"]);
assert!(!args.is_empty());
Ok(())
}
#[tokio::test]
async fn test_info_command_builder() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = InfoCommand::new().format("json");
let args = command.build_command_args();
assert_eq!(args[0], "info");
assert!(args.contains(&"--format".to_string()));
assert!(args.contains(&"json".to_string()));
Ok(())
}
#[tokio::test]
async fn test_info_format_variations() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let formats = vec![
"json",
"table",
"{{.ServerVersion}}",
"{{.Name}}",
"{{.DriverStatus}}",
];
for format in formats {
let command = InfoCommand::new().format(format);
let args = command.build_command_args();
assert_eq!(args[0], "info");
assert!(args.contains(&"--format".to_string()));
assert!(args.contains(&format.to_string()));
}
Ok(())
}
#[tokio::test]
async fn test_info_json_format() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = InfoCommand::new().format("json");
let args = command.build_command_args();
assert!(args.contains(&"--format".to_string()));
assert!(args.contains(&"json".to_string()));
Ok(())
}
#[tokio::test]
async fn test_info_table_format() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = InfoCommand::new().format("table");
let args = command.build_command_args();
assert!(args.contains(&"--format".to_string()));
assert!(args.contains(&"table".to_string()));
Ok(())
}
#[tokio::test]
async fn test_info_custom_go_template() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let template = "Server Version: {{.ServerVersion}}, Storage Driver: {{.Driver}}";
let command = InfoCommand::new().format(template);
let args = command.build_command_args();
assert!(args.contains(&"--format".to_string()));
assert!(args.contains(&template.to_string()));
Ok(())
}
#[tokio::test]
async fn test_info_command_name() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = InfoCommand::new();
let args = command.build_command_args();
assert_eq!(args[0], "info");
Ok(())
}
#[tokio::test]
async fn test_info_command_display() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = InfoCommand::new().format("json");
let args = command.build_command_args();
assert!(!args.is_empty());
assert_eq!(args[0], "info");
assert!(args.contains(&"--format".to_string()));
assert!(args.contains(&"json".to_string()));
Ok(())
}
#[tokio::test]
async fn test_info_default_format() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = InfoCommand::new();
let args = command.build_command_args();
assert_eq!(args[0], "info");
assert_eq!(args, vec!["info"]);
Ok(())
}
#[tokio::test]
async fn test_info_format_parsing_concept() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let json_command = InfoCommand::new().format("json");
let table_command = InfoCommand::new().format("table");
let json_args = json_command.build_command_args();
let table_args = table_command.build_command_args();
assert!(json_args.contains(&"--format".to_string()));
assert!(json_args.contains(&"json".to_string()));
assert!(table_args.contains(&"--format".to_string()));
assert!(table_args.contains(&"table".to_string()));
Ok(())
}
#[tokio::test]
async fn test_info_command_order() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = InfoCommand::new().format("table");
let args = command.build_command_args();
assert_eq!(args[0], "info");
assert!(args.contains(&"--format".to_string()));
assert!(args.contains(&"table".to_string()));
Ok(())
}
#[tokio::test]
async fn test_info_empty_format_handling() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = InfoCommand::new().format("");
let args = command.build_command_args();
assert_eq!(args[0], "info");
assert_eq!(args, vec!["info", "--format", ""]);
Ok(())
}
#[tokio::test]
async fn test_info_complex_go_templates() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let complex_templates = vec![
"{{.ServerVersion}}",
"{{.Name}}",
"{{json .}}",
"Server: {{.ServerVersion}}\nDriver: {{.Driver}}",
"{{range .Plugins.Storage}}{{.}}\n{{end}}",
"{{.NCPU}} CPUs, {{.MemTotal}} bytes memory",
];
for template in complex_templates {
let command = InfoCommand::new().format(template);
let args = command.build_command_args();
assert_eq!(args[0], "info");
assert!(args.contains(&"--format".to_string()));
assert!(args.contains(&template.to_string()));
}
Ok(())
}
#[tokio::test]
async fn test_info_system_information_templates() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let system_templates = vec![
"{{.Architecture}}",
"{{.OSType}}",
"{{.KernelVersion}}",
"{{.OperatingSystem}}",
"{{.DockerRootDir}}",
"{{.SystemTime}}",
];
for template in system_templates {
let command = InfoCommand::new().format(template);
let args = command.build_command_args();
assert_eq!(args[0], "info");
assert!(args.contains(&"--format".to_string()));
assert!(args.contains(&template.to_string()));
}
Ok(())
}
#[tokio::test]
async fn test_info_container_runtime_templates() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let runtime_templates = vec![
"{{.ContainersRunning}}",
"{{.ContainersPaused}}",
"{{.ContainersStopped}}",
"{{.Images}}",
"{{.Driver}}",
"{{.LoggingDriver}}",
"{{.CgroupDriver}}",
];
for template in runtime_templates {
let command = InfoCommand::new().format(template);
let args = command.build_command_args();
assert_eq!(args[0], "info");
assert!(args.contains(&"--format".to_string()));
assert!(args.contains(&template.to_string()));
}
Ok(())
}
#[tokio::test]
async fn test_info_validation() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = InfoCommand::new().format("json");
let args = command.build_command_args();
assert_eq!(args[0], "info");
let args = command.build_command_args();
assert!(!args.is_empty());
assert!(args.contains(&"--format".to_string()));
assert!(args.contains(&"json".to_string()));
Ok(())
}
#[tokio::test]
async fn test_info_builder_pattern() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = InfoCommand::new().format("json");
let args = command.build_command_args();
assert_eq!(args[0], "info");
assert!(args.contains(&"--format".to_string()));
assert!(args.contains(&"json".to_string()));
let chained_command = InfoCommand::new()
.format("table")
.format("{{.ServerVersion}}");
let chained_args = chained_command.build_command_args();
assert!(chained_args.contains(&"--format".to_string()));
assert!(chained_args.contains(&"{{.ServerVersion}}".to_string()));
Ok(())
}
#[tokio::test]
async fn test_info_format_edge_cases() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let edge_case_formats = vec![
"table {{.ServerVersion}}",
"{{.Name}} - {{.ServerVersion}}",
"json",
"{{range .Plugins.Network}}{{.}}\n{{end}}",
"CPU: {{.NCPU}}, Memory: {{.MemTotal}}",
];
for format in edge_case_formats {
let command = InfoCommand::new().format(format);
let args = command.build_command_args();
assert_eq!(args[0], "info");
assert!(args.contains(&"--format".to_string()));
assert!(args.contains(&format.to_string()));
}
Ok(())
}
#[tokio::test]
async fn test_info_output_parsing_concept() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let json_command = InfoCommand::new().format("json");
let table_command = InfoCommand::new().format("table");
let default_command = InfoCommand::new();
assert!(json_command
.build_command_args()
.contains(&"--format".to_string()));
assert!(json_command
.build_command_args()
.contains(&"json".to_string()));
assert!(table_command
.build_command_args()
.contains(&"--format".to_string()));
assert!(table_command
.build_command_args()
.contains(&"table".to_string()));
assert_eq!(default_command.build_command_args(), vec!["info"]);
Ok(())
}
#[tokio::test]
async fn test_info_security_context_templates() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let security_templates = vec![
"{{.SecurityOptions}}",
"{{range .SecurityOptions}}{{.}}\n{{end}}",
"{{.Warnings}}",
"{{range .Warnings}}Warning: {{.}}\n{{end}}",
];
for template in security_templates {
let command = InfoCommand::new().format(template);
let args = command.build_command_args();
assert_eq!(args[0], "info");
assert!(args.contains(&"--format".to_string()));
assert!(args.contains(&template.to_string()));
}
Ok(())
}
#[tokio::test]
async fn test_info_storage_templates() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let storage_templates = vec![
"{{.DriverStatus}}",
"{{range .DriverStatus}}{{index . 0}}: {{index . 1}}\n{{end}}",
"{{.DockerRootDir}}",
"{{.Driver}}",
];
for template in storage_templates {
let command = InfoCommand::new().format(template);
let args = command.build_command_args();
assert_eq!(args[0], "info");
assert!(args.contains(&"--format".to_string()));
assert!(args.contains(&template.to_string()));
}
Ok(())
}