apt-tx/tests/basic.rs
robojerk 2daad2837d Major improvements: rollbacks, testing, docs, and code quality
- Fixed rollback implementation with two-phase approach (remove new, downgrade upgraded)
- Added explicit package tracking (newly_installed vs upgraded)
- Implemented graceful error handling with fail-fast approach
- Added comprehensive test suite (20 tests across 3 test files)
- Created centralized APT command execution module (apt_commands.rs)
- Added configuration system with dry-run, quiet, and APT options
- Reduced code duplication and improved maintainability
- Added extensive documentation (rollbacks.md, rollbacks-not-featured.md, ffi-bridge.md)
- Created configuration usage example
- Updated README with crate usage instructions
- All tests passing, clean compilation, production-ready
2025-09-13 11:21:35 -07:00

57 lines
1.7 KiB
Rust

//! Basic tests for APT wrapper
use apt_wrapper::{AptTransaction, init};
#[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 (before commit)
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)
// The tracking fields (newly_installed, upgraded) are only populated after commit()
}