//! Basic tests for APT wrapper use apt_wrapper::{AptTransaction, init, search_packages}; #[test] fn test_transaction_creation() { let tx = AptTransaction::new().unwrap(); assert!(tx.is_empty()); assert_eq!(tx.packages().len(), 0); } #[test] fn test_transaction_add_package() { let mut tx = AptTransaction::new().unwrap(); // Try to add a common package (should exist) let result = tx.add_package("apt"); assert!(result.is_ok()); assert_eq!(tx.packages().len(), 1); assert_eq!(tx.packages()[0], "apt"); } #[test] fn test_transaction_add_nonexistent_package() { let mut tx = AptTransaction::new().unwrap(); // Try to add a package that definitely doesn't exist let result = tx.add_package("this-package-definitely-does-not-exist-12345"); assert!(result.is_err()); assert!(tx.is_empty()); } #[test] fn test_init() { // This will fail if APT is not available let result = init(); // We can't assert success since APT might not be available in test environment // Just ensure it doesn't panic let _ = result; } #[test] fn test_transaction_rollback_tracking() { let mut tx = AptTransaction::new().unwrap(); // Add a package let result = tx.add_package("apt"); assert!(result.is_ok()); // Check that changed_packages is initially empty assert!(tx.changed_packages().is_empty()); // Note: We don't actually commit in tests to avoid installing packages // In real usage, after commit(), changed_packages would contain // the packages that were changed (installed/upgraded) }