use docker_wrapper::{ensure_docker, DockerCommand, LogoutCommand};
async fn setup_docker() -> Result<(), Box<dyn std::error::Error>> {
ensure_docker().await?;
Ok(())
}
#[tokio::test]
async fn test_logout_prerequisites_validation() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
Ok(())
}
#[tokio::test]
async fn test_logout_basic_command() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = LogoutCommand::new();
let args = command.build_command_args();
assert_eq!(args[0], "logout");
assert_eq!(args, vec!["logout"]);
assert!(!args.is_empty());
Ok(())
}
#[tokio::test]
async fn test_logout_command_builder() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = LogoutCommand::new().server("my-registry.example.com");
let args = command.build_command_args();
assert_eq!(args[0], "logout");
assert!(args.contains(&"my-registry.example.com".to_string()));
Ok(())
}
#[tokio::test]
async fn test_logout_with_private_registry() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = LogoutCommand::new().server("registry.company.com:5000");
let args = command.build_command_args();
assert!(args.contains(&"registry.company.com:5000".to_string()));
Ok(())
}
#[tokio::test]
async fn test_logout_docker_hub_variations() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let hub_variations = vec![
"docker.io",
"index.docker.io",
"registry-1.docker.io",
"https://index.docker.io/v1/",
];
for server in hub_variations {
let command = LogoutCommand::new().server(server);
let args = command.build_command_args();
assert_eq!(args[0], "logout");
assert!(args.contains(&server.to_string()));
}
Ok(())
}
#[tokio::test]
async fn test_logout_command_name() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = LogoutCommand::new();
let args = command.build_command_args();
assert_eq!(args[0], "logout");
Ok(())
}
#[tokio::test]
async fn test_logout_command_display() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = LogoutCommand::new().server("test-registry.com");
let args = command.build_command_args();
assert!(!args.is_empty());
let args = command.build_command_args();
assert_eq!(args[0], "logout");
assert!(args.contains(&"test-registry.com".to_string()));
Ok(())
}
#[tokio::test]
async fn test_logout_command_format() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = LogoutCommand::new().server("registry.example.com");
let args = command.build_command_args();
assert_eq!(args[0], "logout");
assert!(args.contains(&"registry.example.com".to_string()));
Ok(())
}
#[tokio::test]
async fn test_logout_various_registry_formats() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let registry_formats = vec![
"localhost:5000",
"registry.local",
"my-registry.company.com",
"gcr.io",
"quay.io",
"registry.gitlab.com",
"ghcr.io",
];
for registry in registry_formats {
let command = LogoutCommand::new().server(registry);
let args = command.build_command_args();
assert_eq!(args[0], "logout");
assert!(args.contains(®istry.to_string()));
assert!(!args.is_empty());
}
Ok(())
}
#[tokio::test]
async fn test_logout_default_daemon_behavior() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = LogoutCommand::new();
let args = command.build_command_args();
assert_eq!(args[0], "logout");
assert_eq!(args, vec!["logout"]);
Ok(())
}
#[tokio::test]
async fn test_logout_command_order() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = LogoutCommand::new().server("registry.example.com");
let args = command.build_command_args();
assert_eq!(args[0], "logout");
assert!(args.contains(&"registry.example.com".to_string()));
Ok(())
}
#[tokio::test]
async fn test_logout_multiple_servers_concept() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let servers = vec!["registry1.com", "registry2.com", "registry3.com"];
for server in servers {
let command = LogoutCommand::new().server(server);
let args = command.build_command_args();
assert_eq!(args[0], "logout");
assert!(args.contains(&server.to_string()));
}
Ok(())
}
#[tokio::test]
async fn test_logout_empty_server_handling() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = LogoutCommand::new().server("");
let _args = command.build_command_args();
let args = command.build_command_args();
assert_eq!(args[0], "logout");
assert_eq!(_args, vec!["logout", ""]);
Ok(())
}
#[tokio::test]
async fn test_logout_server_with_protocol() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let servers_with_protocol = vec![
"https://registry.example.com",
"http://localhost:5000",
"https://my-registry.com:8443",
];
for server in servers_with_protocol {
let command = LogoutCommand::new().server(server);
let args = command.build_command_args();
assert_eq!(args[0], "logout");
assert!(args.contains(&server.to_string()));
}
Ok(())
}
#[tokio::test]
async fn test_logout_validation() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = LogoutCommand::new().server("test-registry.io");
let args = command.build_command_args();
assert_eq!(args[0], "logout");
let args = command.build_command_args();
assert!(!args.is_empty());
assert!(args.contains(&"test-registry.io".to_string()));
Ok(())
}
#[tokio::test]
async fn test_logout_builder_pattern() -> Result<(), Box<dyn std::error::Error>> {
setup_docker().await?;
let command = LogoutCommand::new().server("registry.example.com");
let args = command.build_command_args();
assert_eq!(args[0], "logout");
assert!(args.contains(&"registry.example.com".to_string()));
let chained = LogoutCommand::new()
.server("first.com")
.server("second.com");
let chained_args = chained.build_command_args();
assert!(chained_args.contains(&"second.com".to_string()));
assert!(!chained_args.contains(&"first.com".to_string()));
Ok(())
}