| 1 | use publication::{ |
| 2 | Cancellation, Cleanup, CloseFailure, FileCommitReceipt, Publication, Report, Resource, |
| 3 | }; |
| 4 | use std::io; |
| 5 | |
| 6 | #[test] |
| 7 | fn constructed_cleanup_failures_are_never_all_successful() { |
| 8 | let cleanup = Cleanup { |
| 9 | attempted: 2, |
| 10 | failures: [ |
| 11 | Some(CloseFailure { |
| 12 | resource: Resource::TemporaryFile, |
| 13 | source: io::Error::from_raw_os_error(libc::EIO), |
| 14 | }), |
| 15 | Some(CloseFailure { |
| 16 | resource: Resource::ParentDirectory, |
| 17 | source: io::Error::from_raw_os_error(libc::EINTR), |
| 18 | }), |
| 19 | None, |
| 20 | None, |
| 21 | ], |
| 22 | }; |
| 23 | assert!(!cleanup.all_close_calls_succeeded()); |
| 24 | assert_eq!(cleanup.attempted, 2); |
| 25 | assert_eq!( |
| 26 | cleanup.failures[0].as_ref().unwrap().resource, |
| 27 | Resource::TemporaryFile |
| 28 | ); |
| 29 | assert_eq!( |
| 30 | cleanup.failures[0].as_ref().unwrap().source.raw_os_error(), |
| 31 | Some(libc::EIO) |
| 32 | ); |
| 33 | assert_eq!( |
| 34 | cleanup.failures[1].as_ref().unwrap().source.raw_os_error(), |
| 35 | Some(libc::EINTR) |
| 36 | ); |
| 37 | let empty = Cleanup { |
| 38 | attempted: 0, |
| 39 | failures: [None, None, None, None], |
| 40 | }; |
| 41 | assert!(empty.all_close_calls_succeeded()); |
| 42 | assert_eq!(empty.attempted, 0); |
| 43 | } |
| 44 | |
| 45 | #[test] |
| 46 | fn public_types_support_transfer_without_forging_receipts() { |
| 47 | fn send<T: Send>() {} |
| 48 | send::<Publication>(); |
| 49 | send::<Cancellation>(); |
| 50 | send::<Report<()>>(); |
| 51 | send::<FileCommitReceipt>(); |
| 52 | } |