| 1 | mod depcache { |
| 2 | use rust_apt::cache::Upgrade; |
| 3 | use rust_apt::new_cache; |
| 4 | |
| 5 | #[test] |
| 6 | fn mark_reinstall() { |
| 7 | let cache = new_cache!().unwrap(); |
| 8 | let pkg = cache.get("apt").unwrap(); |
| 9 | |
| 10 | dbg!(pkg.marked_reinstall()); |
| 11 | dbg!(pkg.mark_reinstall(true)); |
| 12 | assert!(pkg.marked_reinstall()); |
| 13 | } |
| 14 | |
| 15 | #[test] |
| 16 | fn action_groups() { |
| 17 | let cache = new_cache!().unwrap(); |
| 18 | let mut action_group = unsafe { cache.depcache().action_group() }; |
| 19 | |
| 20 | // This is unsafe due to SIGABRT if you try to release after dropping the cache. |
| 21 | // Probably should get wrapped and have a lifetime related to the Cache. |
| 22 | // drop(cache); |
| 23 | |
| 24 | // The C++ deconstructor will be run when the action group leaves scope. |
| 25 | action_group.pin_mut().release(); |
| 26 | } |
| 27 | |
| 28 | // Make a test for getting the candidate after you set a candidate. |
| 29 | // Make sure it's the expected version. |
| 30 | // We had to change to getting the candidate from the depcache. |
| 31 | // https://gitlab.com/volian/rust-apt/-/issues/14 |
| 32 | |
| 33 | // #[test] |
| 34 | // fn changes_test() { |
| 35 | // let cache = new_cache!().unwrap(); |
| 36 | |
| 37 | // let pkg = cache.get("nala").unwrap(); |
| 38 | |
| 39 | // let ver = pkg.get_version("0.12.1").unwrap(); |
| 40 | |
| 41 | // ver.set_candidate(); |
| 42 | |
| 43 | // let cand = pkg.candidate().unwrap(); |
| 44 | |
| 45 | // println!("Version is {}", cand.version()) |
| 46 | // } |
| 47 | |
| 48 | #[test] |
| 49 | fn upgrade() { |
| 50 | // There isn't a great way to test if upgrade is working properly |
| 51 | // as this is dynamic depending on the system. |
| 52 | // This test will always pass, but print the status of the changes. |
| 53 | // Occasionally manually compare the output to apt full-upgrade. |
| 54 | let cache = new_cache!().unwrap(); |
| 55 | cache.upgrade(Upgrade::FullUpgrade).unwrap(); |
| 56 | |
| 57 | for pkg in cache.get_changes(true) { |
| 58 | if pkg.marked_install() { |
| 59 | println!("{} is marked install", pkg.name()); |
| 60 | // If the package is marked install then it will also |
| 61 | // show up as marked upgrade, downgrade etc. |
| 62 | // Check this first and continue. |
| 63 | continue; |
| 64 | } |
| 65 | if pkg.marked_upgrade() { |
| 66 | println!("{} is marked upgrade", pkg.name()) |
| 67 | } |
| 68 | if pkg.marked_delete() { |
| 69 | println!("{} is marked remove", pkg.name()) |
| 70 | } |
| 71 | if pkg.marked_reinstall() { |
| 72 | println!("{} is marked reinstall", pkg.name()) |
| 73 | } |
| 74 | if pkg.marked_downgrade() { |
| 75 | println!("{} is marked downgrade", pkg.name()) |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |