Initial commit: apt-wrapper - Simple APT transaction wrapper
- Core transaction API with add_package, resolve, commit, rollback - Version tracking for upgrades/downgrades - Simple package info with FFI conversion functions - Comprehensive error handling - Basic test suite - Clean, minimal implementation (~326 lines total)
This commit is contained in:
commit
7aaefb9957
10 changed files with 761 additions and 0 deletions
56
tests/basic.rs
Normal file
56
tests/basic.rs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
//! 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)
|
||||
}
|
||||
50
tests/unit/test_basic.rs
Normal file
50
tests/unit/test_basic.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
//! Unit tests for basic functionality
|
||||
|
||||
use apt_wrapper::{AptTransaction, AptPackage, AptRepository, PackageDatabase};
|
||||
|
||||
#[test]
|
||||
fn test_transaction_creation() {
|
||||
let transaction = AptTransaction::new().unwrap();
|
||||
assert!(transaction.is_empty());
|
||||
assert_eq!(transaction.packages().len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transaction_add_package() {
|
||||
let mut transaction = AptTransaction::new().unwrap();
|
||||
transaction.add_package("vim").unwrap();
|
||||
assert!(!transaction.is_empty());
|
||||
assert_eq!(transaction.packages().len(), 1);
|
||||
assert_eq!(transaction.packages()[0], "vim");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transaction_resolve() {
|
||||
let mut transaction = AptTransaction::new().unwrap();
|
||||
transaction.add_package("vim").unwrap();
|
||||
transaction.resolve().unwrap();
|
||||
// Should not panic
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_package_creation() {
|
||||
let package = AptPackage::new("vim".to_string(), "2:8.2.2434-3+deb11u1".to_string());
|
||||
assert_eq!(package.name(), "vim");
|
||||
assert_eq!(package.version(), "2:8.2.2434-3+deb11u1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repository_creation() {
|
||||
let repo = AptRepository::new(
|
||||
"debian".to_string(),
|
||||
"http://deb.debian.org/debian".to_string(),
|
||||
);
|
||||
assert_eq!(repo.name(), "debian");
|
||||
assert_eq!(repo.url(), "http://deb.debian.org/debian");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_package_database_creation() {
|
||||
let db = PackageDatabase::new().unwrap();
|
||||
assert!(!db.is_stale());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue