#[cfg(test)] mod tests { use std::{fs, path::PathBuf}; use tempfile::TempDir; use crate::{ cli::{ExportArgs, ImportArgs, RmArgs}, model::config::Config, }; #[test] fn test_rm_args_parsing_all_flag() { let args = RmArgs::parse_from(&["pakker", "rm", "--all"]); assert!(args.all); assert!(args.inputs.is_empty()); } #[test] fn test_rm_args_parsing_multiple_inputs() { let args = RmArgs::parse_from(&["pakker", "rm", "mod1", "mod2", "mod3"]); assert!(!args.all); assert_eq!(args.inputs, vec!["mod1", "mod2", "mod3"]); } #[test] fn test_rm_args_parsing_all_with_yes() { let args = RmArgs::parse_from(&["pakker", "rm", "--all", "--yes"]); assert!(args.all); assert!(args.yes); assert!(args.inputs.is_empty()); } #[test] fn test_rm_args_parsing_with_inputs_and_yes() { let args = RmArgs::parse_from(&["pakker", "rm", "mod1", "--yes"]); assert!(!args.all); assert!(args.yes); assert_eq!(args.inputs, vec!["mod1"]); } #[test] fn test_import_args_parsing_deps_flag() { let args = ImportArgs::parse_from(&["pakker", "import", "--deps", "pack.zip"]); assert!(args.deps); assert_eq!(args.file, "pack.zip"); } #[test] fn test_import_args_parsing_no_deps_default() { let args = ImportArgs::parse_from(&["pakker", "import", "pack.zip"]); assert!(!args.deps); assert_eq!(args.file, "pack.zip"); } #[test] fn test_import_args_parsing_deps_with_yes() { let args = ImportArgs::parse_from(&[ "pakker", "import", "--deps", "--yes", "pack.zip", ]); assert!(args.deps); assert!(args.yes); assert_eq!(args.file, "pack.zip"); } #[test] fn test_import_args_parsing_short_deps_flag() { let args = ImportArgs::parse_from(&["pakker", "import", "-D", "pack.zip"]); assert!(args.deps); assert_eq!(args.file, "pack.zip"); } #[test] fn test_export_args_parsing_show_io_errors() { let args = ExportArgs::parse_from(&["pakker", "export", "--show-io-errors"]); assert!(args.show_io_errors); assert!(!args.no_server); } #[test] fn test_export_args_parsing_no_server() { let args = ExportArgs::parse_from(&["pakker", "export", "--no-server"]); assert!(args.no_server); assert!(!args.show_io_errors); } #[test] fn test_export_args_parsing_both_flags() { let args = ExportArgs::parse_from(&[ "pakker", "export", "--show-io-errors", "--no-server", "--profile", "modrinth", ]); assert!(args.show_io_errors); assert!(args.no_server); assert_eq!(args.profile, Some("modrinth".to_string())); } #[test] fn test_export_args_parsing_with_output() { let args = ExportArgs::parse_from(&[ "pakker", "export", "--output", "/tmp/export", "--profile", "curseforge", ]); assert_eq!(args.output, Some("/tmp/export".to_string())); assert_eq!(args.profile, Some("curseforge".to_string())); } #[test] fn test_export_args_parsing_pakker_layout() { let args = ExportArgs::parse_from(&["pakker", "export", "--pakker-layout"]); assert!(args.pakker_layout); } #[test] fn test_config_with_export_server_side_projects_to_client_true() { let config = Config { name: "test-pack".to_string(), version: "1.0.0".to_string(), description: None, author: None, overrides: vec!["overrides".to_string()], server_overrides: None, client_overrides: None, paths: std::collections::HashMap::new(), projects: None, export_profiles: None, export_server_side_projects_to_client: Some(true), }; assert_eq!(config.export_server_side_projects_to_client, Some(true)); } #[test] fn test_config_with_export_server_side_projects_to_client_false() { let config = Config { name: "test-pack".to_string(), version: "1.0.0".to_string(), description: None, author: None, overrides: vec!["overrides".to_string()], server_overrides: None, client_overrides: None, paths: std::collections::HashMap::new(), projects: None, export_profiles: None, export_server_side_projects_to_client: Some(false), }; assert_eq!(config.export_server_side_projects_to_client, Some(false)); } #[test] fn test_config_without_export_server_side_projects_to_client() { let config = Config { name: "test-pack".to_string(), version: "1.0.0".to_string(), description: None, author: None, overrides: vec!["overrides".to_string()], server_overrides: None, client_overrides: None, paths: std::collections::HashMap::new(), projects: None, export_profiles: None, export_server_side_projects_to_client: None, file_count_preference: None, }; assert!(config.export_server_side_projects_to_client.is_none()); } #[test] fn test_config_serialization_with_export_server_side() { let config = Config { name: "test-pack".to_string(), version: "1.0.0".to_string(), description: Some("A test modpack".to_string()), author: Some("Test Author".to_string()), overrides: vec!["overrides".to_string()], server_overrides: Some(vec![ "server-overrides".to_string(), ]), client_overrides: Some(vec![ "client-overrides".to_string(), ]), paths: std::collections::HashMap::new(), projects: None, export_profiles: None, export_server_side_projects_to_client: Some(true), }; let json = serde_json::to_string_pretty(&config).unwrap(); assert!(json.contains("exportServerSideProjectsToClient")); assert!(json.contains("true")); let deserialized: Config = serde_json::from_str(&json).unwrap(); assert_eq!( deserialized.export_server_side_projects_to_client, Some(true) ); } #[test] fn test_config_serialization_without_export_server_side() { let config = Config { name: "test-pack".to_string(), version: "1.0.0".to_string(), description: None, author: None, overrides: vec!["overrides".to_string()], server_overrides: None, client_overrides: None, paths: std::collections::HashMap::new(), projects: None, export_profiles: None, export_server_side_projects_to_client: None, file_count_preference: None, }; let json = serde_json::to_string_pretty(&config).unwrap(); assert!(!json.contains("exportServerSideProjectsToClient")); let deserialized: Config = serde_json::from_str(&json).unwrap(); assert!(deserialized.export_server_side_projects_to_client.is_none()); } #[test] fn test_config_default_has_no_export_server_side() { let config = Config::default(); assert!(config.export_server_side_projects_to_client.is_none()); } #[test] fn test_export_args_all_flags_together() { let args = ExportArgs::parse_from(&[ "pakker", "export", "--profile", "modrinth", "--output", "/tmp/out", "--pakker-layout", "--show-io-errors", "--no-server", ]); assert_eq!(args.profile, Some("modrinth".to_string())); assert_eq!(args.output, Some("/tmp/out".to_string())); assert!(args.pakker_layout); assert!(args.show_io_errors); assert!(args.no_server); } }