#[path = "../../../os-turkfs-allocation/src/lib.rs"] mod allocation; #[test] fn os_turkfs_allocation_inode_alloc_positive() { let mut slot = allocation::InodeSlot::new(5, 7).unwrap(); let first = slot.allocate(11).unwrap(); assert_eq!(slot.owner(first), Ok(11)); assert_eq!(slot.allocate(22), Err(allocation::Error::Busy)); slot.release(first).unwrap(); assert!(!slot.live()); assert_eq!(slot.generation(), 8); let second = slot.allocate(22).unwrap(); assert_eq!(second.slot, first.slot); assert_eq!(second.generation, 8); assert_eq!(slot.owner(second), Ok(22)); } #[test] fn os_turkfs_allocation_inode_alloc_negative() { let mut slot = allocation::InodeSlot::new(5, 7).unwrap(); let first = slot.allocate(11).unwrap(); slot.release(first).unwrap(); let second = slot.allocate(22).unwrap(); let before = slot; assert_eq!(slot.owner(first), Err(allocation::Error::Stale)); assert_eq!(slot.release(first), Err(allocation::Error::Stale)); assert_eq!(slot, before); assert_eq!(slot.owner(second), Ok(22)); let mut terminal = allocation::InodeSlot::new(6, u64::MAX).unwrap(); let handle = terminal.allocate(33).unwrap(); let before_terminal = terminal; assert_eq!(terminal.release(handle), Err(allocation::Error::GenerationOverflow)); assert_eq!(terminal, before_terminal); assert_eq!(allocation::InodeSlot::new(0, 1), Err(allocation::Error::InvalidSlot)); }